add

Monday 4 June 2018

Error While Udpate Data in entity Framework of MVC


Error While Udpate Data in entity Framework of MVC

//This Is Get Action Of  Edit

 public ActionResult Edit(int ?id)
        {
            if (!id.HasValue)
                return RedirectToAction("index");

            using (FirstAngularJsWithMVCEntities db = new FirstAngularJsWithMVCEntities())
            {
                var Employee = db.Employees.Find(id);
                return View(Employee);
            }
       

        }
   //This Is Post Action Of  Edit
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(Employee employee)
        {
            if (!ModelState.IsValid)
                return View(employee);
            using (FirstAngularJsWithMVCEntities db = new FirstAngularJsWithMVCEntities())
            {
                var Emp=db.Employees.Find(employee.id);
                if (Emp != null)
                {
                    //Emp.Fname = employee.Fname;
                    //Emp.address = employee.address;
                    //Emp. Age = employee.Age;
                    //Emp.  phoneno = employee.phoneno;
                    //Emp. UserId = employee.UserId;
                    db.Entry(employee).State = EntityState.Modified;

                    if (db.SaveChanges() > 0)
                    {
                        return View("index");
                    }
                    else
                    {
                        return View(employee);
                    }
                }
                else
                    return View(employee);
            }

        }
//Problem:-
(Now The Problem Is Your entity is not modified so you need to Follow The Solution
System.InvalidOperationException
  HResult=0x80131509
  Message=Attaching an entity of type 'AngularFirstWithMVC.DataEntity.Employee' failed because another entity of the same type already has the same primary key value. This can happen when using the 'Attach' method or setting the state of an entity to 'Unchanged' or 'Modified' if any entities in the graph have conflicting key values. This may be because some entities are new and have not yet received database-generated key values. In this case use the 'Add' method or the 'Added' entity state to track the graph and then set the state of non-new entities to 'Unchanged' or 'Modified' as appropriate.
  Source=EntityFramework
  StackTrace:
   at System.Data.Entity.Core.Objects.ObjectContext.VerifyRootForAdd(Boolean doAttach, String entitySetName, IEntityWrapper wrappedEntity, EntityEntry existingEntry, EntitySet& entitySet, Boolean& isNoOperation)
   at System.Data.Entity.Core.Objects.ObjectContext.AttachTo(String entitySetName, Object entity)
   at System.Data.Entity.Internal.Linq.InternalSet`1.<>c__DisplayClassa.<Attach>b__9()
   at System.Data.Entity.Internal.Linq.InternalSet`1.ActOnSet(Action action, EntityState newState, Object entity, String methodName)
   at System.Data.Entity.Internal.Linq.InternalSet`1.Attach(Object entity)
   at System.Data.Entity.Internal.InternalEntityEntry.set_State(EntityState value)
   at System.Data.Entity.Infrastructure.DbEntityEntry`1.set_State(EntityState value)
   at AngularFirstWithMVC.Controllers.EmployeeController.Edit(Employee employee) in D:\Angular demos\AngularFirstWithMVC\AngularFirstWithMVC\Controllers\EmployeeController.cs:line 111
   at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c.<BeginInvokeSynchronousActionMethod>b__9_0(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__11_0()

   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass11_1.<InvokeActionMethodFilterAsynchronouslyRecursive>b__2()

Soulution:-
Finally The Solution Is Update Code in Post Method of Edit action
like this



        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(Employee employee)
        {
            if (!ModelState.IsValid)
                return View(employee);
            using (FirstAngularJsWithMVCEntities db = new FirstAngularJsWithMVCEntities())
            {
                var Emp=db.Employees.Find(employee.id);
                if (Emp != null)
                {
                    
                    db.Entry(Emp).CurrentValues.SetValues(employee);
                    if (db.SaveChanges() > 0)
                        {
                            return View("index");
                        }
                        else
                        {
                     return View(employee);
                        }
                   
                }
                else
                    return View(employee);
            }

        }



System.InvalidOperationException HResult=0x80131509 ,Entity Framework Issue, Update Entity framework


Error While Udpate Data in entity Framework of MVC

//This Is Get Action Of  Edit

 public ActionResult Edit(int ?id)
        {
            if (!id.HasValue)
                return RedirectToAction("index");

            using (FirstAngularJsWithMVCEntities db = new FirstAngularJsWithMVCEntities())
            {
                var Employee = db.Employees.Find(id);
                return View(Employee);
            }
         

        }
   //This Is Post Action Of  Edit
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(Employee employee)
        {
            if (!ModelState.IsValid)
                return View(employee);
            using (FirstAngularJsWithMVCEntities db = new FirstAngularJsWithMVCEntities())
            {
                var Emp=db.Employees.Find(employee.id);
                if (Emp != null)
                {
                    //Emp.Fname = employee.Fname;
                    //Emp.address = employee.address;
                    //Emp. Age = employee.Age;
                    //Emp.  phoneno = employee.phoneno;
                    //Emp. UserId = employee.UserId;
                    db.Entry(employee).State = EntityState.Modified;

                    if (db.SaveChanges() > 0)
                    {
                        return View("index");
                    }
                    else
                    {
                        return View(employee);
                    }
                }
                else
                    return View(employee);
            }

        }
//Problem:-
(Now The Problem Is Your entity is not modified so you need to Follow The Solution
System.InvalidOperationException
  HResult=0x80131509
  Message=Attaching an entity of type 'AngularFirstWithMVC.DataEntity.Employee' failed because another entity of the same type already has the same primary key value. This can happen when using the 'Attach' method or setting the state of an entity to 'Unchanged' or 'Modified' if any entities in the graph have conflicting key values. This may be because some entities are new and have not yet received database-generated key values. In this case use the 'Add' method or the 'Added' entity state to track the graph and then set the state of non-new entities to 'Unchanged' or 'Modified' as appropriate.
  Source=EntityFramework
  StackTrace:
   at System.Data.Entity.Core.Objects.ObjectContext.VerifyRootForAdd(Boolean doAttach, String entitySetName, IEntityWrapper wrappedEntity, EntityEntry existingEntry, EntitySet& entitySet, Boolean& isNoOperation)
   at System.Data.Entity.Core.Objects.ObjectContext.AttachTo(String entitySetName, Object entity)
   at System.Data.Entity.Internal.Linq.InternalSet`1.<>c__DisplayClassa.<Attach>b__9()
   at System.Data.Entity.Internal.Linq.InternalSet`1.ActOnSet(Action action, EntityState newState, Object entity, String methodName)
   at System.Data.Entity.Internal.Linq.InternalSet`1.Attach(Object entity)
   at System.Data.Entity.Internal.InternalEntityEntry.set_State(EntityState value)
   at System.Data.Entity.Infrastructure.DbEntityEntry`1.set_State(EntityState value)
   at AngularFirstWithMVC.Controllers.EmployeeController.Edit(Employee employee) in D:\Angular demos\AngularFirstWithMVC\AngularFirstWithMVC\Controllers\EmployeeController.cs:line 111
   at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c.<BeginInvokeSynchronousActionMethod>b__9_0(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__11_0()

   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass11_1.<InvokeActionMethodFilterAsynchronouslyRecursive>b__2()

Soulution:-
Finally The Solution Is Update Code in Post Method of Edit action
like this



        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(Employee employee)
        {
            if (!ModelState.IsValid)
                return View(employee);
            using (FirstAngularJsWithMVCEntities db = new FirstAngularJsWithMVCEntities())
            {
                var Emp=db.Employees.Find(employee.id);
                if (Emp != null)
                {
                    
                    db.Entry(Emp).CurrentValues.SetValues(employee);
                    if (db.SaveChanges() > 0)
                        {
                            return View("index");
                        }
                        else
                        {
                     return View(employee);
                        }
                   
                }
                else
                    return View(employee);
            }

        }



Increase Traffic of Website or Searching of Webpage On Search Egine


Increase the traffic for your website

How to increase the traffic for your website, there are a lot of ways to do this, such as, submit to the B2B marketplace, blogs, forums, Bookmarks, and so on.
Following are the details about where you can submit the website to increase traffic:
1 Submit to search engines
The first step is to submit the website to all search engines, like Google, Bing, Yahoo and so on. For more indexing and exposures in the near future.
2 B2B marketplace
A lot of B2B marketplace allows the users to post their products with pictures. And also they can manage their B2B homepage or the products in there.
3 SEO
If you have a small website, you can do some on-page SEO and off-page SEO.On-page SEO refers to optimize the TDK, external links, original content, updates and conversion etc..
Off-page SEO refers to keywords ranking, traffic, and so on. Select some keywords, and improve the keywords ranking in the Google search engine. If the website can be indexed by the Google or Bing, the more pages indexed, the more exposures it will be.
4 SNS
There are some popular social media websites like Facebook, LinkedIn, Twitter, Google+. Here you can find the potential customers, and also you can interact with the potential customers.
5 Blogs
You can also use some Free blogs, like WordPress, blogger, LiveJournal, Tumblr and so on.
6 Forums
The forum is a place of gathering people together with the relative topic and same interests. You can find the relative forums to interact with them.
7 Bookmarks
Most customers like to read information via bookmarks, such as, Digg, Dig, Diggo, Reddit, StumbleUpon, Folkd and so on. So you can start to share some interesting things for them.


What is blog posting and how can i do it? like this
  • Social media promotion(Facebook, twitter, Google+, Instagram, Tumblr)
  • Blog posting
  • Blog commenting
  • Guest blogging
  • Article submission
  • Question and Answering site
  • Directory Submission one site i have seen for this which will give your website huge amount of traffic visit:- Business Directory Listing IndiaLocal Business Listing
  • Profile creation
  • Social bookmarking
  • Video promotion
  • Press release submission
  • Blog submission. For that you have to submit your blog in blog submission site.

Local Listing Sites :
  1. Yelp
  2. CrunchBase accelerates innovation by bringing together data on companies and the people behind them.
  3. Free online business directory
  4. Yellow Pages, the new yellowpages.com
  5. http://www.manta.com/
  6. Small Business Services and Business Directory
  7. about.me
  8. Marketing and Media in South Africa
  9. Cylex Business Directory USA
  10. CrunchBase accelerates innovation by bringing together data on companies and the people behind them.
  11. http://1millionfreehit.com/
Social Bookmarking Sites :
  1. Delicious
  2. folkd.com - social bookmarking
  3. StumbleUpon
  4. the front page of the internet
  5. Better reading and research with annotation, highlighter, sticky notes, archiving, bookmarking & more.

how to create responsive website using css , html without bootstrap Or Responsive Website Using Media query



HTML CSS MEdia Query 

what is viewPort:
              View Port is a user visible part of any webpage. what ever you see on webpage and view port manage with of content or a page in responsive website

How To Set View Port:
ex:- <meta name="viewport" content="width=device-width, initial-scale=1.0">

What is Responsive Website :
An Responsive Website is a Type of Website which is suitable for all type's of Devices Like mobile Devices,teblat Devices,laptop ,and PC.Any of the devices browse the website that essly manage there all content autometically no need to write deffrent code for each and every device .only one Responsive website

how to create responsive website:
                              There are two ways to developed responsive website
1).built in repository like bootstrap
2).Create Your Own code using html css (usign Media query)

what is media query:
                  It is  usesd the @media rule to include a block of CSS properties only if a certain condition is true.

example:
________________________________________________________________________________

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
    background-color: red;
}
@media only screen and (max-width: 768px) {
    body {
        background-color: silver;
    }
}
@media only screen and (max-width: 600px) {
    body {
        background-color: lightblue;
    }
}
@media only screen and (max-width: 420px) {
    body {
        background-color: green;
    }
}
@media only screen and (max-width: 360px) {
    body {
        background-color: yellow;
    }
}
</style>
</head>
<body>
<ol>
<li>
<p>
Resize the browser window. When the width of this document is greater then 768 pixels or more, the background-color is  "red".</p>
</li>
<li>
<p>
Resize the browser window. When the width of this document is 768 pixels or less, the background-color is silver </p>
</li>

<li>
<p>
Resize the browser window. When the width of this document is 420 pixels or less, the background-color is "green" .</p>
</li>

<li>
<p>
Resize the browser window. When the width of this document is 360 pixels or less, the background-color is yellow </p>
</li>

</ul>
</body>
</html>
_________________________________________________________________________________