public ActionResult Rate(int id) { var pub = PubDAO.Search(id); var rating = RatingDAO.SearchByPersonAndPubId(UserSession.ReturnPersonId(null), pub.Id); if (rating == null) { rating = new Rating { PersonId = UserSession.ReturnPersonId(null), PubId = pub.Id }; if (RatingDAO.Insert(rating) != null) { pub.Rating = pub.Rating + 1; PubDAO.Update(pub); } } else { if (RatingDAO.Delete(rating) == true) { pub.Rating = pub.Rating - 1; PubDAO.Update(pub); } } return RedirectToAction("Pub", new { id }); }
public ActionResult Update(Pub pubUpdate) { var pub = PubDAO.Search(UserSession.ReturnPubId(null)); pubUpdate.Rating = pub.Rating; pubUpdate.RegistrationDate = pub.RegistrationDate; pubUpdate.UserType = pub.UserType; pubUpdate.State = pub.State; pubUpdate.PhotoUrl = pub.PhotoUrl; pubUpdate.Login = pub.Login; pubUpdate.Id = pub.Id; if (pubUpdate.Password == null) { pubUpdate.Password = pub.Password; } Tuple <double, double> tuple = GoogleGeoLocation.GetCoordinates(pubUpdate.Address, pubUpdate.State); pubUpdate.Lat = tuple.Item1; pubUpdate.Lng = tuple.Item2; if (PubDAO.Update(pubUpdate) == true) { return(RedirectToAction("Dashboard")); } else { ViewBags(); ModelState.AddModelError("", "Error - Check information and try again"); return(View("Account", pub)); } }
public ActionResult Update(Pub pubUpdate) { var returnedPub = PubDAO.Search(UserSession.ReturnPubId(null)); if (returnedPub == null) { return(RedirectToAction("Logout", "User")); } // Set the remaining properties of the model returnedPub.Name = pubUpdate.Name ?? returnedPub.Name; returnedPub.FoundationDate = pubUpdate.FoundationDate == null ? returnedPub.FoundationDate : pubUpdate.FoundationDate; returnedPub.Address = pubUpdate.Address ?? returnedPub.Address; returnedPub.City = pubUpdate.City ?? returnedPub.City; returnedPub.State = pubUpdate.State ?? returnedPub.State; // Get the coordinates of the bar location that the user has given Tuple <double, double> tuple = GoogleGeoLocation.GetCoordinates(returnedPub.Address, returnedPub.City, returnedPub.State); returnedPub.Lat = tuple.Item1; returnedPub.Lng = tuple.Item2; if (PubDAO.Update(returnedPub) != true) { ModelState.AddModelError("", "Error - Check information and try again"); return(View("Account")); } return(RedirectToAction("Account")); }
public ActionResult Account() { var returnedPub = PubDAO.Search(UserSession.ReturnPubId(null)); ViewBags(); return(View(returnedPub)); }
public ActionResult Product() { var pubSession = PubDAO.Search(UserSession.ReturnPubId(null)); if (pubSession == null) { return(RedirectToAction("Logout", "User")); } ViewBags(pubSession); ViewBag.ProductList = ProductDAO.ReturnList(pubSession.Id); ViewBag.Categories = new MultiSelectList(CategoryDAO.ReturnList(), "Id", "Name"); try { var product = (Product)System.Web.HttpContext.Current.Session["product"]; if (product != null) { ViewBag.Alter = "Yes"; return(View(product)); } } catch (Exception ex) { ModelState.AddModelError("", $"Error - {ex.Message}"); } ViewBag.Alter = "No"; return(View()); }
public void ViewBags() { var pub = PubDAO.Search(UserSession.ReturnPubId(null)); var pubsList = PubDAO.ReturnList().Select(x => new { x.Id, x.Name, x.Rating, x.Lat, x.Lng, x.Address, x.FoundationDate }).ToList(); ViewBag.PubsList = JsonConvert.SerializeObject(pubsList); ViewBag.Name = pub.Name; ViewBag.Profile = pub.PhotoBase64(); }
public ActionResult Login(string EmailLogin, string PasswordLogin) { var pub = PubDAO.Search(EmailLogin, PasswordLogin); if (pub != null) { UserSession.ReturnPubId(pub.Id); return(RedirectToAction("Dashboard", "Pub")); } return(View("Login")); }
public IHttpActionResult GetPubById(int pubId) { Pub pub = PubDAO.Search(pubId); if (pub == null) { return(NotFound()); } return(Ok(pub)); }
public ActionResult Dashboard() { var pubSession = PubDAO.Search(UserSession.ReturnPubId(null)); if (pubSession == null) { RedirectToAction("Login", "User"); } return(View(pubSession)); }
public ActionResult Account() { var returnedPub = PubDAO.Search(UserSession.ReturnPubId(null)); if (returnedPub == null) { return(RedirectToAction("Logout", "User")); } ViewBags(returnedPub); return(View(returnedPub)); }
public ActionResult Dashboard() { var pubSession = PubDAO.Search(UserSession.ReturnPubId(null)); if (pubSession == null) { return(RedirectToAction("Logout", "User")); } ViewBags(pubSession); return(View(pubSession)); }
public ActionResult Delete(string Password) { var pub = PubDAO.Search(UserSession.ReturnPubId(null)); if (Password == pub.Password) { PubDAO.Delete(pub); UserSession.ClearPubSession(); return(RedirectToAction("Login")); } else { ViewBags(); ModelState.AddModelError("", "Error - Password does not match"); return(View("Account", pub)); } }
public ActionResult Login(User user) { var pub = PubDAO.Search(user.Email, user.Password); var person = PersonDAO.Search(user.Email, user.Password); if (pub != null) { UserSession.ReturnPubId(pub.Id); return(RedirectToAction("Dashboard", "Pub")); } else if (person != null) { UserSession.ReturnPubId(person.Id); return(RedirectToAction("Dashboard", "Person")); } return(View("Login", user)); }
public ActionResult UpdateImg(HttpPostedFileBase upImage) { var pub = PubDAO.Search(UserSession.ReturnPubId(null)); if (upImage != null) { pub.PhotoUrl = ImageHandler.HttpPostedFileBaseToByteArray(upImage); pub.PhotoType = upImage.ContentType; PubDAO.Update(pub); return(RedirectToAction("Account", "Pub")); } else { ViewBags(); ModelState.AddModelError("", "Error - Image dont work"); return(View("Account", pub)); } }
public ActionResult Register(Product product, HttpPostedFileBase upImage, int?Categories) { var pub = PubDAO.Search(UserSession.ReturnPubId(null)); product.PubId = pub.Id; ViewBag.Categories = new SelectList(CategoryDAO.ReturnList(), "Id", "Name"); product.Category = CategoryDAO.Search(Categories); if (ModelState.IsValid != true) { return(RedirectToAction("Product", "Pub")); } product.Photo = ImageHandler.HttpPostedFileBaseToByteArray(upImage); product.PhotoType = upImage.ContentType; ProductDAO.Insert(product); return(RedirectToAction("Product", "Pub")); }
public ActionResult UpdateProfile(HttpPostedFileBase upImage) { if (upImage == null) { ModelState.AddModelError("", "Error - Image dont work"); return(View("Account")); } var pub = PubDAO.Search(UserSession.ReturnPubId(null)); pub.Photo = ImageHandler.HttpPostedFileBaseToByteArray(upImage); pub.PhotoType = upImage.ContentType; if (PubDAO.Update(pub) != true) { ModelState.AddModelError("", "Error - Database update image error!"); return(View("Account")); } return(RedirectToAction("Dashboard")); }
public ActionResult Pub(int id) { var pub = PubDAO.Search(id); var returnedPerson = PersonDAO.Search(UserSession.ReturnPersonId(null)); if (returnedPerson == null) return RedirectToAction("Logout", "User"); ViewBag.ProductList = ProductDAO.ReturnList(pub.Id); ViewBag.Categories = new MultiSelectList(CategoryDAO.ReturnList(), "Id", "Name"); if (RatingDAO.SearchByPersonAndPubId(UserSession.ReturnPersonId(null), id) != null) { ViewBag.Rate = "Unrate"; } else { ViewBag.Rate = "Rate"; } ViewBags(returnedPerson); return View(pub); }
public ActionResult Delete(string password) { var returnedPub = PubDAO.Search(UserSession.ReturnPubId(null)); if (returnedPub == null) { return(RedirectToAction("Logout", "User")); } var returnedUser = UserDAO.Search(returnedPub.UserId); if (password != returnedUser.Password) { ModelState.AddModelError("", "Error - Password does not match"); return(View("Account")); } PubDAO.Delete(returnedPub); UserDAO.Delete(returnedUser); return(RedirectToAction("Logout", "User")); }
public ActionResult Product() { ViewBags(); var pubSession = PubDAO.Search(UserSession.ReturnPubId(null)); ViewBag.ProductList = ProductDAO.ReturnList(pubSession.Id); ViewBag.Categories = new MultiSelectList(CategoryDAO.ReturnList(), "Id", "Name"); try { var product = (Product)System.Web.HttpContext.Current.Session["product"]; if (product != null) { ViewBag.Alter = "Yes"; return(View(product)); } } catch { } ViewBag.Alter = "No"; return(View()); }