public ActionResult Contact(string message) { if (string.IsNullOrEmpty(message) || message.Length < 20) { ModelState.AddModelError("message", "Too short feedback"); } if (ModelState.IsValid) { var userId = User.Identity.GetUserId(); var customer = _customerService.GetCustomerByIdentityUserId(userId); var cistomerViewModel = MappingViewModel.MapCustomerViewModel(customer); var feedback = new FeedbackViewModel() { Customer = cistomerViewModel, CustomerId = cistomerViewModel.Id, IsRead = false, Message = message, Date = DateTime.Now }; var feedbackDto = MappingViewModel.MapFeedbackDTO(feedback); _customerService.SendFeedback(feedbackDto); SLogger.InfoToFile($"Customer {customer.Id} sent feedback"); var messageInfo = new MessageViewModel() { Status = "success", Info = "Your feedback has been sent" }; return(RedirectToAction("Index", "Customer", messageInfo)); } return(View()); }
public ActionResult UpdateStatus(List <int?> typeOfStatusId) { var registeredTours = _managerService.GetRegisteredTours(); var registeredToursViewModel = MappingViewModel.MapTourCustomerListViewModel(registeredTours); if (Request.HttpMethod == "POST") { if (typeOfStatusId != null) { for (int i = 0; i < typeOfStatusId.Count; i++) { if (typeOfStatusId[i] != null) { registeredToursViewModel[i].TypeOfStatusId = typeOfStatusId[i].Value; var updateTour = MappingViewModel.MapTourCustomerDTO(registeredToursViewModel[i]); _managerService.UpdateTourCustomer(updateTour); SLogger.InfoToFile($"Manager update status tour id: {updateTour.Id}"); } } } return(RedirectToAction("Index", "Home")); } else { ViewBag.ListOption = _managerService.GetListOption(); return(View(registeredToursViewModel)); } }
public ActionResult BlockUnlockManager(int?id) { var managers = _adminService.GetAllManagers(); var managersViewModel = MappingViewModel.MapManagerListViewModel(managers); if (id != null) { var manager = _adminService.GetManagerById(id.Value); if (manager == null) { return(HttpNotFound()); } if (manager.IsBlock) { _adminService.UnlockManager(id.Value); SLogger.InfoToFile($"Admin unlock manager id: {id.Value}"); } else { _adminService.BlockManager(id.Value); SLogger.InfoToFile($"Admin block manager id: {id.Value}"); } return(RedirectToAction("Index", "Home")); } else { return(View(managersViewModel)); } }
public ActionResult DeleteTour(int id) { if (Request.HttpMethod == "POST") { _adminService.DeleteTour(id); SLogger.InfoToFile($"Admin delete tour id: {id}"); var messageInfo = new MessageViewModel() { Status = "success", Info = "Tour deleted" }; return(RedirectToAction("Index", messageInfo)); } else { var tour = MappingViewModel.MapTourViewModel(_adminService.GetTourById(id)); if (tour == null) { return(HttpNotFound()); } if (tour.NumberOfOrders <= 0) { return(HttpNotFound()); } return(View(tour)); } }
public ActionResult TourCancellation(int?id) { var userId = User.Identity.GetUserId(); var customer = _customerService.GetCustomerByIdentityUserId(userId); var tours = _customerService.GetTourCustomerByCustomerId(userId); var toursViewModel = MappingViewModel.MapTourCustomerListViewModel(tours); var tourCustomerViewModel = toursViewModel.Find(t => t.Id == id.Value); var tourCustomer = MappingViewModel.MapTourCustomerDTO(tourCustomerViewModel); _customerService.CancelTour(tourCustomer); SLogger.InfoToFile($"Customer {customer.Id} сanceled the tour {tourCustomer.Id}"); var messageInfo = new MessageViewModel() { Status = "success", Info = "Tour canceled -5 percent of the discount" }; return(RedirectToAction("Index", messageInfo)); }
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 ChangeInformation(string name, string surname) { var userId = User.Identity.GetUserId(); var customer = _customerService.GetCustomerByIdentityUserId(userId); var cistomerViewModel = MappingViewModel.MapCustomerViewModel(customer); if (Request.HttpMethod == "POST") { if (name.Length <= 3) { ModelState.AddModelError("name", "Please enter valid name"); } if (surname.Length <= 3) { ModelState.AddModelError("surname", "Please enter valid surname"); } if (ModelState.IsValid) { customer.Name = name; customer.Surname = surname; _customerService.ChangePersonalInformation(customer); SLogger.InfoToFile($"Customer {customer.Id} changed name to {name} {surname}"); var messageInfo = new MessageViewModel() { Status = "success", Info = "Changed information" }; return(RedirectToAction("Index", messageInfo)); } else { return(View(cistomerViewModel)); } } else { return(View(cistomerViewModel)); } }
public ActionResult ChangeDiscount(int id, int?maxDiscount, int?stepDiscount) { var customer = _managerService.GetCustomerById(id); var customerViewModel = MappingViewModel.MapCustomerViewModel(customer); if (Request.HttpMethod == "POST") { if (maxDiscount == null) { ModelState.AddModelError("maxDiscount", "Please enter max discount"); } if (stepDiscount == null) { ModelState.AddModelError("stepDiscount", "Please enter step discount"); } if (ModelState.IsValid) { customer.StepDiscount = stepDiscount.Value; customer.MaxDiscount = maxDiscount.Value; _managerService.ChangeDiscountCustomer(customer); SLogger.InfoToFile($"Manager change discount customer id: {customer.Id}"); var messageInfo = new MessageViewModel() { Status = "success", Info = $"Changed discount for {customer.Name}" }; return(RedirectToAction("Index", messageInfo)); } else { return(View(customerViewModel)); } } else { return(View(customerViewModel)); } }
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)); } }