public ActionResult OrderTour(int id, int?realNumberOfPeople) { var tour = _customerService.GetTourById(id); var tourViewModel = MappingViewModel.MapTourViewModel(tour); var userId = User.Identity.GetUserId(); var customer = _customerService.GetCustomerByIdentityUserId(userId); if (Request.HttpMethod == "POST") { if (realNumberOfPeople == null) { ModelState.AddModelError("realNumberOfPeople", "Please enter valid number of people"); } else if (realNumberOfPeople > tourViewModel.MaxNumberOfPeople) { ModelState.AddModelError("realNumberOfPeople", "Please enter valid number of people"); } if (ModelState.IsValid) { var tourDto = MappingViewModel.MapTourDTO(tourViewModel); int cost = Discount.DiscountPrice(tourViewModel.Price, customer.Discount); _customerService.BuyTour(tourDto, userId, realNumberOfPeople.Value, cost); SLogger.InfoToFile($"Customer {customer.Id} order tour {tourViewModel.Id} by price {cost}"); var messageInfo = new MessageViewModel() { Status = "success", Info = "Tour ordered" }; return(RedirectToAction("Index", messageInfo)); } else { ViewBag.PriceForCustomer = Discount.DiscountPrice(tourViewModel.Price, customer.Discount); return(View(tourViewModel)); } } else { ViewBag.PriceForCustomer = Discount.DiscountPrice(tourViewModel.Price, customer.Discount); return(View(tourViewModel)); } }
public ActionResult UpdateTour(int id, string startOfTour, string endOfTour, int?typeOfTourId, int?typeOfHotelsId, int?maxNumberOfPeople, int?price, int?cityId, string isHot, int?numberOfOrders) { if (Request.HttpMethod == "POST") { var tour = MappingViewModel.MapTourViewModel(_managerService.GetTourById(id)); DateTime startOfTourDate = DateTime.MinValue; DateTime endOfTourDate = DateTime.MinValue; bool update = false; if (!string.IsNullOrEmpty(startOfTour) || !string.IsNullOrEmpty(endOfTour)) { startOfTourDate = Convert.ToDateTime(startOfTour); endOfTourDate = Convert.ToDateTime(endOfTour); if (startOfTourDate > endOfTourDate) { ModelState.AddModelError("date", "Enter valid dates"); } else { tour.StartOfTour = startOfTourDate; tour.StartOfTour = endOfTourDate; update = true; } } if (ModelState.IsValid) { if (typeOfTourId != null) { tour.TypeOfTourId = typeOfTourId.Value; update = true; } if (typeOfHotelsId != null) { tour.TypeOfHotelId = typeOfHotelsId.Value; update = true; } if (maxNumberOfPeople != null) { tour.MaxNumberOfPeople = maxNumberOfPeople.Value; update = true; } if (price != null) { tour.Price = price.Value; update = true; } if (cityId != null) { tour.CityId = cityId.Value; update = true; } if (numberOfOrders != null) { tour.NumberOfOrders = numberOfOrders.Value; update = true; } bool isHotType = Convert.ToBoolean(isHot); if (!((tour.IsHot && isHotType) || (!tour.IsHot && !isHotType))) { tour.IsHot = Convert.ToBoolean(isHot); update = true; } if (update) { var updateTour = MappingViewModel.MapTourDTO(tour); _managerService.UpdateTour(updateTour); SLogger.InfoToFile($"Manager updated tour id: {updateTour.Id}"); var messageInfo = new MessageViewModel() { Status = "success", Info = "Tour updated" }; return(RedirectToAction("Index", messageInfo)); } else { ViewBag.ListOption = _managerService.GetListOption(); ModelState.AddModelError("Update", "Tour not updated"); return(View(tour)); } } else { ViewBag.ListOption = _managerService.GetListOption(); return(View(tour)); } } else { ViewBag.ListOption = _managerService.GetListOption(); var tour = MappingViewModel.MapTourViewModel(_managerService.GetTourById(id)); if (tour == null) { return(HttpNotFound()); } if (tour.NumberOfOrders <= 0) { return(HttpNotFound()); } return(View(tour)); } }
public ActionResult CreateNewTour(string startOfTour, string endOfTour, int?typeOfTourId, int?typeOfHotelsId, int?maxNumberOfPeople, int?price, int?cityId, int?numberOfOrders, HttpPostedFileBase upload) { if (Request.HttpMethod == "POST") { DateTime startOfTourDate = DateTime.MinValue; DateTime endOfTourDate = DateTime.MinValue; if (string.IsNullOrEmpty(startOfTour) || string.IsNullOrEmpty(endOfTour)) { ModelState.AddModelError("date", "Enter valid dates"); } else { startOfTourDate = Convert.ToDateTime(startOfTour); endOfTourDate = Convert.ToDateTime(endOfTour); if (startOfTourDate > endOfTourDate) { ModelState.AddModelError("date", "Enter valid dates"); } } if (upload == null) { ModelState.AddModelError("upload", "Please enter image"); } if (typeOfTourId == null) { ModelState.AddModelError("typeOfTourId", "Please enter type of tour"); } if (typeOfHotelsId == null) { ModelState.AddModelError("typeOfHotelsId", "Please enter type of hotel"); } if (maxNumberOfPeople == null) { ModelState.AddModelError("maxNumberOfPeople", "Please enter max number of people"); } if (price == null) { ModelState.AddModelError("price", "Please enter price"); } if (cityId == null) { ModelState.AddModelError("cityId", "Please enter a city"); } if (numberOfOrders == null) { ModelState.AddModelError("typeOfTourId", "Please enter number of orders"); } if (ModelState.IsValid) { var newTour = new TourViewModel() { StartOfTour = startOfTourDate, EndOfTour = endOfTourDate, TypeOfHotelId = typeOfHotelsId.Value, TypeOfTourId = typeOfTourId.Value, MaxNumberOfPeople = maxNumberOfPeople.Value, IsDelete = false, NumberOfOrders = numberOfOrders.Value, Price = price.Value, CityId = cityId.Value, IsHot = false, ImagePath = Path.GetFileName(upload.FileName) }; upload.SaveAs(Server.MapPath("~/Content/Image/" + newTour.ImagePath)); var newTourDTO = MappingViewModel.MapTourDTO(newTour); _adminService.CreateTour(newTourDTO); SLogger.InfoToFile($"Admin create a new tour"); var messageInfo = new MessageViewModel() { Status = "success", Info = "Tour created" }; return(RedirectToAction("Index", messageInfo)); } else { var listOption = _adminService.GetListOption(); return(View(listOption)); } } else { var listOption = _adminService.GetListOption(); return(View(listOption)); } }