コード例 #1
0
ファイル: PubController.cs プロジェクト: Zaetic/Dain
        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"));
        }
コード例 #2
0
ファイル: PersonController.cs プロジェクト: Zaetic/Dain
        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");
        }
コード例 #3
0
ファイル: PubController.cs プロジェクト: Stunitz/Dain
        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));
            }
        }
コード例 #4
0
ファイル: PubController.cs プロジェクト: Zaetic/Dain
        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"));
        }
コード例 #5
0
ファイル: PubController.cs プロジェクト: Stunitz/Dain
        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));
            }
        }