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 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 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 ActionResult Account() { var returnedPub = PubDAO.Search(UserSession.ReturnPubId(null)); ViewBags(); return(View(returnedPub)); }
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 Login(User user) { var returnedUser = UserDAO.SearchByEmailPassword(user.Email, user.Password); if (returnedUser == null) { ModelState.AddModelError("", "Error - Email or Password incorrect"); return(View(user)); } if (returnedUser.UserType.Equals(nameof(Pub))) { var pub = PubDAO.SearchByUserId(returnedUser.Id); UserSession.ReturnPubId(pub.Id); UserSession.ReturnUserId(pub.UserId); return(RedirectToAction("Dashboard", "Pub")); } else if (returnedUser.UserType.Equals(nameof(Person))) { var person = PersonDAO.SearchByUserId(returnedUser.Id); UserSession.ReturnPersonId(person.Id); UserSession.ReturnUserId(person.UserId); return(RedirectToAction("Dashboard", "Person")); } ModelState.AddModelError("", "Error - I dont know"); return(View("Login", user)); }
public ActionResult Pubs() { var returnedPerson = PersonDAO.Search(UserSession.ReturnPersonId(null)); if (returnedPerson == null) return RedirectToAction("Logout", "User"); ViewBags(returnedPerson); return View(PubDAO.ReturnList().OrderByDescending(l => l.Rating).ToList()); }
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 UpdateLayout(string layout) { var update = PubDAO.SearchByUserId(UserSession.ReturnUserId(null)); if (update == null) { return(RedirectToAction("Logout", "User")); } update.LayoutStyle = layout; Update(update); return(RedirectToAction("Account")); }
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 Register(Pub newPub, HttpPostedFileBase upImage) { // Verify the if the model is valid if (ModelState.IsValid == false) { ModelState.AddModelError("", "Error - Check information and try again"); return(View(newPub)); } // Get the user from the session that the User Controller generated with the basic data from the user var newUser = (User)System.Web.HttpContext.Current.Session["user"]; // If there is nothing in the user session, return to the user registration page if (newUser == null) { return(RedirectToAction("Register", "User")); } // Get the coordinates of the bar location that the user has given Tuple <double, double> tuple = GoogleGeoLocation.GetCoordinates(newPub.Address, newPub.City, newPub.State); // Set the remaining properties of the model newPub.Lat = tuple.Item1; newPub.Lng = tuple.Item2; newPub.Photo = ImageHandler.HttpPostedFileBaseToByteArray(upImage); newPub.PhotoType = upImage.ContentType; newPub.LayoutStyle = "dark"; newUser.RegistrationDate = DateTime.Now; newUser.UserType = nameof(Pub); newUser.Password = CryptSharp.Crypter.MD5.Crypt(newUser.Password); // Insert in the database, if successful var returnedUser = UserDAO.Insert(newUser); newPub.UserId = returnedUser.Id; var returnedPub = PubDAO.Insert(newPub); if (returnedPub == null || returnedUser == null) { ModelState.AddModelError("", "Error - Check information and try again"); return(View(newPub)); } // Generate a session with the user database id UserSession.ReturnPubId(returnedPub.Id); UserSession.ReturnUserId(returnedPub.UserId); System.Web.HttpContext.Current.Session["user"] = null; return(RedirectToAction("Dashboard", "Pub")); }
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 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 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 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()); }
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 void ViewBags(Pub returnedPub) { var pubsList = PubDAO.ReturnList().Select(pub => new GoogleMapPubData() { Id = pub.Id, Name = pub.Name, Photo = ImageHandler.PhotoBase64(pub.Photo, pub.PhotoType), Rating = pub.Rating, Lat = pub.Lat, Lng = pub.Lng, Address = pub.Address, FoundationDate = pub.FoundationDate }).ToList(); ViewBag.PubsList = JsonConvert.SerializeObject(pubsList); ViewBag.Lng = returnedPub.Lng == 0 ? -49.276855 : returnedPub.Lng; ViewBag.Lat = returnedPub.Lat == 0 ? -25.441105 : returnedPub.Lat; ViewBag.Name = returnedPub.Name; ViewBag.Profile = ImageHandler.PhotoBase64(returnedPub.Photo, returnedPub.PhotoType); ViewBag.LayoutStyle = returnedPub.LayoutStyle; ViewBag.Type = "pub"; }
public ActionResult Register(Pub newPub, HttpPostedFileBase upImage) { if (ModelState.IsValid == true) { Tuple <double, double> tuple = GoogleGeoLocation.GetCoordinates(newPub.Address, newPub.State); if (upImage == null) { newPub.PhotoUrl = null; newPub.PhotoType = null; } else { newPub.PhotoUrl = ImageHandler.HttpPostedFileBaseToByteArray(upImage); newPub.PhotoType = upImage.ContentType; } newPub.RegistrationDate = DateTime.Now; newPub.Lat = tuple.Item1; newPub.Lng = tuple.Item2; var returnedPub = PubDAO.Insert(newPub); if (returnedPub == null) { ModelState.AddModelError("", "Error - Check information and try again"); return(View(newPub)); } else { UserSession.ReturnPubId(returnedPub.Id); return(RedirectToAction("Dashboard", "Pub")); } } else { ModelState.AddModelError("", "Error - Check information and try again"); return(View(newPub)); } }
public IQueryable <Pub> GetPubs() { return(PubDAO.ReturnList().AsQueryable()); }