public ActionResult Book(BookingViewModel booking) { try { var bookingTableDto = new BookingTableDTO { Carriage_Id = booking.Carriage_Id, NAME = booking.NAME, EMAIL = booking.EMAIL, Description = booking.Description, Seat_Num = booking.Seat_Num }; carriageService.BookPlace(bookingTableDto); return(Content("<h2>Ваш заказ успешно оформлен</h2> <a href='/'> На главную </a>")); } catch (ValidationException ex) { ModelState.AddModelError(ex.Property, ex.Message); } return(View(booking)); }
public void BookPlace(BookingTableDTO bookt) { CarriageDetail carriage = Database.CarriageDetails.Get(bookt.Carriage_Id); // валидация if (carriage == null) { throw new ValidationException("Вагон не найден", ""); } BookingTable bt = new BookingTable { CarriageDetail = carriage, Carriage_Id = bookt.Carriage_Id, Date = DateTime.Now, NAME = bookt.NAME, EMAIL = bookt.EMAIL, Description = bookt.Description, Seat_Num = bookt.Seat_Num }; Database.BookingTables.Create(bt); Database.Save(); /* * try * { * MailMessage mailMessage = new MailMessage(); * mailMessage.To.Add(bookt.EMAIL); * mailMessage.From = new MailAddress("*****@*****.**"); * mailMessage.Subject = "Place booked"; * mailMessage.Body = "Hello. You have booked a ticket via NovaZaliznitsya service. Your place "+ bookt.Seat_Num; * SmtpClient smtpClient = new SmtpClient("smtp.isp.com"); * smtpClient.Send(mailMessage); * } * catch (Exception ex) * { * Response.Write("Could not send the e-mail - error: " + ex.Message); * }*/ }