Ejemplo n.º 1
0
        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"));
        }
Ejemplo n.º 2
0
        public ActionResult Update(Person personUpdate)
        {
            var returnedPerson = PersonDAO.Search(UserSession.ReturnPersonId(null));
            if (returnedPerson == null) return RedirectToAction("Logout", "User");

            // Get the coordinates of the bar location that the user has given
            Tuple<double, double> tuple =
                GoogleGeoLocation.GetCoordinates(personUpdate.Address, personUpdate.City, personUpdate.State);

            // Set the remaining properties of the model
            returnedPerson.Lat = tuple.Item1;
            returnedPerson.Lng = tuple.Item2;
            returnedPerson.Name = personUpdate.Name;
            returnedPerson.Birthday = personUpdate.Birthday;
            returnedPerson.Address = personUpdate.Address;
            returnedPerson.City = personUpdate.City;
            returnedPerson.State = personUpdate.State;

            if (PersonDAO.Update(returnedPerson) != true)
            {
                ModelState.AddModelError("", "Error - Check information and try again");
                return View("Account");
            }
            return View("Account");
        }
Ejemplo n.º 3
0
        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));
            }
        }
Ejemplo n.º 4
0
        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"));
        }
Ejemplo n.º 5
0
        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));
            }
        }