public async Task <IActionResult> Promote(EmployeeInputModel input, string id) { var userData = await userService.GetUserAsync <EmployeeInputModel>(id); if (userData == null) { return(this.NotFound()); } if (!ModelState.IsValid) { return(this.View(input)); } var appUser = await userManager.FindByIdAsync(id); await userManager.AddToRoleAsync(appUser, "Employee"); var employee = new EmployeeData { UserId = id, UCN = input.UCN, SecondName = input.SecondName, IsActive = true, DateOfAppointment = DateTime.UtcNow, User = appUser, DateOfResignation = null, }; await userService.UpdateAsync(employee); return(RedirectToAction("Index", "Users")); }
public ActionResult Add(EmployeeInputModel model) { if (!ModelState.IsValid) { return(View(model)); } if (this.employeesService.AllEmployees().Any(e => e.Position == CompanyRoleType.CEO) && model.Position == CompanyRoleType.CEO) { ModelState.AddModelError(string.Empty, Constants.CeoExistsMessage); return(View(model)); } if (!this.employeesService.AllEmployees().Any(e => e.Position == CompanyRoleType.CEO) && model.Position != CompanyRoleType.CEO) { ModelState.AddModelError(string.Empty, Constants.NoCeoMessage); return(View(model)); } var employee = this.mappingService.Map <Employee>(model); this.employeesService.AddEmployee(employee); return(RedirectToAction(Constants.Index)); }
public async Task <IActionResult> Create(EmployeeInputModel model) { this.FillEmployeeInputModel(); if (!this.ModelState.IsValid) { return(this.View("Create", this.employeeInputModel)); } var employee = new CreateEmployeeServiceModel { JobPositionId = model.JobPositionId, OperatingLocationId = model.OperatingLocationId, FirstName = model.FirstName, MiddleName = model.MiddleName, LastName = model.LastName, Phone = model.Phone, Email = model.Email, Town = model.Town, Address = model.Address, ImageUrl = model.ImageUrl, }; await this.employeesService.CreateAsync(employee); return(this.RedirectToAction("Create")); }
//------------- CONSTRUCTORS -------------- public EmployeesController(IEmployeesService employeesService, IJobPositionsService jobPositionsService, IOperatingLocationsService operatingLocationsService) { this.employeesService = employeesService; this.jobPositionsService = jobPositionsService; this.operatingLocationsService = operatingLocationsService; this.employeeInputModel = new EmployeeInputModel(); }
public async Task <IActionResult> Edit(EmployeeInputModel model) { if (!this.employeesService.Exists(model.Id)) { return(this.BadRequest()); } if (!ModelState.IsValid) { return(this.RedirectToAction("Error", "Home")); } EditEmployeeServiceModel serviceModel = new EditEmployeeServiceModel { Id = model.Id, JobPositionId = model.JobPositionId, OperatingLocationId = model.OperatingLocationId, FirstName = model.FirstName, MiddleName = model.MiddleName, LastName = model.LastName, Phone = model.Phone, Email = model.Email, Town = model.Town, Address = model.Address, ImageUrl = model.ImageUrl, }; await this.employeesService.EditAsync(serviceModel); return(this.RedirectToAction("Details", "Employees", new { id = serviceModel.Id })); }
public async Task <ResultData <Employee> > CreateEmployee(EmployeeInputModel inputModel) { if (string.IsNullOrEmpty(inputModel.FirstName) || string.IsNullOrEmpty(inputModel.LastName)) { return(new ResultData <Employee>(EmployeeNamesNotFoundMessage, false, null)); } if (inputModel.StartingDate < DateTime.Today) { return(new ResultData <Employee>(InvalidStartDateMessage, false, null)); } if (inputModel.Salary < 0) { return(new ResultData <Employee>(InvalidSalaryMessage, false, null)); } Employee employee = new Employee { FirstName = inputModel.FirstName, LastName = inputModel.LastName, ExperienceLevel = inputModel.ExperienceLevel, Salary = inputModel.Salary, StartingDate = inputModel.StartingDate, VacationDays = 20, OfficeId = inputModel.OfficeId }; await this.employeeRepository.CreateNewEmployee(employee); return(new ResultData <Employee>(EmployeeAddedMessage, true, employee)); }
public IActionResult Index(EmployeeInputModel model) { if (!ModelState.IsValid) { return(View(model)); } var json = JsonConvert.SerializeObject(model); return(Content(json)); }
public int CreateEmployee(RegisterInputModel model) { var employee = new EmployeeInputModel { Email = model.Email, FirstName = model.FirstName, LastName = model.LastName }; return(_employeeRepo.AddEmployee(employee)); }
public Employee Add(EmployeeInputModel employee) { return(_employeeService.Add( new Employee { PersonId = employee.PersonId, Salary = employee.Salary, Date = employee.Date } )); }
public async Task <IActionResult> Edit(EmployeeInputModel model) { if (!this.ModelState.IsValid) { return(this.View(model)); } await this.employeeService.EditAsync <EmployeeInputModel>(model); return(this.Redirect("/Home/Index")); }
public async Task <IActionResult> Index(EmployeeInputModel model) { if (!ModelState.IsValid) { var lineEmployees = _employeeService.GetAll(); var lineEmployeesModels = lineEmployees.Select(x => new EmployeeViewModel { Id = x.Id, Name = $"{x.FirstName} {x.LastName}" }); model.LineEmployees = lineEmployeesModels; return(View(model)); } var employee = await _employeeService.GetByIdAsync(model.Id); if (employee == null) { employee = new Employee { Address = model.Address, Amount = model.Amount, DateJoinedCompany = model.DateJoinedCompany, Department = model.Department, FirstName = model.FirstName, LastName = model.LastName, IsMonthly = model.IsMonthly, JobTitle = model.JobTitle, LineManagerEmployeeId = model.LineManagerEmployeeId, CreatedDateTime = DateTime.Now, IsActive = true }; } else { employee.Address = model.Address; employee.Amount = model.Amount; employee.DateJoinedCompany = model.DateJoinedCompany; employee.Department = model.Department; employee.FirstName = model.FirstName; employee.LastName = model.LastName; employee.IsMonthly = model.IsMonthly; employee.JobTitle = model.JobTitle; employee.LineManagerEmployeeId = model.LineManagerEmployeeId; employee.LastUpdatedDateTime = DateTime.Now; } await _employeeService.SaveChangesAsync(employee); return(Redirect("/Home/Index")); }
public async Task <IActionResult> Add(EmployeeInputModel input) { if (userService.IsAlreadyAdded(input.Email)) { ModelState.AddModelError("Added", "User already added!"); } if (!ModelState.IsValid) { return(this.View(input)); } var appUser = new ApplicationUser { UserName = input.UserName, IsAdult = input.IsAdult, Email = input.Email, FirstName = input.FirstName, LastName = input.LastName, PhoneNumber = input.PhoneNumber, SecurityStamp = DateTime.UtcNow.Ticks.ToString() }; var res = await userManager.CreateAsync(appUser, input.Password); if (res.Errors?.Any() ?? false) { ModelState.AddModelError("General", string.Join("; ", res.Errors.Select(x => x.Description))); return(this.View(input)); } res = await userManager.AddToRoleAsync(appUser, "Employee"); if (res.Errors?.Any() ?? false) { ModelState.AddModelError(nameof(input.Password), string.Join("; ", res.Errors.Select(x => x.Description))); return(this.View(input)); } var employee = new EmployeeData { UserId = appUser.Id, UCN = input.UCN, SecondName = input.SecondName, IsActive = true, DateOfAppointment = DateTime.UtcNow, User = appUser }; await userService.AddAsync(employee); return(RedirectToAction("Index", "Users")); }
public IActionResult Save([FromBody] EmployeeInputModel model) { if (model.Id == 1) { ModelState.AddModelError("Id", "Id already exists"); } if (ModelState.IsValid) { return(Ok(model)); } return(BadRequest(ModelState)); }
public int AddEmployee(EmployeeInputModel model) { var employee = new Employee { Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, }; _db.Add(employee); _db.SaveChanges(); return(employee.Id); }
public async Task <ActionResult <int> > UpdateEmployee(EmployeeInputModel employee) { try { var result = await _employeeComponent.UpdateEmployeeAsync(_mapper.Map <Employee>(employee)); return(Ok(result)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <IActionResult> PutFuncionario(int id, EmployeeInputModel employee) { try { await _employeeService.Update(id, employee); return(Ok()); } //GameDoesNotExistException catch (Exception e) { return(NotFound(e)); } }
public IActionResult Save(EmployeeInputModel model) { // simulate DB call to check existence of Id if (model.Id == 1) { ModelState.AddModelError("Id", "Id already exist"); } if (ModelState.IsValid) { return(Ok(model)); } return(BadRequest(ModelState)); }
public ResultData <EmployeeInputModel> CreateEmployeeInputModel(int officeId) { if (officeId == 0) { return(new ResultData <EmployeeInputModel>(OfficeNotFoundMessage, false, null)); } var model = new EmployeeInputModel { OfficeId = officeId, StartingDate = DateTime.Today }; return(new ResultData <EmployeeInputModel>(EmployeeInputModelCreatedMessage, true, model)); }
public IActionResult AddEmployee([FromBody] EmployeeInputModel employeeInputModel) { var employee = new Employee() { FirstName = employeeInputModel.Name, LastName = employeeInputModel.LastName, Specialization = employeeInputModel.Specialization, Rating = employeeInputModel.Rating, YearsOfWork = int.Parse(employeeInputModel.OverallTenure), }; context.Employees.Add(employee); context.SaveChanges(); return(StatusCode((int)HttpStatusCode.OK)); }
public async Task <ActionResult <EmployeeViewModel> > PostEmployee(EmployeeInputModel employeeModel) { EmployeeCharge employeeCharge = await _employeesRepository.GetAllEmployeeCharges() .FirstOrDefaultAsync(c => c.Id == employeeModel.ChargeId); if (employeeCharge is null) { return(BadRequest("El cargo del empleado no se encuentra registrado.")); } Employee employee = _mapper.Map <Employee>(employeeModel); employee.EmployeeCharge = employeeCharge; IdentityResult result = await _applicationUserRepository.CreateAsync(employee.User, employeeModel.User.Password); if (!result.Succeeded) { return(this.IdentityResultErrors(result)); } IdentityResult roleResult = await _applicationUserRepository.AddToRoleAsync(employee.User, GetEmployeeRole(employee)); if (!roleResult.Succeeded) { return(this.IdentityResultErrors(roleResult)); } _employeesRepository.Insert(employee); try { await _unitWork.SaveAsync(); } catch (DbUpdateException) { if (EmployeeExists(employee.Id)) { return(Conflict($"Ya existe un empleado registrado con el código {employeeModel.Id}")); } throw; } return(_mapper.Map <EmployeeViewModel>(employee)); }
public async Task <IActionResult> Create(EmployeeInputModel inputModel) { if (!ModelState.IsValid) { return(this.View(inputModel)); } var result = await this.employeeService.CreateEmployee(inputModel); if (!result.Success) { return(this.View(inputModel)); } return(this.RedirectToAction(nameof(Details), new { id = result.Data.Id })); }
public async Task <IActionResult> Create([FromBody] EmployeeInputModel employee) { if (employee == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await _employeeRepository.AddAsync(employee.Update(new Employee())); return(NoContent()); }
public async Task <IActionResult> Update(EmployeeInputModel input, string id) { var userData = await userService.GetUserAsync <EmployeeInputModel>(id); if (userData == null) { return(this.NotFound()); } if (!ModelState.IsValid) { return(this.View(input)); } var user = await userManager.FindByIdAsync(id); user.FirstName = input.FirstName; user.LastName = input.LastName; user.IsAdult = input.IsAdult; user.PhoneNumber = input.PhoneNumber; user.UserName = input.UserName; user.Email = input.Email; var data = await userService.GetEmployeeAsync <EmployeeDataViewModel>(id); var employee = new EmployeeData { IsActive = true, DateOfAppointment = data.DateOfAppointment, DateOfResignation = null, SecondName = data.SecondName, UCN = input.UCN, User = user, UserId = id }; user.EmployeeData = employee; await userService.UpdateAsync(employee); await userManager.UpdateAsync(user); return(RedirectToAction("Index", "Users")); }
public async Task <IActionResult> Index(int?employeeId) { var lineEmployees = _employeeService.GetAll(); var lineEmployeesModels = lineEmployees.Select(x => new EmployeeViewModel { Id = x.Id, Name = $"{x.FirstName} {x.LastName}" }); var employee = await _employeeService.GetByIdAsync(employeeId); if (employee == null) { var model = new EmployeeInputModel { LineManagerEmployeeId = 0, LineEmployees = lineEmployeesModels, DateJoinedCompany = DateTime.Now }; return(View(model)); } else { var inputModel = new EmployeeInputModel { Id = employee.Id, Address = employee.Address, Amount = employee.Amount, DateJoinedCompany = employee.DateJoinedCompany, Department = employee.Department, FirstName = employee.FirstName, LastName = employee.LastName, IsMonthly = employee.IsMonthly, JobTitle = employee.JobTitle, LineManagerEmployeeId = employee.LineManagerEmployeeId, LineEmployees = lineEmployeesModels, }; return(View(inputModel)); } }
public IActionResult Edit(string id) { EmployeeServiceModel employee = this.employeesService.GetById(id); if (employee.FullName == null) { return(this.BadRequest()); } var model = new EmployeeInputModel { JobPositionId = employee.JobPositionId, JobPositions = this.jobPositionsService.GetAll().Select(x => new JobPositionsDropdownViewModel { Id = x.Id, JobPositionName = x.Name, }), // TODO: add job positions qualifications table OperatingLocationId = employee.OperatingLocationId, OperatingLocations = this.operatingLocationsService.GetAll().Select(x => new OperatingLocationsDropdownViewModel { Id = x.Id, Town = x.Town, Address = x.Address, }), // TODO: add opLoc img Id = employee.Id, FirstName = employee.FirstName, MiddleName = employee.MiddleName, LastName = employee.LastName, Phone = employee.PhoneNumber, Email = employee.Email, Town = employee.Town, Address = employee.Address, ImageUrl = employee.ImageUrl, }; return(this.View(model)); }
public async Task Update(int id, EmployeeInputModel funcionario) { var entity = await Context.Funcionarios.FirstOrDefaultAsync(x => x.Id == id); if (entity == null) { throw new Exception("Employee does not exist"); } Context.Entry(entity).CurrentValues.SetValues(funcionario); try { await Context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } }
public IActionResult EditEmployee(EmployeeInputModel inputEmployeeModel) { if (inputEmployeeModel == null) { return(new StatusCodeResult((int)HttpStatusCode.BadRequest)); } var employee = context.Employees.FirstOrDefault(x => x.Id == inputEmployeeModel.Id); if (employee == null) { return(new StatusCodeResult((int)HttpStatusCode.NotFound)); } employee.FirstName = inputEmployeeModel.Name; employee.LastName = inputEmployeeModel.LastName; employee.Specialization = inputEmployeeModel.Specialization; employee.Rating = inputEmployeeModel.Rating; employee.YearsOfWork = int.Parse(inputEmployeeModel.OverallTenure); context.SaveChanges(); return(StatusCode((int)HttpStatusCode.OK)); }
public async Task <IActionResult> Update(Guid id, [FromBody] EmployeeInputModel employeeInputModel) { if (employeeInputModel == null) { return(BadRequest()); } var employee = await _employeeRepository.GetByIdAsync(id); if (employee == null) { return(NotFound()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await _employeeRepository.UpdateAsync(employeeInputModel.Update(employee)); return(NoContent()); }
public ActionResult New() { var model = new EmployeeInputModel(); return(View(model)); }
public Task <int> Create(EmployeeInputModel model) { throw new NotImplementedException(); }