public async Task <IHttpActionResult> AppendJob(int id, [FromBody] JobEditBindingModel model) { var job = AutoMapper.Mapper.Map <Job>(model); await _jobManager.UpdateAndSave(job, UserId); return(Ok()); }
public async Task <IActionResult> Edit(int?id, JobEditBindingModel model) { var company = await companyService.GetCompanyForUser(this.User?.Identity?.Name); if (id == null) { return(this.NotFound()); } var serviceModel = await this.jobsService.GetAsync(id); if (serviceModel == null || serviceModel.CompanyId != company.Id) { return(this.NotFound()); } serviceModel.Id = (int)id; serviceModel.Title = model.Title; serviceModel.Location = model.Location; serviceModel.CategoryId = (int)model.CategoryId; serviceModel.JobTypeId = (int)model.JobTypeId; serviceModel.Description = model.Description; serviceModel.Responsibilities = model.Responsibilities; serviceModel.Benefits = model.Benefits; serviceModel.Education = model.Education; serviceModel.EndDate = model.EndDate; serviceModel.Qualification = model.Qualification; if (!this.ModelState.IsValid) { var bindingModel = Mapper.Map <JobEditBindingModel>(serviceModel); bindingModel.JobCategories = await GetAllJobCategoriesAsync(); bindingModel.JobTypes = GetAllJobTypes(); return(this.View(bindingModel)); } var result = await this.jobsService.UpdateAsync(serviceModel); if (result) { this.Success(NotificationMessages.JobEdited); } else { this.Error(NotificationMessages.JobEditError); } return(this.RedirectToAction("ManageJobs", "Company", new { Area = "AccountManagement" })); }
public async Task <IHttpActionResult> Put(int id, [FromBody] JobEditBindingModel model) { // check model sanity var jobs = _jobManager.GetGraphs(x => x.Id == id); var job = jobs.SingleOrDefault(); if (job == null) { return(BadRequest(string.Format("Ошибка: Заказ с Id = {0} не найден.", id))); } AutoMapper.Mapper.Map <JobEditBindingModel, Job>(model, job); await _jobManager.UpdateAndSave(job, UserId); return(Ok()); }