Ejemplo n.º 1
0
        public Task <DataResult <DTOService> > EditServiceAsync(DTOService serviceDTO)
        {
            return(Task.Run(() => {
                var serviceRepository = _unitOfWork.GetRepository <Service>();
                var updatedServiceDTO = new DTOService();

                var serviceEntity = _mapper.Map <Service>(serviceDTO);
                if ((serviceRepository.ExistByCondition(x => (x.Name == serviceEntity.Name && x.Id == serviceEntity.Id))) || (!serviceRepository.ExistByCondition(x => x.Name == serviceEntity.Name)))
                {
                    var updatedServiceEntity = serviceRepository.Update(serviceEntity);
                    _unitOfWork.SaveChanges();

                    updatedServiceDTO = _mapper.Map <DTOService>(updatedServiceEntity);

                    return new DataResult <DTOService> {
                        Errors = new List <ErrorDescriber>(), Target = updatedServiceDTO
                    };
                }
                else
                {
                    return new DataResult <DTOService> {
                        Errors = new List <ErrorDescriber> {
                            new ErrorDescriber("Existed Employee Name")
                        }, Target = updatedServiceDTO
                    };
                }
            }));
        }
Ejemplo n.º 2
0
 private static void CreateNewRelocationPlaces(Candidate destination, CandidateDTO source, IRepository <City> locationRepo)
 {
     source.RelocationPlaces.Where(x => x.IsNew()).ToList().ForEach(newRelocationPlace =>
     {
         var toDomain = DTOService.ToEntity <RelocationPlaceDTO, RelocationPlace>(newRelocationPlace);
         destination.RelocationPlaces.Add(toDomain);
     });
 }
Ejemplo n.º 3
0
 public virtual IHttpActionResult Add([FromBody] ViewModel entity)
 {
     if (ModelState.IsValid)
     {
         var newEntity = DTOService.ToEntity <ViewModel, DomainEntity>(entity);
         _currentRepo.Add(newEntity);
         return(Json(DTOService.ToDTO <DomainEntity, ViewModel>(_currentRepo.GetAll().Last())));
     }
     return(BadRequest());
 }
Ejemplo n.º 4
0
        public virtual IHttpActionResult Get(int id)
        {
            var foundedEntity = _currentRepo.Get(id);

            if (foundedEntity != null)
            {
                var foundedEntityDto = DTOService.ToDTO <DomainEntity, ViewModel>(foundedEntity);
                return(Json(foundedEntityDto, SERIALIZER_SETTINGS));
            }
            return(NotFound());
        }
Ejemplo n.º 5
0
 public virtual IHttpActionResult Put(int id, [FromBody] ViewModel changedEntity)
 {
     if (ModelState.IsValid)
     {
         if (changedEntity != null)
         {
             var changedDomainEntity = DTOService.ToEntity <ViewModel, DomainEntity>(changedEntity);
             _currentRepo.Update(changedDomainEntity);
             return(Json(DTOService.ToDTO <DomainEntity, ViewModel>(_currentRepo.Get(changedDomainEntity.Id)), SERIALIZER_SETTINGS));
         }
         return(NotFound());
     }
     return(BadRequest());
 }
Ejemplo n.º 6
0
        public Task <DataResult <DTOService> > CreateServiceAsync(DTOService serviceDTO)
        {
            return(Task.Run(() => {
                var createdServiceDTO = new DTOService();
                var serviceEntity = _mapper.Map <Service>(serviceDTO);
                if (!_serviceRepository.ExistByCondition(x => x.Name == serviceEntity.Name))
                {
                    var createdServiceEntity = _serviceRepository.Insert(serviceEntity);
                    _unitOfWork.SaveChanges();

                    createdServiceDTO = _mapper.Map <DTOService>(createdServiceEntity);
                }

                return new DataResult <DTOService> {
                    Errors = new List <ErrorDescriber>(), Target = createdServiceDTO
                };
            }));
        }
Ejemplo n.º 7
0
        public Task <DataResult <DTOService> > GetServiceByIdAsync(string id)
        {
            return(Task.Run(() => {
                var serviceDTO = new DTOService();

                var service = _serviceRepository.GetById(id);
                if (service != null)
                {
                    serviceDTO = _mapper.Map <DTOService>(service);
                }
                else
                {
                    var identityNumber = _serviceRepository.Identity(x => x.GenerateId) != null ? _serviceRepository.Identity(x => x.GenerateId).GenerateId : 0;
                    serviceDTO.Id = IdentityGenerate.Create(identityNumber, new string[] { "", EntityPrefix.Service.ToDefaultValue() }, NumberUnitType.Small);
                }

                return new DataResult <DTOService> {
                    Errors = new List <ErrorDescriber>(), Target = serviceDTO
                };
            }));
        }
Ejemplo n.º 8
0
        public virtual IHttpActionResult All(int?pageNumber = 1)
        {
            var entitiesQuery = _currentRepo.GetAll().OrderBy(x => x.Id);

            if (pageNumber.HasValue)
            {
                var totalCount = _currentRepo.GetAll().Count();
                var totalPages = Math.Ceiling((double)totalCount / ENTITIES_PER_PAGE);

                var entities = entitiesQuery
                               .Skip((pageNumber.Value - 1) * ENTITIES_PER_PAGE)
                               .Take(ENTITIES_PER_PAGE)
                               .ToList()
                               .Select(x => DTOService.ToDTO <DomainEntity, ViewModel>(x));
                return(Json(new
                {
                    totalCount = totalCount,
                    totalPages = totalPages,
                    queryResult = entities
                }, SERIALIZER_SETTINGS));
            }
            return(Json(entitiesQuery, SERIALIZER_SETTINGS));
        }
Ejemplo n.º 9
0
        public void CanReadDTO <TDTO>() where TDTO : CoreDTO
        {
            var userServiceMock = new Mock <IUserInfoService>();

            userServiceMock.Setup(meth => meth.GetCurrentUserInfo()).Returns(_userInfo);

            var contextOption = new DbContextOptionsBuilder <CoreDbContext>().UseNpgsql(_connection).Options;

            var saveRepo = new SafeDTORepository <TDTO>(new CoreDbContext(contextOption),
                                                        new SqlRepositoryHelper(new PostgresQueryConditionsBuilder()));

            var service = new DTOService <TDTO>(saveRepo);

            try
            {
                var _ = service.GetDTO().FirstOrDefault();
            }
            catch (Exception)
            {
                Assert.False(true);
            }

            Assert.True(true);
        }
Ejemplo n.º 10
0
 public async Task <IHttpActionResult> Put([FromBody] DTOService serviceDTO)
 {
     return(await ExecuteServiceReturnDefaultResult(() => _serviceBuilder.Parameter.PublicService.EditServiceAsync(serviceDTO), false));
 }