private async void button2_Click(object sender, EventArgs e) { try { if (this.dataGridView1.CurrentRow == null) { throw new Exception("Выберите транспорт для удаления."); } var number = this.textBox1.Text; var model = this.textBox2.Text; var date = this.dateTimePicker1.Value; var transportId = long.Parse(this.dataGridView1.CurrentRow.Cells[0].Value.ToString()); var transportDto = new TransportDto(number, model, date) { TransportId = transportId }; await this.transporManager.DeleteTransportAsync(transportDto); this.FillTransportTable(); } catch (Exception exception) { MessageBox.Show(exception.Message, @"Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public IActionResult Edit(int id, TransportDto transportDto) { log.Info(nameof(Edit) + ": Post"); if (id != transportDto.Id) { log.Warn(nameof(Edit) + " id is not equal to transportDto.Id"); return(NotFound()); } try { if (ModelState.IsValid) { transportService.Update(transportDto); return(RedirectToAction(nameof(Index))); } return(View(transportDto)); } catch (Exception e) { log.Error(e); return(BadRequest()); } }
public void Update(TransportDto transportDto) { var transport = mapper.Map <TransportDto, Transport>(transportDto); uow.Transports.Update(transport); uow.Save(); }
public async Task DeleteTransportAsync(TransportDto transportDto) { var transport = await this.transportRepository.Entity.FirstOrDefaultAsync(x => x.TransportId == transportDto.TransportId); this.transportRepository.Entity.Remove(transport ?? throw new ArgumentException("Не найден транспорт для удаления.")); await this.transportRepository.SaveChangesAsync(); }
private void Validate(TransportDto transportDto) { var validate = DataAnnotationsValidator.Validate(transportDto); if (!validate.Success) { throw new ArgumentException(validate.ErrorMessage); } }
public async Task <bool> BuyTransportAsync(int userId) { var logger = new Logger(); await logger.WriteLogAsync($"{DateTime.Now} - Transport purchase service triggered"); var transportKey = (userId, BookingType.Transport); var bookingTransportIds = _db.Find(transportKey); var isBuying = true; if (bookingTransportIds != null) { if (bookingTransportIds.Count != 0) { foreach (var id in bookingTransportIds) { var transportServiceUrl = BuyingServiceUrls.TRANSPORT_URL + id; var transportData = new TransportDto() { BookingId = id }; var body = JsonConvert.SerializeObject(transportData); var response = await _client.GetAsync(transportServiceUrl); var responseData = ""; if (response.StatusCode == HttpStatusCode.OK) { responseData = await response.Content.ReadAsStringAsync(); } if (responseData == "true" || responseData == "True") { isBuying = true; _db.Remove(transportKey); } else { isBuying = false; } } } else { isBuying = false; } } else { isBuying = false; } return(isBuying); }
public bool BuyTransport([FromBody] TransportDto dto) { var isBuying = false; var buyingTransportId = dto.Id; if (buyingTransportId != -1) { isBuying = true; } return(isBuying); }
public async Task AddTransportAsync(TransportDto transportDto) { var transport = SimpleAutoMapperTransformer.Transform <TransportDto, Transport>(transportDto); this.Validate(transportDto); if (await this.transportRepository.Entity.AnyAsync( x => x.NumberOfCar == transport.NumberOfCar && x.CarModel == transport.CarModel && x.DateOfRegistration == transport.DateOfRegistration)) { throw new ArgumentException("Такой транспорт уже существует."); } this.transportRepository.Entity.Add(transport); await this.transportRepository.SaveChangesAsync(); }
private async void button3_Click(object sender, EventArgs e) { try { var number = this.textBox1.Text; var model = this.textBox2.Text; var date = this.dateTimePicker1.Value; var transportDto = new TransportDto(number, model, date); await this.transporManager.AddTransportAsync(transportDto); this.FillTransportTable(); } catch (Exception exception) { MessageBox.Show(exception.Message, @"Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public IActionResult Create(TransportDto transportDto) { log.Info(nameof(Create) + ": Post"); if (ModelState.IsValid) { try { transportService.Create(transportDto); return(RedirectToAction(nameof(Index))); } catch (Exception e) { log.Error(e); return(BadRequest()); } } return(View(transportDto)); }
public Task UpdateTransportAsync(TransportDto transportDto) { this.Validate(transportDto); this.transportRepository.Entity.AddOrUpdate(SimpleAutoMapperTransformer.Transform <TransportDto, Transport>(transportDto)); return(this.transportRepository.SaveChangesAsync()); }