public async Task <IActionResult> Add(AddAndEditEmployeeBindingModel model) { if (!ModelState.IsValid) { this.TempData["__MessageType"] = MessageType.Warning; this.TempData["__MessageText"] = Constants.ErrorMessages.InvalidFormData; return(View(model)); } var id = await this.employeeService.AddEmployeeAsync(model); this.TempData["__MessageType"] = MessageType.Success; this.TempData["__MessageText"] = Constants.SuccessMessages.EmployeeAdded; return(this.RedirectToAction("Details", new { id })); }
public async Task <AddAndEditEmployeeBindingModel> GetInitialEmployeeInfo(int id) { var model = new AddAndEditEmployeeBindingModel() { CompanyId = id, ExperienceLevels = await this.DbContext.Levels .Select(b => new SelectListItem() { Text = b.ExperienceLevel.ToString(), Value = b.Id.ToString() }) .ToListAsync() }; return(model); }
public async Task <int> EditEmployeeAsync(AddAndEditEmployeeBindingModel model) { var employee = this.Mapper.Map <Employee>(model); employee.ExperienceLevel = await this.DbContext .Levels .FindAsync(int.Parse(model .ExperienceLevelId)); employee.Company = await this.DbContext .Companies .FindAsync(model .CompanyId); this.DbContext.Employees.Update(employee); await this.DbContext.SaveChangesAsync(); return(employee.Id); }