Ejemplo n.º 1
0
        public ActionResult StoreHouse(CreateHouseViewModel ch)
        {
            if (Session["user_id"] != null)
            {
                var user_id    = (int)Session["user_id"];
                var singleUser = _Context.Users.SingleOrDefault(u => u.Id == user_id);
                if (!ModelState.IsValid)
                {
                    var newHouse = new CreateHouseViewModel()
                    {
                        Divisions = _Context.Divisions.ToList(),
                        UserId    = singleUser.UserId
                    };

                    return(View("CreateHouse", newHouse));
                }

                var nHouse = new House()
                {
                    Address = ch.Address,
                    UserId  = user_id,
                    ThanaId = ch.ThanaId
                };
                _Context.Houses.Add(nHouse);
                _Context.SaveChanges();

                return(RedirectToAction("Index", "Users"));
            }
            return(RedirectToAction("LogInUser", "Users"));
        }
Ejemplo n.º 2
0
        public ActionResult FinishAdd(int id)
        {
            var conPay = _Context.ConfirmPayments.SingleOrDefault(cp => cp.Id == id);

            conPay.IsCheckedByAdmin = true;
            _Context.SaveChanges();

            var advertise = _Context.Advertisements.SingleOrDefault(a => a.Key == conPay.AddKey);

            advertise.IsPaid = true;
            _Context.SaveChanges();

            return(RedirectToAction("PendingAdd"));
        }
Ejemplo n.º 3
0
        public ActionResult Store(NewUserViewModel newUser)
        {
            if (!ModelState.IsValid)
            {
                var user = new NewUserViewModel()
                {
                    User        = newUser.User,
                    Occupations = _Context.Occupations.ToList()
                };
                return(View("Create", user));
            }
            var checkingUser = _Context.Users.SingleOrDefault(u => u.UserId == newUser.User.UserId);

            if (checkingUser != null)
            {
                var user = new NewUserViewModel()
                {
                    User        = newUser.User,
                    Occupations = _Context.Occupations.ToList()
                };
                ModelState.AddModelError("User.UserId", "User Id is already exists!!! Try another User Id");
                return(View("Create", user));
            }

            // hasihing password to protect
            byte[] bytes   = Encoding.Unicode.GetBytes(newUser.User.Password);
            byte[] inArray = HashAlgorithm.Create("SHA1").ComputeHash(bytes);
            newUser.User.Password = Convert.ToBase64String(inArray);

            // hasihing confirm password to protect
            byte[] bytes1   = Encoding.Unicode.GetBytes(newUser.User.ConfirmPassword);
            byte[] inArray1 = HashAlgorithm.Create("SHA1").ComputeHash(bytes1);
            newUser.User.ConfirmPassword = Convert.ToBase64String(inArray1);

            _Context.Users.Add(newUser.User);
            _Context.SaveChanges();

            return(RedirectToAction("Create"));
        }
        public ActionResult StoreManager(ManagerHouse mh)
        {
            if (Session["user_id"] != null)
            {
                if (Session["check_pass"] == null)
                {
                    return(RedirectToAction("CheckingNManager"));
                }
                if (!ModelState.IsValid)
                {
                    return(View("CreateManager", mh));
                }
                var keyChecking = _Context.HouseKeys.SingleOrDefault(hk => hk.Key == mh.Key);
                if (keyChecking == null)
                {
                    ModelState.AddModelError("Key", "Invalid Key. Please Try Another.");
                    return(View("CreateManager", mh));
                }
                var checkExistingManage =
                    _Context.ManagerHouses.SingleOrDefault(m => m.Key == m.Key && m.IsActive == true);
                if (checkExistingManage != null)
                {
                    ModelState.AddModelError("Key", "Already have a manager.");
                    return(View("CreateManager", mh));
                }
                mh.IsActive = true;
                _Context.ManagerHouses.Add(mh);
                _Context.SaveChanges();

                var existingUser = _Context.Users.Find((int)Session["user_id"]);

                existingUser.IsAManager = true;
                _Context.SaveChanges();

                var       user_id = (int)Session["user_id"];
                var       user    = _Context.Users.Find(user_id);
                UserHouse uh      = new UserHouse();
                uh.UserId     = user.UserId;
                uh.IsActive   = true;
                uh.HouseKeyId = keyChecking.Id;

                _Context.UserHouses.Add(uh);
                _Context.SaveChanges();

                return(RedirectToAction("Index", "Users"));
            }
            return(RedirectToAction("LogInUser", "Users"));
        }