Exemplo n.º 1
0
 public ActionResult Edit(int id, NoteEdit newItem)
 {
     if (!ModelState.IsValid)
     {
         // If there's a problem with the form data postback, redisplay the form
         var form = AutoMapper.Mapper.Map <NoteEditForm>(newItem);
         // If there's a problem with the form data postback, redisplay the form
         return(View(form));
     }
     else
     {
         var updatedItem = m.UpdateNoteForAuthenticatedEmployee(newItem);
         return(RedirectToAction("Details", "Employees", new { id = updatedItem.EmployeeId }));
     }
 }
Exemplo n.º 2
0
        public NoteBase UpdateNoteForAuthenticatedEmployee(NoteEdit newItem)
        {
            // Validate the incoming item, by fetching the employee object
            Employee employee = ds.Employees.Find(newItem.EmployeeId);

            if (employee == null)
            {
                return(null);
            }
            else if (employee.IdentityUserId != User.Identity.Name)
            {// Test whether the user is the same as the security context user
                return(null);
            }
            else
            {// If yes, can add the new note object, and then return it
                //update note
                ds.Entry(ds.Notes.Find(newItem.NoteId)).CurrentValues.SetValues(Mapper.Map <NoteAdd>(newItem));

                var returnItem = Mapper.Map <NoteBase>(newItem);
                returnItem.EmployeeId = newItem.EmployeeId;
                ds.SaveChanges();
                return(Mapper.Map <NoteBase>(returnItem));
            }
        }