Esempio n. 1
0
 public ActionResult Login(USER user)
 {
     using (DemoPPCRentalEntities entities = new DemoPPCRentalEntities())
     {
         var EncryptedUsersPassword = Crypto.Hash(user.Password);
         var UserDetails            = entities.USERs.Where(x => x.Email == user.Email && x.Password == EncryptedUsersPassword && x.Status == true).FirstOrDefault();
         if (UserDetails == null)
         {
             ViewBag.LoginError = "Wrong username or password.";
             return(View("Login", user));
         }
         else
         {
             Session["ID"]       = UserDetails.ID;
             Session["Email"]    = UserDetails.Email;
             Session["FullName"] = UserDetails.FullName;
             Session["Role"]     = UserDetails.Role;
             Session["Status"]   = UserDetails.Status;
             if (Convert.ToInt32(Session["Role"]) == 1)
             {
                 return(RedirectToAction("Admin_ControlPage", "Admin"));
             }
             else
             {
                 return(RedirectToAction("Index", "Home"));
             }
         }
     }
 }
        //public ProjectDriver(SearchResultState context)
        //{
        //    _context = context;
        //}

        public void InsertProjecttoDB(Table givenProjects)
        {
            using (var db = new DemoPPCRentalEntities())
            {
                foreach (var row in givenProjects.Rows)
                {
                    var property = new PROPERTY
                    {
                        PropertyName    = row["PropertyName"],
                        PropertyType_ID = db.PROPERTY_TYPE.ToList().FirstOrDefault(x => x.CodeType == row["PropertyType"]).ID,
                        Status_ID       = db.PROJECT_STATUS.ToList().FirstOrDefault(x => x.Status_Name == row["Status"]).ID,
                        District_ID     = db.DISTRICT.ToList().FirstOrDefault(x => x.DistrictName == row["District"]).ID,
                        Street_ID       = db.STREET.ToList().FirstOrDefault(x => x.StreetName == row["Street"]).ID,
                        Content         = row["Content"],
                        UserID          = db.USER.ToList().FirstOrDefault(x => x.FullName == row["Agency"]).ID,
                        Sale_ID         = db.USER.ToList().FirstOrDefault(x => x.FullName == row["Sale"]).ID,
                        Avatar          = row["Avarta"],
                        Images          = row["Images"],
                        BedRoom         = int.Parse(row["BedRoom"]),
                        BathRoom        = int.Parse(row["BathRoom"]),
                        PackingPlace    = int.Parse(row["PackingPlace"]),
                        Price           = int.Parse(row["Price"]),
                        Area            = row["Area"],
                    };

                    //_context.ReferenceBooks.Add(
                    //        givenProjects.Header.Contains("ID") ? row["ID"] : row["PropertyName"],
                    //        property);

                    db.PROPERTY.Add(property);
                }

                db.SaveChanges();
            }
        }
Esempio n. 3
0
        public ActionResult Create(USER collection)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var db = new DemoPPCRentalEntities();

                    var encryptedMd5Pas = MaHoa.MD5Hash(collection.Password);
                    collection.Password = encryptedMd5Pas;
                    //db.USER_TABLE.Add(collection);
                    //db.SaveChangesAsync();
                    var  dao = new AccountModel();
                    long id  = dao.Insert(collection);
                    if (id > 0)
                    {
                        return(RedirectToAction("Index", "_USER"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Thêm user không thành công");
                    }
                }
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View("Index"));
            }
        }
Esempio n. 4
0
        public ActionResult Details(int id)
        {
            db = new DemoPPCRentalEntities();
            var product = db.PROPERTies.FirstOrDefault(x => x.ID == id);

            return(View(product));
        }
Esempio n. 5
0
 public ActionResult Agency_AccountPage(int id)
 {
     using (DemoPPCRentalEntities entities = new DemoPPCRentalEntities())
     {
         var AccountDetails = entities.USERs.FirstOrDefault(x => x.ID == id);
         return(View(AccountDetails));
     }
 }
