Beispiel #1
0
        public IHttpActionResult GetEmployeePassport(int id)
        {
            try
            {
                UnitOfWork       unitOfWork = new UnitOfWork(factory);
                EmployeePassport p          = unitOfWork.EmployeePassportsRepository
                                              .Get(d => d.Id == id,
                                                   includeProperties: "Address,Address.Country,Address.AddressLocality,Address.AddressPlace,Address.AddressRegion,Address.AddressVillage")
                                              .FirstOrDefault();
                EmployeePassportDTO employeePassport = p.ToDTO();

                return(Ok(employeePassport));
            }
            catch (NotFoundException nfe)
            {
                return(NotFound());
            }
            catch (ConflictException ce)
            {
                return(Conflict());
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Beispiel #2
0
 public IHttpActionResult PostEmployeePassport(EmployeePassportDTO employeePassport)
 {
     if (employeePassport == null)
     {
         return(BadRequest(ModelState));
     }
     try
     {
         EmployeePassport passport   = employeePassport.FromDTO();
         UnitOfWork       unitOfWork = new UnitOfWork(factory);
         passport.Address.Id = passport.Address.NewId(unitOfWork);
         passport.AddressId  = passport.Address.Id;
         passport.Id         = passport.NewId(unitOfWork);
         unitOfWork.EmployeePassportsRepository.Insert(passport);
         unitOfWork.Save();
         EmployeePassportDTO dto = unitOfWork.EmployeePassportsRepository
                                   .Get(d => d.Id == passport.Id,
                                        includeProperties: "Address,Address.Country,Address.AddressLocality,Address.AddressPlace,Address.AddressRegion,Address.AddressVillage").FirstOrDefault().ToDTO();
         return(CreatedAtRoute("GetEmployeePassport", new { id = dto.Id }, dto));
     }
     catch (NotFoundException nfe)
     {
         return(NotFound());
     }
     catch (ConflictException ce)
     {
         return(Conflict());
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Beispiel #3
0
 public IHttpActionResult DeleteEmployeePassport(int id)
 {
     try
     {
         UnitOfWork       unitOfWork = new UnitOfWork(factory);
         EmployeePassport passport   = unitOfWork.EmployeePassportsRepository
                                       .Get(d => d.EmployeeId == id,
                                            includeProperties: "Address, Address.Country,Address.AddressLocality,Address.AddressPlace,Address.AddressRegion,Address.AddressVillage").FirstOrDefault();
         passport.Deleted = true;
         unitOfWork.EmployeePassportsRepository.Update(passport);
         unitOfWork.Save();
         EmployeePassportDTO dto = passport.ToDTO();
         return(Ok(dto));
     }
     catch (NotFoundException nfe)
     {
         return(NotFound());
     }
     catch (ConflictException ce)
     {
         return(Conflict());
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Beispiel #4
0
 public IHttpActionResult PutEmployeePassport(int id, EmployeePassportDTO employeePassport)
 {
     if (employeePassport == null || !ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     if (id != employeePassport.Id)
     {
         return(BadRequest());
     }
     try
     {
         EmployeePassport passport   = employeePassport.FromDTO();
         UnitOfWork       unitOfWork = new UnitOfWork(factory);
         unitOfWork.EmployeePassportsRepository.Update(passport);
         unitOfWork.Save();
         EmployeePassportDTO dto = unitOfWork.EmployeePassportsRepository
                                   .Get(d => d.Id == id,
                                        includeProperties: "Address,Address.Country,Address.AddressLocality,Address.AddressPlace,Address.AddressRegion,Address.AddressVillage").FirstOrDefault().ToDTO();
         return(Ok(dto));
     }
     catch (NotFoundException nfe)
     {
         return(NotFound());
     }
     catch (ConflictException ce)
     {
         return(Conflict());
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
 public void UpdateUserPassport(EmployeePassportDTO EmployeePassportDTO, string authorEmail)
 {
     throw new NotImplementedException();
 }