Beispiel #1
0
 public JsonResult UpdatePostIt(PostItHelpModel postItHelpModel)
 {
     if (ModelState.IsValid)
     {
         using (PostItRepository _postItRepo = new PostItRepository(ApplicationDbContext.Create()))
             using (CustomerRepository _customerRepository = new CustomerRepository(ApplicationDbContext.Create()))
                 using (EmployeeRepository _employeeRepository = new EmployeeRepository(ApplicationDbContext.Create()))
                 {
                     PostIt postIt = _postItRepo.Find(postItHelpModel.id);
                     postIt.Title      = postItHelpModel.title;
                     postIt.From       = postItHelpModel.start;
                     postIt.To         = postItHelpModel.end;
                     postIt.CustomerId = postItHelpModel.customerId;
                     postIt.EmployeeId = postItHelpModel.employeeId;
                     postIt.DayOfWeek  = postItHelpModel.dayOfWeek;
                     postIt.Note       = postItHelpModel.note;
                     postIt.TemplateNo = postItHelpModel.templateNo;
                     postIt.IsAssigned = true;
                     _postItRepo.Update(postIt);
                     _postItRepo.Save();
                     return(Json(true));
                 }
     }
     return(Json(false));
 }
        public ActionResult Delete(int id)
        {
            using (ICustomerRepository _customerRepo = new CustomerRepository(ApplicationDbContext.Create()))
                using (IPostItRepository _postItRepo = new PostItRepository(ApplicationDbContext.Create()))
                {
                    var postItsForCus = _postItRepo.AllForCustomer(id).ToList();
                    foreach (var postIt in postItsForCus)
                    {
                        postIt.IsAssigned = false;
                        _postItRepo.Update(postIt);
                        _postItRepo.Save();
                    }

                    _customerRepo.Delete(id);
                    _customerRepo.Save();
                    return(RedirectToAction("Index"));
                }
        }