Esempio n. 6
0
 public ActionResult ChangePassword(int id)
 {
     using (DemoPPCRentalEntities entities = new DemoPPCRentalEntities())
     {
         var UserInfo = entities.USERs.FirstOrDefault(x => x.ID == id);
         return(View(UserInfo));
     }
 }
Esempio n. 7
0
 public static void CleanDatabase(TestContext context)
 {
     using (var db = new DemoPPCRentalEntities())
     {
         //db.OrderLines.RemoveRange(db.OrderLines);
         //db.Orders.RemoveRange(db.Orders);
         //db.Books.RemoveRange(db.Books);
         db.SaveChanges();
     }
 }
Esempio n. 8
0
 public void CleanDatabase()
 {
     using (var db = new DemoPPCRentalEntities())
     {
         //db.OrderLines.RemoveRange(db.OrderLines);
         //db.Orders.RemoveRange(db.Orders);
         db.PROPERTY.RemoveRange(db.PROPERTY);
         db.SaveChanges();
     }
 }
        //public void Login(string email, string pass)
        //{
        //    using (var controller = new AccountController())
        //    {
        //        _context = controller.Login(email, pass);
        //    }
        //}



        public void ViewDetail(string propertyName)
        {
            var db = new DemoPPCRentalEntities();

            int id = db.PROPERTY.FirstOrDefault(r => r.PropertyName == propertyName).ID;

            using (var controller = new PropertyController())
            {
                _context = controller.Details(id);
            }
        }
Esempio n. 10
0
 public ActionResult Admin_ActivateAccount(int id, USER user)
 {
     using (DemoPPCRentalEntities entities = new DemoPPCRentalEntities())
     {
         var EditedInfo = entities.USERs.FirstOrDefault(x => x.ID == id);
         EditedInfo.Status = true;
         //entities.Configuration.ValidateOnSaveEnabled = false;
         entities.SaveChanges();
     }
     return(RedirectToAction("Admin_ControlPage"));
 }
Esempio n. 11
0
        public JsonResult GetStreet(int did)
        {
            var db      = new DemoPPCRentalEntities();
            var streets = db.STREETs.Where(s => s.DISTRICT_Table.ID == did);

            return(Json(streets.Select(s => new
            {
                id = s.ID,
                text = s.StreetName
            }), JsonRequestBehavior.AllowGet));
        }
Esempio n. 12
0
 public ActionResult ChangePassword(int id, USER user)
 {
     using (DemoPPCRentalEntities entities = new DemoPPCRentalEntities())
     {
         var AccountDetails = entities.USERs.FirstOrDefault(x => x.ID == id);
         AccountDetails.Password        = Crypto.Hash(user.Password);
         AccountDetails.ConfirmPassword = Crypto.Hash(user.ConfirmPassword);
         entities.Configuration.ValidateOnSaveEnabled = false;
         entities.SaveChanges();
         return(Redirect(Url.Action("Agency_AccountPage", "Agency") + "/" + Session["ID"]));
     }
 }
Esempio n. 13
0
        public void ShowPropertyDetails(Table shownPropertyDetails)
        {
            DemoPPCRentalEntities db = new DemoPPCRentalEntities();
            //Arrange
            var expectedPropertyDetails = shownPropertyDetails.Rows.Single();

            //Act
            var actualPropertyDetails = _context.Model <PROPERTY>();

            //Assert
            actualPropertyDetails.Should().Match <PROPERTY>(
                b => (b.PropertyName == expectedPropertyDetails["PropertyName"]));
        }
