Beispiel #1
0
        public Employee Add(UpdateEmployeeRequest request)
        {
            var department = this.MapToDataAccess(request);
            var added      = this.context.Employees.Add(department);

            this.context.Employees.SaveChanges();
            var result = this.MapToResponse(added);

            return(result);
        }
Beispiel #2
0
 private DataAccess.Employees.Employee MapToDataAccess(UpdateEmployeeRequest request)
 {
     return(new DataAccess.Employees.Employee
     {
         FirstName = request.FirstName,
         LastName = request.LastName,
         MiddleName = request.MiddleName,
         HiredAt = request.HiredAt,
         Position = request.Position
     });
 }
Beispiel #3
0
        public Employee Update(int id, UpdateEmployeeRequest request)
        {
            var item = this.context.Employees.FirstOrDefaultItem(item => item.Id == id);

            if (item == null)
            {
                throw new RequestedResourceNotFoundException();
            }

            item.ChangedAt  = DateTime.Now;
            item.HiredAt    = request.HiredAt;
            item.LastName   = request.LastName;
            item.FirstName  = request.FirstName;
            item.MiddleName = request.MiddleName;
            item.Position   = request.Position;

            var updated = this.context.Employees.Update(item);

            this.context.Employees.SaveChanges();
            var result = this.MapToResponse(updated);

            return(result);
        }