public async Task <Employee> AddEmployeeAsync(EmployeeCreationBindingModel model) { var employee = this.Mapper.Map <Employee>(model); await this.DbContext.Employees.AddAsync(employee); await this.DbContext.SaveChangesAsync(); return(employee); }
public async Task <IActionResult> Add(EmployeeCreationBindingModel model) { if (!ModelState.IsValid) { return(View()); } var employee = await this.employeesSecrvice.AddEmployeeAsync(model); return(this.RedirectToAction("Details", new { id = employee.EmployeeId })); }
public async Task <IActionResult> Create(EmployeeCreationBindingModel model) { if (!ModelState.IsValid) { return(View()); } var result = await this.employeesService.CreateAsync(model); if (result == 0) { this.TempData[WebConstants.BadMessage] = string.Format(Messages.EmployeeHiredErrorMessage, model.FirstName); } else { this.TempData[WebConstants.GoodMessage] = string.Format(Messages.EmployeeHiredSuccessMessage, model.FirstName); } return(RedirectToAction("AllEmployees", "Employees", new { area = WebConstants.AdminArea })); }
public async Task <int> CreateAsync(EmployeeCreationBindingModel model) { var employee = this.Mapper.Map <User>(model); try { await this.userManager.CreateAsync(employee, model.Password); await userManager.AddToRoleAsync(employee, model.Role); } catch { //failure return(0); } //success return(1); }