public async Task <WorkEditViewModel> EditDeleteForm(int id, string userName) { var work = await this.workRepo.All().SingleOrDefaultAsync(w => w.Id == id); var user = await this.userRepo.All().SingleOrDefaultAsync(u => u.ResumeId == work.ResumeId); var currentUser = user.UserName; if (userName != currentUser) { return(null); } WorkEditViewModel model = null; if (work != null) { model = new WorkEditViewModel { Id = work.Id, Company = work.Company, Title = work.Title, Description = work.Description, StartDate = work.StartDate, EndDate = work.EndDate.HasValue ? work.EndDate.Value : (DateTime?)null, Country = work.Country, Region = work.Region, City = work.City, ResumeId = work.ResumeId }; } return(model); }
public ActionResult Create() { Work work = new Work(); IEnumerable <Project> projects = _projectRepository.GetAll(); IEnumerable <WorkType> workTypes = _workTypeRepository.GetAll(); WorkEditViewModel viewModel = Mapper.Map <Work, WorkEditViewModel>(work) .Map(projects) .Map(workTypes); return(PartialView("_Create", viewModel)); }
public ActionResult Create(WorkEditViewModel viewModel) { if (ModelState.IsValid) { Work work = Mapper.Map <WorkEditViewModel, Work>(viewModel); work.UserID = User.Identity.GetUserId(); _workRepository.Add(work); _workRepository.Save(); return(Json(new { success = true })); } return(PartialView("_Create")); }
public ActionResult Edit(WorkEditViewModel viewModel) { if (ModelState.IsValid) { Work work = Mapper.Map(viewModel, _workRepository.GetById(viewModel.ID)); //work.UserID = User.Identity.GetUserId(); _workRepository.Update(work); _workRepository.Save(); string url = Url.Action("Index", "Time"); return(Json(new { success = true, url })); } return(PartialView("_Edit", viewModel)); }
public async Task Delete(WorkEditViewModel model) { if (model == null) { throw new NullReferenceException("Invalid data"); } var work = await this.workRepo.GetByIdAsync(model.Id); try { this.workRepo.Delete(work); await this.workRepo.SaveChangesAsync(); } catch (Exception e) { throw new InvalidOperationException($"Unable to delete work model {model.Id} id.", e); } }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Work work = _workRepository.GetById((int)id); if (work == null) { return(HttpNotFound()); } IEnumerable <Project> projects = _projectRepository.GetAll(); IEnumerable <WorkType> workTypes = _workTypeRepository.GetAll(); WorkEditViewModel viewModel = Mapper.Map <Work, WorkEditViewModel>(work) .Map(projects) .Map(workTypes); return(PartialView("_Edit", viewModel)); }
public async Task Update(WorkEditViewModel model) { if (model == null) { throw new NullReferenceException("Invalid data"); } if (this.resumeId == null) { throw new InvalidOperationException($"Resume id is null."); } var work = new WorkExperience { Id = model.Id, Company = this.sanitizer.Sanitize(model.Company), Title = this.sanitizer.Sanitize(model.Title), Description = this.sanitizer.Sanitize(model.Description), StartDate = model.StartDate, EndDate = model.EndDate.HasValue ? model.EndDate.Value : (DateTime?)null, Country = model.Country, Region = model.Region, City = model.City, ResumeId = this.resumeId.Value }; this.workRepo.Update(work); try { await this.workRepo.SaveChangesAsync(); } catch (Exception e) { throw new InvalidOperationException(e.Message); } }