Exemplo n.º 1
0
 public IActionResult Put(int id, [FromBody] UpdateEmployeeViewModel employeeViewModel)
 {
     if (employeeViewModel != null)
     {
         employeeViewModel.ID = id;
         if (string.IsNullOrEmpty(employeeViewModel.UserName))
         {
             employeeViewModel.UserName = iEmployeeRepository.GetEmployeeByID(employeeViewModel.ID).UserName;
         }
         //TO DO for later on: move the update logic for the employee position into a service
         List <PositionApplicationRole> positions = iPositionRepository.GetPositions();
         if (employeeViewModel.Position.Id == 0)
         {
             employeeViewModel.Position = iEmployeeRepository.GetEmployeeByID(employeeViewModel.ID).Position;
         }
         else
         {
             PositionApplicationRole employeePositionFromDropDownList = positions.Where(x => x.Id == employeeViewModel.Position.Id).FirstOrDefault();
             employeeViewModel.Position = employeePositionFromDropDownList;
         }
         EmployeeApplicationUser employee = new EmployeeApplicationUser()
         {
             Id       = employeeViewModel.ID,
             UserName = employeeViewModel.UserName,
             Position = employeeViewModel.Position
         };
         iEmployeeRepository.UpdateEmployee(employee);
         iUnitOfWork.Save();
         return(Ok(employee));
     }
     else
     {
         return(NotFound("Employee with ID " + id.ToString() + " was not found."));
     }
 }
Exemplo n.º 2
0
 public IActionResult Post([FromBody] EmployeeApplicationUser employee)
 {
     try
     {
         //TO DO for later on: move the create logic for the employee position into a service
         List <PositionApplicationRole> positions = iPositionRepository.GetPositions();
         if (employee.Position == null || employee.Position.Id == 0)
         {
             employee.Position = positions.Where(x => x.Name == "No Position!").FirstOrDefault();
         }
         else
         {
             PositionApplicationRole employeePositionFromDropDownList = positions.Where(x => x.Id == employee.Position.Id).FirstOrDefault();
             employee.Position = employeePositionFromDropDownList;
         }
         iEmployeeRepository.CreateEmployee(employee);
         Uri uri = new Uri(Url.Link("GetEmployeeByID", new { Id = employee.Id }));
         iUnitOfWork.Save();
         return(Created(uri, employee.Id.ToString()));
     }
     catch (Exception ex)
     {
         return(Content(ex.ToString(), BadRequest().ToString()));
     }
 }
Exemplo n.º 3
0
        public void DeletePosition(int id)
        {
            PositionApplicationRole position = GetPositionByID(id);

            if (position != null)
            {
                dbContext.Positions.Remove(position);
            }
        }
Exemplo n.º 4
0
        public void UpdatePosition(PositionApplicationRole position)
        {
            PositionApplicationRole positionToUpdate = GetPositionByID(position.Id);

            if (positionToUpdate != null)
            {
                // this code might be extended later, for more property updates
                positionToUpdate.Name = position.Name;
                dbContext.Positions.Update(positionToUpdate);
            }
        }
        public IActionResult GetPositionByID(int id)
        {
            PositionApplicationRole position = iPositionRepository.GetPositionByID(id);

            if (position != null)
            {
                return(Ok(position));
            }
            else
            {
                return(NotFound("Position with ID " + id.ToString() + " was not found."));
            }
        }
        public IActionResult Delete(int id)
        {
            PositionApplicationRole positionToDelete = iPositionRepository.GetPositionByID(id);

            if (positionToDelete != null)
            {
                iPositionRepository.DeletePosition(positionToDelete.Id);
                //if a certain employee has this position(the position for deletion), we are setting his position to be "No Position!"
                positionToDelete.Employees.ForEach(x =>
                                                   x.Position = iPositionRepository.GetPositions().Where(x => x.Name == "No Position!").FirstOrDefault());
                iUnitOfWork.Save();
                return(Ok(positionToDelete));
            }
            else
            {
                return(NotFound("Position with ID " + id.ToString() + " was not found."));
            }
        }
 public IActionResult Post([FromBody] CreatePositionViewModel createPositionViewModel)
 {
     try
     {
         PositionApplicationRole position = new PositionApplicationRole()
         {
             Id   = createPositionViewModel.ID,
             Name = createPositionViewModel.Name
         };
         iPositionRepository.CreatePosition(position);
         Uri uri = new Uri(Url.Link("GetPositionByID", new { Id = position.Id }));
         iUnitOfWork.Save();
         return(Created(uri, position.Id.ToString()));
     }
     catch (Exception ex)
     {
         return(Content(ex.ToString(), BadRequest().ToString()));
     }
 }
 public IActionResult Put(int id, [FromBody] UpdatePositionViewModel updatePositionViewModel)
 {
     if (updatePositionViewModel != null)
     {
         updatePositionViewModel.ID = id;
         if (string.IsNullOrEmpty(updatePositionViewModel.Name))
         {
             updatePositionViewModel.Name = iPositionRepository.GetPositionByID(updatePositionViewModel.ID).Name;
         }
         PositionApplicationRole position = new PositionApplicationRole()
         {
             Id        = updatePositionViewModel.ID,
             Name      = updatePositionViewModel.Name,
             Employees = iPositionRepository.GetPositionByID(updatePositionViewModel.ID).Employees
         };
         iPositionRepository.UpdatePosition(position);
         iUnitOfWork.Save();
         return(Ok(position));
     }
     else
     {
         return(NotFound("Position with ID " + id.ToString() + " was not found."));
     }
 }
Exemplo n.º 9
0
 public void CreatePosition(PositionApplicationRole position)
 {
     dbContext.Positions.Add(position);
 }