public ActionResult Edit(int id, EditWorkDone formModel) { var client = new Client(formModel.ClientId); var workType = new WorkType(formModel.WorkTypeId); var workDone = new WorkDone() { Id = id, ClientId = formModel.ClientId, WorkTypeId = formModel.WorkTypeId, StartedOn = formModel.StartedOn, EndedOn = formModel.EndedOn }; try { var repo = new WorkDoneRepository(_context); repo.Update(workDone); return(RedirectToAction("Index")); } catch { ModelState.AddModelError("Edit", "Unable to update work done"); return(View(formModel)); } }
public ActionResult Finish(int?id) { if (!id.HasValue) { return(RedirectToAction("Index")); } WorkDoneRepository repo = new WorkDoneRepository(context); WorkDone wd = repo.GetById((int)id); wd.Finished(); repo.Update(wd); return(RedirectToAction("Index")); }
public ActionResult Edit(int id, EditWorkDone workDone) { WorkDoneRepository workDoneRepo = new WorkDoneRepository(); // Populate DropDowns ClientRepository clientRepo = new ClientRepository(); Client client = clientRepo.GetById(workDone.ClientId); WorkTypeRepository workTypeRepo = new WorkTypeRepository(); WorkType workType = workTypeRepo.GetById(workDone.WorkTypeId); // Repopulate DropDown Lists ClientRepository clientsRepo = new ClientRepository(); List <Client> clients = clientsRepo.GetClients(); WorkTypeRepository workTypesRepo = new WorkTypeRepository(); List <WorkType> workTypes = workTypesRepo.GetWorkTypes(); WorkDone newWorkDone = new WorkDone(id, client, workType, workDone.StartedOn, workDone.EndedOn); // Populate View Model EditWorkDone editWorkDone = new EditWorkDone(clients, workTypes); editWorkDone.ClientId = workDone.ClientId; editWorkDone.WorkTypeId = workDone.WorkTypeId; editWorkDone.StartedOn = workDone.StartedOn; editWorkDone.EndedOn = workDone.EndedOn; // If it's good, submit and go back. if (ModelState.IsValid) { workDoneRepo.Update(newWorkDone); return(RedirectToAction("Index")); } // If it's not, show page again. return(View("Edit", editWorkDone)); }