Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MVC3 ASP.NET4.0
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.
 
 public ActionResult Create()
        {
            EmployeeContext empDB = new EmployeeContext();
            Employee emp = new Employee();
            var emp1 = new Employee()
            {
                CheckInTime = DateTime.Now
               
            };
            empDB.SaveChanges();
            
            return View(emp1);
 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 26-Feb-12 4:41am
Edited 27-Feb-12 4:34am
v6
Comments
M Ali Qadir at 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)



Advertise | Privacy | Mobile
Web03 | 2.8.150327.1 | Last Updated 27 Feb 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100