public async Task <IActionResult> Create(EmoloyeeCreateBindingModel model) { if (ModelState.IsValid) { var serviceModel = new EmployeeCreateServiceModel() { FirstName = model.FirstName, LastName = model.LastName, Salary = model.Salary, StartingDate = model.StartingDate, VacationDays = model.VacationDays, ExperienceLevel = model.ExperienceLevel }; bool result = await this._employeeServices.CreateEmployeeAsync(serviceModel); if (!result) { return(RedirectToAction("Error", "Home")); } return(RedirectToAction("Index", "Employee")); } return(View(model)); }
public async Task <int> AddAsync(EmployeeCreateServiceModel employeeDto) { //string imagePath = await fileService.SaveFileToFolderAsync(employeeDto.Image, "Resources", "Images"); Employee employee = new Employee { FirstName = employeeDto.FirstName, LastName = employeeDto.LastName, Salary = employeeDto.Salary, StartingDate = employeeDto.StartingDate, VacationDays = employeeDto.VacationDays, ExperienceLevel = employeeDto.ExperienceLevel, //Image = imagePath, }; foreach (var officeId in employeeDto.OfficeIds) { employee.OfficeEmployees.Add(new OfficeEmployee { OfficeId = officeId }); } dbContext.Employees.Add(employee); await dbContext.SaveChangesAsync(); return(employee.Id); }
public async Task <ActionResult> EditAsync(int id, [FromBody] EmployeeCreateModel employee) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!await employeesService.ExistsAsync(id)) { return(NotFound()); } EmployeeCreateServiceModel employeeToCreate = new EmployeeCreateServiceModel { Id = id, FirstName = employee.FirstName, LastName = employee.LastName, Salary = employee.Salary, ExperienceLevel = employee.ExperienceLevel, StartingDate = employee.StartingDate, VacationDays = employee.VacationDays, Image = employee.Image }; await employeesService.EditAsync(employeeToCreate); return(NoContent()); }
public async Task <ActionResult> CreateAsync([FromBody] EmployeeCreateModel employee) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } EmployeeCreateServiceModel employeeToCreate = new EmployeeCreateServiceModel { FirstName = employee.FirstName, LastName = employee.LastName, Salary = employee.Salary, ExperienceLevel = employee.ExperienceLevel, StartingDate = employee.StartingDate, VacationDays = employee.VacationDays, Image = employee.Image, OfficeIds = employee.OfficeIds }; //TODO: Fix the image problem. //var file = Request.Form.Files[0]; int createdEmployeeId = await employeesService .AddAsync(employeeToCreate); return(CreatedAtAction(nameof(GetByIdAsync), new { id = createdEmployeeId })); }
public async Task <bool> CreateEmployeeAsync(EmployeeCreateServiceModel model) { Employee employee = new Employee { FirstName = model.FirstName, LastName = model.LastName, ExperienceLevel = model.ExperienceLevel, Salary = model.Salary, StartingDate = model.StartingDate, VacationDays = model.VacationDays, }; this._context.Employees.Add(employee); int result = await this._context.SaveChangesAsync(); if (result > 0) { return(true); } return(false); }
public async Task EditAsync(EmployeeCreateServiceModel employeeDto) { Employee employee = await dbContext .Employees .FindAsync(employeeDto.Id); if (employee == null) { return; } string imagePath = await fileService.SaveFileToFolderAsync(employeeDto.Image, "Resources", "Images"); employee.FirstName = employeeDto.FirstName; employeeDto.LastName = employeeDto.LastName; employee.Salary = employeeDto.Salary; employee.ExperienceLevel = employeeDto.ExperienceLevel; employee.StartingDate = employeeDto.StartingDate; employee.VacationDays = employeeDto.VacationDays; employee.Image = imagePath; await dbContext.SaveChangesAsync(); }