private void buttonAdd_Click(object sender, EventArgs e) { if (ValidationService.ValidateHotelName(textBoxHotelName.Text) && ValidationService.ValidateFoundationYear(dateTimePickerFYear.Value)) { var hotel = new Hotel() { HotelName = textBoxHotelName.Text, Adress = textBoxAdress.Text, FoundationYear = dateTimePickerFYear.Value, IsActive = Convert.ToBoolean(comboBoxIsActive.Text), Created = DateTime.Now }; using (var context = ContextResolver.GetContext(connectionString)) { var hotelService = new HotelService(context); hotelService.Add(hotel); } MessageBox.Show("New record has been added"); this.Close(); } else { labelValidationMessage.Visible = true; } }
public ResultViewModels <HotelEditViewModel> AddHotel(HotelEditViewModel HotelEditView) { ResultViewModels <HotelEditViewModel> result = new ResultViewModels <HotelEditViewModel>(); try { var hotelTemp = HotelService.Add(HotelEditView); if (hotelTemp == null) { result.Successed = false; result.Message = "Data is empty"; } else { result.Successed = true; result.Message = "Data added"; result.Data = hotelTemp; } } catch (Exception ex) { result.Successed = false; result.Message = "Something Went Wrong !!"; } return(result); }
public ActionResult Create(hotel hotel) { hs.Add(hotel); hs.Commit(); return(RedirectToAction("Index")); }
public async Task Add_WhenCalled_ShouldAddAHotel() { using (var context = new ApplicationContext(options)) { var hotelService = new HotelService(context, imageServiceMock.Object, thumbnailServiceMock.Object, localizerMock.Object, mapper.Object); var contextLength = context.Hotels.Count(); var hotelName = "New Hotel"; var hotel = await hotelService.Add( new Hotel { Name = hotelName } ); Assert.Equal(contextLength + 1, context.Hotels.Count()); Assert.True(context.Hotels.Contains(hotel)); Assert.Equal(hotelName, context.Hotels.Find(hotel.HotelId).Name); } }
public HotelEditViewModel AddHotel(HotelEditViewModel HotelEditView) { var Hotel = HotelService.Add(HotelEditView); return(Hotel); }