public Task <DataResult <DTOManufacturer> > EditManufacturerAsync(DTOManufacturer manufacturerDTO)
        {
            return(Task.Run(() => {
                var manufacturerRepository = _unitOfWork.GetRepository <Manufacturer>();

                var manufacturerEntity = _mapper.Map <Manufacturer>(manufacturerDTO);
                var updatedManufacturerDTO = new DTOManufacturer();
                if ((manufacturerRepository.ExistByCondition(x => (x.Name == manufacturerEntity.Name && x.Id == manufacturerEntity.Id))) || (!manufacturerRepository.ExistByCondition(x => x.Name == manufacturerEntity.Name)))
                {
                    var updatedManufacturerEntity = manufacturerRepository.Update(manufacturerEntity);
                    _unitOfWork.SaveChanges();

                    updatedManufacturerDTO = _mapper.Map <DTOManufacturer>(updatedManufacturerEntity);

                    return new DataResult <DTOManufacturer> {
                        Errors = new List <ErrorDescriber>(), Target = updatedManufacturerDTO
                    };
                }
                else
                {
                    return new DataResult <DTOManufacturer> {
                        Errors = new List <ErrorDescriber> {
                            new ErrorDescriber("Existed Manufacture Name")
                        }, Target = updatedManufacturerDTO
                    };
                }
            }));
        }
        public Task <DataResult <DTOManufacturer> > GetManufacturerByIdAsync(int id)
        {
            return(Task.Run(() => {
                var manufacturerDTO = new DTOManufacturer();
                var manufacturerRepository = _unitOfWork.GetRepository <Manufacturer>();
                var manufacturer = manufacturerRepository.GetById(id);
                if (manufacturer != null)
                {
                    manufacturerDTO = _mapper.Map <DTOManufacturer>(manufacturer);
                }

                return new DataResult <DTOManufacturer> {
                    Errors = new List <ErrorDescriber>(), Target = manufacturerDTO
                };
            }));
        }
        public Task <DataResult <DTOManufacturer> > CreateManufacturerAsync(DTOManufacturer manufacturerDTO)
        {
            return(Task.Run(() => {
                var createdManufacturerDTO = new DTOManufacturer();

                var manufacturerRepository = _unitOfWork.GetRepository <Manufacturer>();
                var manufacturerEntity = _mapper.Map <Manufacturer>(manufacturerDTO);

                var createdManufacturerEntity = manufacturerRepository.Insert(manufacturerEntity);
                _unitOfWork.SaveChanges();

                createdManufacturerDTO = _mapper.Map <DTOManufacturer>(createdManufacturerEntity);

                return new DataResult <DTOManufacturer> {
                    Errors = new List <ErrorDescriber>(), Target = createdManufacturerDTO
                };
            }));
        }
 public async Task <IHttpActionResult> Put([FromBody] DTOManufacturer manufacturerDTO)
 {
     return(await ExecuteServiceReturnDefaultResult(() => _serviceBuilder.Parameter.ManufacturerService.EditManufacturerAsync(manufacturerDTO), false));
 }