Esempio n. 14
0
 public ActionResult Admin_Decentralization(int id, USER user)
 {
     using (DemoPPCRentalEntities entities = new DemoPPCRentalEntities())
     {
         var EditedInfo = entities.USERs.FirstOrDefault(x => x.ID == id);
         EditedInfo.Email    = user.Email;
         EditedInfo.Password = user.Password;
         EditedInfo.FullName = user.FullName;
         EditedInfo.Phone    = user.Phone;
         EditedInfo.Address  = user.Address;
         EditedInfo.Role     = user.Role;
         EditedInfo.Status   = user.Status;
         entities.Configuration.ValidateOnSaveEnabled = false;
         entities.SaveChanges();
     }
     return(RedirectToAction("Admin_ControlPage"));
 }
Esempio n. 15
0
 public ActionResult Agency_UpdateInfomation(int id, USER user)
 {
     using (DemoPPCRentalEntities entities = new DemoPPCRentalEntities())
     {
         var EditedInfo = entities.USERs.FirstOrDefault(x => x.ID == id);
         EditedInfo.Email           = user.Email;
         EditedInfo.Password        = user.Password;
         EditedInfo.ConfirmPassword = user.ConfirmPassword;
         EditedInfo.FullName        = user.FullName;
         EditedInfo.Phone           = user.Phone;
         EditedInfo.Address         = user.Address;
         EditedInfo.Role            = user.Role;
         EditedInfo.Status          = user.Status;
         entities.Configuration.ValidateOnSaveEnabled = false;
         entities.SaveChanges();
     }
     return(Redirect(Url.Action("Agency_AccountPage", "Agency") + "/" + Session["ID"]));
 }
Esempio n. 16
0
        public ActionResult Register(USER user)
        {
            using (DemoPPCRentalEntities entities = new DemoPPCRentalEntities())
            {
                if (entities.USERs.Any(x => x.Email == user.Email))
                {
                    ViewBag.DuplicateMessage = "This Email has already used.";
                    return(View("Register", user));
                }
                user.Password        = Crypto.Hash(user.Password);
                user.ConfirmPassword = Crypto.Hash(user.ConfirmPassword);
                entities.USERs.Add(user);
                entities.SaveChanges();
            }
            ModelState.Clear();
            ViewBag.SuccessMessage = "Your account successfully registered. Your account will be activated in 24h if all information is valid.";

            return(View("Register", new USER()));
        }
Esempio n. 17
0
        public void Login(string email, string pwd)
        {
            user = new AccountController();
            db   = new DemoPPCRentalEntities();
            us   = db.USER.FirstOrDefault(d => d.Email == email);

            var moqContext = new Moq.Mock <ControllerContext>();
            var moqSession = new Moq.Mock <HttpSessionStateBase>();

            moqContext.Setup(c => c.HttpContext.Session).Returns(moqSession.Object);
            user.ControllerContext = moqContext.Object;
            moqSession.Setup(s => s["UserRole"]).Returns("2");//debug

            us.Email    = email;
            us.Password = pwd;
            us.Role     = db.USER.FirstOrDefault(d => d.Email == email).Role;
            us.Phone    = db.USER.FirstOrDefault(d => d.Email == email).Phone;
            us.Address  = db.USER.FirstOrDefault(d => d.Email == email).Address;
            us.Role     = db.USER.FirstOrDefault(d => d.Email == email).Role;
            us.ID       = db.USER.FirstOrDefault(d => d.Email == email).ID;
            us.Status   = db.USER.FirstOrDefault(d => d.Email == email).Status;
            us.FullName = db.USER.FirstOrDefault(d => d.Email == email).FullName;
            user.Login(email, pwd);
        }
Esempio n. 18
0
 public Project_TypeModel()
 {
     context = new DemoPPCRentalEntities();
 }
Esempio n. 19
0
 public PropertyModel()
 {
     context = new DemoPPCRentalEntities();
 }
Esempio n. 20
0
 public ContactModel()
 {
     db = new DemoPPCRentalEntities();
 }
Esempio n. 21
0
 public AccountModel()
 {
     db = new DemoPPCRentalEntities();
 }