Esempio n. 1
0
 public IActionResult AddEmployee(InputEmployeeModel employeeInputModel)
 {
     context.Employees.Add(new Employee()
     {
         FirstName      = employeeInputModel.Name,
         LastName       = employeeInputModel.LastName,
         Specialization = employeeInputModel.Specialization,
         Rating         = employeeInputModel.Rating,
         YearsOfWork    = int.Parse(employeeInputModel.OverallTenure)
     });
     context.SaveChanges();
     return(StatusCode((int)HttpStatusCode.OK));
 }
Esempio n. 2
0
        public IActionResult EditEmployee(InputEmployeeModel 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));
        }