public string AddPictureHolidayHome(int Id, string Path) { HolidayHome home = context.HolidayHomes.Find(Id); int count = home.Images.Count(); if (count > 5) { return(""); } try { HolidayHome entity = context.HolidayHomes.Find(Id); Image image = new Image(); string ResortId = entity.Resort.ResortId.ToString(); string text = "\\Resort" + ResortId + "HolidayHome" + entity.HolidayHomeId + "Picturenr" + (count + 1).ToString() + ".jpg"; image.ImagePath = "~\\Images" + text; entity.Images.Add(image); context.SaveChanges(); return(text); } catch { return(""); } }
public void when_calling_BookHolidayHome_with_specified_Id_returns_model() { HolidayHome hhome = new HolidayHome() { HolidayHomeId = 1, Price = 200, numberofGuests = 1, numberofBeds = 1, doubleBed = false, petsAllowed = true, Toilet = true, Kitchen = false, numberofTelevisions = 1, numberofFloors = 1 }; List <DateTime> listDateTime = new List <DateTime>(); listDateTime.Add(new DateTime(2019, 4, 9)); listDateTime.Add(new DateTime(2019, 4, 10)); listDateTime.Add(new DateTime(2019, 4, 11)); listDateTime.Add(new DateTime(2019, 4, 12)); Mock <IHolidaysRepository> mock = new Mock <IHolidaysRepository>(); mock.Setup(r => r.GetHolidayHomeById(It.IsAny <int>())).Returns(hhome); mock.Setup(r => r.GetDaysBookedHolidayHome(It.IsAny <int>())).Returns(listDateTime); ClientController controller = new ClientController(mock.Object); ViewResult result = (ViewResult)(controller.BookHolidayHome(1)); BookViewModel model = (BookViewModel)result.Model; Assert.AreEqual(model.holidayhome, hhome); Assert.AreEqual(model.list.Count, listDateTime.Count); }
public ActionResult ShowDetailsHolidayHome(int Id) { HolidayHome home = repository.GetHolidayHomeById(Id); return(View(home)); }
public ActionResult DeleteHolidayHome(int id, int resortId) { HolidayHome holidayHome = repository.GetHolidayHomeById(id); repository.RemoveHolidayHome(id); return(RedirectToAction("EditResort", "Owner", new { id = resortId })); }
public bool Delete(int id) { this._repository.Delete(id); HolidayHome exist = this._repository.FindById(id); return(exist == null ? true : false); }
public async Task <IActionResult> PutHolidayHome(int id, HolidayHome hHome) { if (id != hHome.Id) { return(BadRequest()); } _context.Entry(hHome).State = EntityState.Modified; await _context.SaveChangesAsync(); return(Ok()); }
public HolidayHome GetHolidayHomeById(int id) { try { HolidayHome holidayHome = context.HolidayHomes.Find(id); return(holidayHome); } catch { return(new HolidayHome()); } }
public async Task <ActionResult <HolidayHome> > PostHolidayHome(HolidayHome hHome) { //Checks if the Home owner doesn't exits if (!await _context.HolidayOwners.AnyAsync(h => h.Id == hHome.HomeOwnerId)) { return(Content("Holiday Home Owner does not exist")); } _context.HolidayHomes.Add(hHome); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetHolidayHome), new { id = hHome.Id }, hHome)); }
public bool AddHolidayHomeToResort(HolidayHome holidayhome, int id) { try { Resort resort = context.Resorts.Find(id); resort.HolidayHomes.Add(holidayhome); context.SaveChanges(); return(true); } catch { return(false); } }
public RespHolidayHome Get(int id) { HolidayHome hh = this._repository.FindById(id); if (hh == null) { return(null); } return(new RespHolidayHome() { Id = hh.Id, Owner = this._repositoryOwner.FindById(hh.OwnerId), Alias = hh.Alias, Langs = this._repositoryLang.Find(hh.Id).ToList <HolidayHomeLang>(), FreeDay = this._repositoryFreeDay.Find(hh.Id).ToList <HolidayHomeFreeDay>() }); }
public ActionResult BookHolidayHome(int Id) { HolidayHome model = repository.GetHolidayHomeById(Id); List <DateTime> list = repository.GetDaysBookedHolidayHome(Id); List <string> liststring = new List <string>(); foreach (var item in list) { liststring.Add(item.ToShortDateString()); } BookViewModel viewmodel = new BookViewModel(); viewmodel.holidayhome = model; viewmodel.list = liststring; return(View(viewmodel)); }
public void when_calling_ShowDetailsHolidayHome_with_id_it_returns_specified_model() { HolidayHome hhome = new HolidayHome() { HolidayHomeId = 1, Price = 200, numberofGuests = 1, numberofBeds = 1, doubleBed = false, petsAllowed = true, Toilet = true, Kitchen = false, numberofTelevisions = 1, numberofFloors = 1 }; Mock <IHolidaysRepository> mock = new Mock <IHolidaysRepository>(); mock.Setup(r => r.GetHolidayHomeById(It.IsAny <int>())).Returns(hhome); HomeController controller = new HomeController(mock.Object); ViewResult result = (ViewResult)(controller.ShowDetailsHolidayHome(1)); Assert.AreEqual(result.Model, hhome); }
public void when_calling_ReserveHolidayHome_with_model_error_returns_BookViewModel() { //CheckBookingModel model = new CheckBookingModel(); //model.Available = true; //model.DaysAvailable = 3; //model.FirstDateAvailable = new DateTime(2019, 4, 13); //model.room = new Room() { Price = 100, numberofGuests = 1, numberofBeds = 1, doubleBed = false, petsAllowed = false, Toilet = true, Kitchen = false, numberofTelevisions = 1 }; //model.holidayHome = new HolidayHome() { HolidayHomeId = 3, Price = 200, numberofGuests = 1, numberofBeds = 1, doubleBed = false, petsAllowed = true, Toilet = true, Kitchen = false, numberofTelevisions = 1, numberofFloors = 1 }; HolidayHome hhome = new HolidayHome() { HolidayHomeId = 3, Price = 200, numberofGuests = 1, numberofBeds = 1, doubleBed = false, petsAllowed = true, Toilet = true, Kitchen = false, numberofTelevisions = 1, numberofFloors = 1 }; List <DateTime> listDateTime = new List <DateTime>(); listDateTime.Add(new DateTime(2019, 4, 9)); listDateTime.Add(new DateTime(2019, 4, 10)); listDateTime.Add(new DateTime(2019, 4, 11)); listDateTime.Add(new DateTime(2019, 4, 12)); ReverveHolidayHomeModel reservemodel = new ReverveHolidayHomeModel(); reservemodel.dateFrom = new DateTime(2019, 4, 6); reservemodel.dateTo = new DateTime(2019, 4, 5); reservemodel.holidayhomeId = 3; Mock <IHolidaysRepository> mock = new Mock <IHolidaysRepository>(); mock.Setup(r => r.GetHolidayHomeById(It.IsAny <int>())).Returns(hhome); mock.Setup(r => r.GetDaysBookedHolidayHome(It.IsAny <int>())).Returns(listDateTime); ClientController controller = new ClientController(mock.Object); ViewResult result = (ViewResult)(controller.ReserveHolidayHome(reservemodel)); Assert.AreEqual("~/Views/Client/BookHolidayHome.cshtml", result.ViewName); BookViewModel bookviewmodel = (BookViewModel)result.Model; Assert.AreEqual(hhome, bookviewmodel.holidayhome); }
public HolidayHome Save(HolidayHome entity) { HolidayHome saved = null; using (TransactionScope scope = new TransactionScope()) { try { this._repository.Insert(entity); scope.Complete(); saved = this._repository.Find(entity); } catch (Exception e) { System.Console.WriteLine(e.Message); } } return(saved); }
public ActionResult ReserveHolidayHome(ReverveHolidayHomeModel model) { if (model.dateTo <= model.dateFrom) { ModelState.AddModelError("dateTo", "Date should be later than above"); } if (model.dateFrom == null) { ModelState.AddModelError("dateFrom", "Pole nie moze być puste"); } if (ModelState.IsValid) { //repository.BookHolidayHome(model.holidayhomeId, model.dateFrom, model.dateTo); CheckBookingModel modelbook = repository.bookholidayhome(model.holidayhomeId, model.dateFrom, model.dateTo); ViewBag.checkbookingmodel = modelbook; return(RedirectToAction("ShowDetailsHolidayHome", "Home", new { Id = model.holidayhomeId })); } else { HolidayHome holidayhome = repository.GetHolidayHomeById(model.holidayhomeId); List <DateTime> list = repository.GetDaysBookedHolidayHome(model.holidayhomeId); List <string> liststring = new List <string>(); foreach (var item in list) { liststring.Add(item.ToShortDateString()); } BookViewModel viewmodel = new BookViewModel(); viewmodel.holidayhome = holidayhome; viewmodel.list = liststring; //return View("~/Views/Client/Book/HolidayHome.cshtml", viewmodel); return(View("~/Views/Client/BookHolidayHome.cshtml", viewmodel)); } }
public HolidayHome Update(int id, HolidayHome entity) { HolidayHome saved = null; if (entity != null) { using (var scope = new TransactionScope()) { try { this._repository.Update(entity); scope.Complete(); saved = this._repository.Find(entity); } catch (Exception e) { System.Console.WriteLine(e.Message); } } } return(saved); }
public List <DateTime> GetDaysBookedHolidayHome(int Id) { List <ReserveObject> list_reserveobjects = new List <ReserveObject>(); List <DateTime> listAll = new List <DateTime>(); List <DateTime> listDaysBooked = new List <DateTime>(); DateTime now = DateTime.Now.Date; DateTime TwoWeeksSooner = now.AddDays(-14); DateTime lastDay = now.AddDays(60); try { HolidayHome home = context.HolidayHomes.Find(Id); list_reserveobjects = home.reserveTimes.Where(r => r.bookingFrom >= TwoWeeksSooner && r.bookingToo <= lastDay).ToList(); //list_reserveobjects =home.reserveTimes.Where(r => r.bookingFrom >= now && r.bookingFrom <= lastDay).ToList(); for (int i = 0; i < 60; i++) { listAll.Add(now.AddDays(i)); } for (int i = 0; i < 60; i++) { foreach (var item in list_reserveobjects) { if (item.bookingFrom.Date == listAll[i].Date || listAll[i] >= item.bookingFrom && listAll[i].Date < item.bookingToo.Date) { listDaysBooked.Add(listAll[i]); } } } } catch { return(listDaysBooked); } return(listDaysBooked); }
public bool RemoveHolidayHome(int id) { try { HolidayHome holidayHome = context.HolidayHomes.Find(id); if (holidayHome.Images.Count > 0) { List <Image> images = holidayHome.Images.ToList(); foreach (var item in images) { holidayHome.Images.Remove(item); } context.SaveChanges(); } context.HolidayHomes.Remove(holidayHome); context.SaveChanges(); return(true); } catch { return(false); } }
public CheckBookingModel() { holidayHome = new HolidayHome(); room = new Room(); }
public ActionResult AddHolidayHome(HolidayHome holidayhome, string name, int id) { repository.AddHolidayHomeToResort(holidayhome, id); return(RedirectToAction("EditResort", new { id = id })); }