Beispiel #1
0
        private async void button1_Click(object sender, System.EventArgs e)
        {
            try
            {
                if (this.dataGridView1.CurrentRow == null)
                {
                    throw new Exception("Выберите тип груза для редактирования.");
                }

                var name        = this.textBox1.Text;
                var description = this.textBox2.Text;

                var typeOfCargoId  = long.Parse(this.dataGridView1.CurrentRow.Cells[0].Value.ToString());
                var typeOfCargoDto = new TypeOfCargoDto(name, description)
                {
                    TypeOfCargoId = typeOfCargoId
                };

                await this.typeOfCargoManager.UpdateTypeOfCargoAsync(typeOfCargoDto);

                this.FillCargoTable();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, @"Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #2
0
        public async Task DeleteTypeOfCargoAsync(TypeOfCargoDto typeOfCargoDto)
        {
            var typeOfCargo =
                await this.typeOfCargoRepository.Entity.FirstOrDefaultAsync(x => x.TypeOfCargoId == typeOfCargoDto.TypeOfCargoId);

            this.typeOfCargoRepository.Entity.Remove(typeOfCargo ?? throw new ArgumentException("Не найден тип груза для удаления."));
            await this.typeOfCargoRepository.SaveChangesAsync();
        }
Beispiel #3
0
        private void Validate(TypeOfCargoDto courier)
        {
            var validate = DataAnnotationsValidator.Validate(courier);

            if (!validate.Success)
            {
                throw new ArgumentException(validate.ErrorMessage);
            }
        }
Beispiel #4
0
        public async Task AddTypeOfCargoAsync(TypeOfCargoDto typeOfCargoDto)
        {
            var typeOfCargo = SimpleAutoMapperTransformer.Transform <TypeOfCargoDto, TypeOfCargo>(typeOfCargoDto);

            this.Validate(typeOfCargoDto);

            if (await this.typeOfCargoRepository.Entity.AnyAsync(
                    x => x.Name == typeOfCargo.Name && x.Description == typeOfCargo.Description))
            {
                throw new ArgumentException("Такой тип груза уже существует.");
            }

            this.typeOfCargoRepository.Entity.Add(typeOfCargo);
            await this.typeOfCargoRepository.SaveChangesAsync();
        }
Beispiel #5
0
        private async void button3_Click(object sender, EventArgs e)
        {
            try
            {
                var name        = this.textBox1.Text;
                var description = this.textBox2.Text;

                var typeOfCargoDto = new TypeOfCargoDto(name, description);

                await this.typeOfCargoManager.AddTypeOfCargoAsync(typeOfCargoDto);

                this.FillCargoTable();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, @"Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #6
0
 public Task UpdateTypeOfCargoAsync(TypeOfCargoDto typeOfCargoDto)
 {
     this.Validate(typeOfCargoDto);
     this.typeOfCargoRepository.Entity.AddOrUpdate(SimpleAutoMapperTransformer.Transform <TypeOfCargoDto, TypeOfCargo>(typeOfCargoDto));
     return(this.typeOfCargoRepository.SaveChangesAsync());
 }