Beispiel #1
0
        public Task <DataResult <DTOCustomerType> > EditCustomerTypeAsync(DTOCustomerType customerTypeDTO)
        {
            return(Task.Run(() =>
            {
                var customerTypeEntity = _mapper.Map <CustomerType>(customerTypeDTO);
                var updatedCustomerTypeDTO = new DTOCustomerType();

                if ((customerTypeRepository.ExistByCondition(x => (x.Name == customerTypeEntity.Name && x.Id == customerTypeEntity.Id))) || (!customerTypeRepository.ExistByCondition(x => x.Name == customerTypeEntity.Name)))
                {
                    var updatedCustomerTypeEntity = customerTypeRepository.Update(customerTypeEntity);
                    _unitOfWork.SaveChanges();

                    updatedCustomerTypeDTO = _mapper.Map <DTOCustomerType>(updatedCustomerTypeEntity);

                    return new DataResult <DTOCustomerType> {
                        Errors = new List <ErrorDescriber>(), Target = updatedCustomerTypeDTO
                    };
                }
                else
                {
                    return new DataResult <DTOCustomerType> {
                        Errors = new List <ErrorDescriber> {
                            new ErrorDescriber("Existed Customer Type Name")
                        }, Target = updatedCustomerTypeDTO
                    };
                }
            }));
        }
Beispiel #2
0
        public Task <DataResult <DTOCustomerType> > GetByIdAsync(int id)
        {
            return(Task.Run(() =>
            {
                var customerTypeDTO = new DTOCustomerType();
                var customerType = customerTypeRepository.GetById(id);

                if (customerType != null)
                {
                    customerTypeDTO = _mapper.Map <DTOCustomerType>(customerType);
                }

                return new DataResult <DTOCustomerType> {
                    Errors = new List <ErrorDescriber>(), Target = customerTypeDTO
                };
            }));
        }
Beispiel #3
0
        public Task <DataResult <DTOCustomerType> > CreateCustomerTypeAsync(DTOCustomerType customerTypeDTO)
        {
            return(Task.Run(() =>
            {
                var createdCustomerTypeDTO = new DTOCustomerType();
                var customerEntity = _mapper.Map <CustomerType>(customerTypeDTO);

                if (!customerTypeRepository.ExistByCondition(x => x.Name == customerEntity.Name))
                {
                    var createdCustomerTypeEntity = customerTypeRepository.Insert(customerEntity);
                    _unitOfWork.SaveChanges();

                    createdCustomerTypeDTO = _mapper.Map <DTOCustomerType>(createdCustomerTypeEntity);
                }

                return new DataResult <DTOCustomerType> {
                    Errors = new List <ErrorDescriber>(), Target = createdCustomerTypeDTO
                };
            }));
        }
 public async Task <IHttpActionResult> Put([FromBody] DTOCustomerType customerTypeDTO)
 {
     return(await ExecuteServiceReturnDefaultResult(() => _serviceBuilder.Parameter.CustomerTypeService.EditCustomerTypeAsync(customerTypeDTO), false));
 }