Exemplo n.º 1
0
        public ActionResult Search(PropertyModel propertyModel)
        {
            IEnumerable <PropertyType> propertyTypes = propertyBL.GetPropertyType();
            IEnumerable <string>       locationList  = propertyBL.GetLocation();

            ViewBag.propertyType = new SelectList(propertyTypes, "PropertyTypeID", "Type");
            ViewBag.location     = new SelectList(locationList);
            int propertyId, propertyTypeId;
            IEnumerable <PropertyValues>  propertyValues   = new List <PropertyValues>();
            IEnumerable <PropertyFeature> propertyFeatures = new List <PropertyFeature>();
            List <Property> property = propertyBL.SearchByLocation(propertyModel.Location, propertyModel.PropertyTypeID);

            if (property.Count != 0)
            {
                for (int index = 0; index < property.Count; index++)
                {
                    propertyId       = Convert.ToInt32(property[index].PropertyId);
                    propertyTypeId   = Convert.ToInt32(property[index].PropertyTypeID);
                    propertyValues   = (propertyBL.GetPropertyValueDetails(propertyId));
                    propertyFeatures = (propertyBL.GetPropertyFeatureDetails(propertyTypeId));
                }
                TempData["Property"]        = property;
                TempData["PropertyFeature"] = propertyFeatures;
                TempData["PropertyValue"]   = propertyValues;
                return(RedirectToAction("DisplayByLocation"));
            }
            else
            {
                ViewBag.Message = "There is no property :(";
                return(View());
            }
        }
        public ActionResult Login(LoginModel loginModel)
        {
            User   user   = new User();
            UserBL userBL = new UserBL();

            if (ModelState.IsValid)
            {
                user.Email    = loginModel.Email;
                user.Password = loginModel.Password;
                user          = userBL.Login(user);
                if (user != null)
                {
                    FormsAuthentication.SetAuthCookie(user.Email, false);
                    var    authTicket      = new FormsAuthenticationTicket(1, user.Email, DateTime.Now, DateTime.Now.AddMinutes(20), false, user.Role);
                    string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
                    var    authCookie      = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
                    HttpContext.Response.Cookies.Add(authCookie);
                    if (user.Role == "Admin")
                    {
                        return(RedirectToAction("DisplayPropertyDetails", "Property"));
                    }
                    else if (user.Role == "Buyer")
                    {
                        PropertyBL      propertyBL       = new PropertyBL();
                        List <Property> property         = userBL.GetPropertyDetailsByUserId(user.UserId);
                        List <int>      propertyValues   = new List <int>();
                        List <string>   propertyFeatures = new List <string>();
                        for (int index = 0; index < property.Count; index++)
                        {
                            propertyValues[index]   = Convert.ToInt32(propertyBL.GetPropertyValueDetails(Convert.ToInt32(property[index].PropertyId)));
                            propertyFeatures[index] = Convert.ToString(propertyBL.GetPropertyFeatureDetails(Convert.ToInt32(property[index].PropertyTypeID)));
                        }
                        TempData["Property"]        = property;
                        TempData["PropertyFeature"] = propertyFeatures;
                        TempData["PropertyValue"]   = propertyValues;
                        TempData["UserId"]          = user.UserId;
                        return(RedirectToAction("DisplayBuyerPropertyDetails", "Buyer"));
                    }
                    else
                    {
                        ViewBag.Message = "Login failed";
                    }
                }
                else
                {
                    ViewBag.Message = "Login failed";
                }
            }
            return(View());
        }