Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
I have Updated the code,In which I am getting current date time when I click on the "Create New" it fills the field of CheckInTime Automatically and when I click on edit It fills the Checkout field for me but when I click on the save button It arose an Exception"Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries."what should I do to handle the Exception.Kindly Reply.
Thank you.

C#
public ActionResult Create()
       {
           EmployeeContext empDB = new EmployeeContext();
           Employee emp = new Employee();
           var emp1 = new Employee()
           {
               CheckInTime = DateTime.Now

           };
           empDB.SaveChanges();

           return View(emp1);

C#
public ActionResult Edit(int id)
       {

           Employee employee = db.Employees.Find(id);

           if (employee.CheckOutTime == null)
           {
               var emp2 = new Employee();
               {
                   emp2.CheckOutTime = DateTime.Now;
               };
               return View(emp2);
           }

           return View(employee.CheckOutTime);
       }

       //
       // POST: /Employee/Edit/5

       [HttpPost]
       public ActionResult Edit(Employee employee)
       {
           Employee em = new Employee();

           if (ModelState.IsValid)
           {
               db.Entry(employee).State = EntityState.Modified;
               db.SaveChanges();
               return RedirectToAction("Index");
           }

           return View(employee.CheckOutTime=System.DateTime.Today);
       }

       //
       // GET: /Employee/Delete/5

       public ActionResult Delete(int id)
       {
           Employee employee = db.Employees.Find(id);
           return View(employee);
       }
Posted
Updated 27-Feb-12 3:34am
v6
Comments
M Ali Qadir 28-Feb-12 8:40am    
Please reply to this post thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900