public ActionResult Edit(int id) { var repo = new WorkTypeRepository(_context); var workType = repo.GetById(id); var formModel = new EditWorkType { Id = workType.Id, Name = workType.Name, Rate = workType.Rate }; return(View(formModel)); }
public ActionResult Edit(int?id) { if (!id.HasValue) { return(RedirectToAction("Index")); } WorkTypeRepository repo = new WorkTypeRepository(context); WorkType workType = repo.GetById((int)id); if (workType == null) { return(RedirectToAction("Index")); } EditWorkType editWorkType = new EditWorkType(); editWorkType.Id = workType.Id; editWorkType.Name = workType.Name; editWorkType.Rate = workType.Rate; return(View(editWorkType)); }
public ActionResult Delete(int?id) { if (id == null) { return(RedirectToAction("Index")); } WorkTypeRepository repo = new WorkTypeRepository(); WorkType workType = repo.GetById(id.Value); if (workType == null) { return(RedirectToAction("Index")); } DeleteWorkType model = new DeleteWorkType(); model.Id = workType.Id; model.Name = workType.Name; return(View("Delete", model)); }
public ActionResult Create(CreateWorkDone workDone) { WorkDoneRepository workDoneRepo = new WorkDoneRepository(); // Get DropDownList values ClientRepository clientRepo = new ClientRepository(); Client client = clientRepo.GetById(workDone.ClientId); WorkTypeRepository workTypeRepo = new WorkTypeRepository(); WorkType workType = workTypeRepo.GetById(workDone.WorkTypeId); WorkDone newWorkDone = new WorkDone(0, client, workType, DateTimeOffset.Now); // If it's good, submit and go back to Index. if (ModelState.IsValid) { workDoneRepo.Insert(newWorkDone); return(RedirectToAction("Index")); } // If it's not good, repost the page with errors. return(View("Create", workDone)); }
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)); }