Exemplo n.º 1
0
        public async Task CreateOrUpdateManufacturer(ManufacturerCreateOrUpdateInput input)
        {
            await CheckValidation(input);

            if (input.Id.HasValue)
            {
                await UpdateManufacturerAsync(input);
            }
            else
            {
                await CreateManufacturerAsync(input);
            }
        }
Exemplo n.º 2
0
        private async Task CheckValidation(ManufacturerCreateOrUpdateInput input)
        {
            var existingObj = (await _manufacturerRepository.GetAll().AsNoTracking()
                               .FirstOrDefaultAsync(l => l.Code == input.Code));

            if (existingObj != null && existingObj.Id != input.Id)
            {
                throw new UserFriendlyException(L("ThisCodeAlreadyExists"));
            }

            existingObj = (await _manufacturerRepository.GetAll().AsNoTracking()
                           .FirstOrDefaultAsync(l => l.Name == input.Name));
            if (existingObj != null && existingObj.Id != input.Id)
            {
                throw new UserFriendlyException(L("ThisNameAlreadyExists"));
            }
        }
Exemplo n.º 3
0
        public async Task <ManufacturerCreateOrUpdateInput> GetManufacturerForEdit(NullableIdDto <int> input)
        {
            //Getting all available roles
            var output = new ManufacturerCreateOrUpdateInput();

            if (input.Id.HasValue)
            {
                //Editing an existing user
                var manufacturer = await _manufacturerRepository.GetAsync(input.Id.Value);

                if (manufacturer != null)
                {
                    ObjectMapper.Map <Manufacturer, ManufacturerCreateOrUpdateInput>(manufacturer, output);
                }
            }

            return(output);
        }
Exemplo n.º 4
0
 private async Task UpdateManufacturerAsync(ManufacturerCreateOrUpdateInput input)
 {
     var manufacturer = ObjectMapper.Map <Manufacturer>(input);
     await _manufacturerRepository.UpdateAsync(manufacturer);
 }