public IActionResult Login(APAccountLoginModel Login) { if (ModelState.IsValid) { APuser user = _context.APusers.Where(u => u.Email == Login.Email).FirstOrDefault(); if (user != null) { if (Crypto.VerifyHashedPassword(user.Password, Login.Password)) { user.Token = Guid.NewGuid().ToString(); _context.SaveChanges(); Response.Cookies.Append("APtoken", user.Token, new Microsoft.AspNetCore.Http.CookieOptions { Expires = DateTime.Now.AddHours(1), HttpOnly = true }); return(RedirectToAction("index", "home")); } else { ModelState.AddModelError("Login.Password", "E-poçt və ya şifrə yalnışdır"); } } else { ModelState.AddModelError("Login.Password", "E-poçt və ya şifrə yalnışdır"); } } return(View("~/Areas/Admin/Views/Account/Login.cshtml")); }
public IActionResult Login(AccountLoginModel Login) { if (ModelState.IsValid) { User user = _context.Users.Where(u => u.Email == Login.Email).FirstOrDefault(); if (user != null) { if (Crypto.VerifyHashedPassword(user.Password, Login.Password)) { user.Token = Guid.NewGuid().ToString(); _context.SaveChanges(); Response.Cookies.Append("token", user.Token, new Microsoft.AspNetCore.Http.CookieOptions { Expires = DateTime.Now.AddYears(1), HttpOnly = true }); TempData["Success"] = "Sistemə müvəffəqiyyətlə daxil oldunuz..."; return(RedirectToAction("index", "home")); } else { ModelState.AddModelError("Login.Password", "E-poçt və ya şifrə yalnışdır"); } } else { ModelState.AddModelError("Login.Password", "E-poçt və ya şifrə yalnışdır"); } } AccountIndexViewModel data = new AccountIndexViewModel { Login = Login }; data.Breadcumb = new BreadcumbViewModel { Title = "Şəxsi kabinetə giriş", Path = new List <BreadcumbItemViewModel>() }; BreadcumbItemViewModel home = new BreadcumbItemViewModel { Name = "Ana səhifə", Controller = "Home", Action = "index" }; BreadcumbItemViewModel login = new BreadcumbItemViewModel { Name = "Daxil Ol" }; data.Breadcumb.Path.Add(home); data.Breadcumb.Path.Add(login); ViewBag.Partial = data.Breadcumb; return(View("~/Views/Account/Index.cshtml")); }
public IActionResult Approve(int id) { if (_auth.APuser == null) { return(RedirectToAction("Login", "Account")); } User SelectedUser = _context.Users.Find(id); if (SelectedUser == null) { return(NotFound()); } SelectedUser.Status = UserStatus.Active; _context.SaveChanges(); return(RedirectToAction("index", "User")); }
public IActionResult Deactivate(int id) { if (_auth.APuser == null) { return(RedirectToAction("Login", "Account")); } Addvertisiment SelectedAdd = _context.Addvertisiments.Find(id); if (SelectedAdd == null || _auth.APuser.isAdmin == false) { return(NotFound()); } SelectedAdd.AddStatus = AddStatus.Deactive; _context.SaveChanges(); return(RedirectToAction("index", "Add")); }
public IActionResult Index() { //Checking Date of Creating Add for Deactivate foreach (Addvertisiment add in _context.Addvertisiments.ToList()) { if (add.ExpDate < DateTime.Now) { add.AddStatus = AddStatus.Deactive; _context.SaveChanges(); } } if (_auth.APuser == null) { return(RedirectToAction("Login", "Account")); } return(View()); }
public IActionResult Index() { //Checking Date of Creating Add for Deactivate foreach (Addvertisiment add in _context.Addvertisiments.ToList()) { if (add.ExpDate < DateTime.Now) { add.AddStatus = AddStatus.Deactive; _context.SaveChanges(); } } HomeIndexViewModel data = new HomeIndexViewModel { AddsPanel = new AddsPanelViewModel { Type = ViewType.normal, AddList = _context.Addvertisiments.Include("AddType").Include("Property"). Include("Property.City"). Include("Property.District"). Include("Property.Flat"). Include("Property.Floor"). Include("Property.PropDoc"). Include("Property.PropertySort"). Include("Property.Project"). Where(a => a.User.Status == UserStatus.Active && a.AddStatus == AddStatus.Active).OrderByDescending(a => a.CreatedAt).Take(8).ToList(), }, SearchPanel = new FilterPanelViewModel { AddTypes = _context.AddTypes.ToList(), Cities = _context.Cities.ToList(), PropertySorts = _context.PropertySorts.ToList(), }, Agencies = _context.Users.Where(u => u.UserTypeID == 1 && u.Status == UserStatus.Active && u.Adds.Count > 0).ToList(), }; ViewBag.Adds = data.AddsPanel; return(View(data)); }
public IActionResult Create(AddCreatePostViewModel AddCreatePost) { //Checking User who created addvertisiment if (_auth.User.Token != Request.Cookies["token"]) { return(BadRequest()); } if (ModelState.IsValid) { Property newProp = new Property //CREATE NEW PROPERTY { CityId = AddCreatePost.CityId, DistrictId = AddCreatePost.DistrictId, PropertySortId = AddCreatePost.PropertySortId, PropDocId = AddCreatePost.PropDocId, FloorId = AddCreatePost.FloorId, FloorSum = AddCreatePost.FloorSum, FlatId = AddCreatePost.FlatId, PropProjectId = AddCreatePost.ProjectId, BuildingVolume = AddCreatePost.BuildingVolume, LandVolume = AddCreatePost.LandVolume, Longitude = AddCreatePost.Longitude, Latitude = AddCreatePost.Latitude, FullAbout = AddCreatePost.FullAbout, FullAddress = AddCreatePost.PropertyFullAddress }; _context.Properties.Add(newProp); _context.SaveChanges(); foreach (Feature item in AddCreatePost.Features) { if (item.Selected) { PropFeature newPropFeature = new PropFeature //PROPERTY FEATURE { PropertyID = newProp.PropertyId, FeatureID = item.FeatureID }; _context.PropFeatures.Add(newPropFeature); _context.SaveChanges(); } } string FileName; if (AddCreatePost.Photos != null && AddCreatePost.Photos.Count() > 0) { foreach (IFormFile photo in AddCreatePost.Photos) { string UploadsFolder; UploadsFolder = Path.Combine(_hosting.WebRootPath, "img", "property"); FileName = Guid.NewGuid() + "_" + photo.FileName; string FilePath = Path.Combine(UploadsFolder, FileName); FileStream fs = new FileStream(FilePath, FileMode.OpenOrCreate); photo.CopyTo(fs); fs.Close(); PropPhoto newPropPhoto = new PropPhoto //CREATE NEW PHOTO OF PROPERTY { PropPhotoName = FileName, PropertyId = newProp.PropertyId }; _context.PropPhotos.Add(newPropPhoto); _context.SaveChanges(); } } Addvertisiment newAdd = new Addvertisiment // CREATE NEW ADDVERTISIMENT { PropertyID = newProp.PropertyId, UserId = _auth.User.UserId, AddTypeID = AddCreatePost.AddTypeId, PropPrice = AddCreatePost.AddPrice, CreatedAt = DateTime.Now, ExpDate = DateTime.Now.AddMonths(1), AddStatus = AddStatus.Waiting }; _context.Addvertisiments.Add(newAdd); newProp.MainPhoto = newProp.Photos[0].PropPhotoName; _context.Entry(newProp).State = Microsoft.EntityFrameworkCore.EntityState.Modified; _context.SaveChanges(); TempData["Success"] = "Elanınız qəbul edildi, təsdiq edildikdən sonra yayımlanacaq."; return(RedirectToAction("cabinet", "account")); } else { AddViewModel data = new AddViewModel { AddCreateIndex = new AddCreateIndexViewModel { Cities = _context.Cities.Include(c => c.Districts).ToList(), PropertySorts = _context.PropertySorts.OrderBy(ps => ps.PropertySortId).ToList(), AddTypes = _context.AddTypes.OrderBy(ad => ad.AddTypeId).ToList(), Flats = _context.Flats.OrderBy(f => f.FlatID).ToList(), Floors = _context.Floors.OrderBy(f => f.FloorID).ToList(), PropDocs = _context.PropDocs.OrderBy(ps => ps.PropDocID).ToList(), Features = _context.Features.OrderBy(f => f.FeatureID).ToList() }, Breadcumb = new BreadcumbViewModel { Title = "Elan yerləşdir", Path = new List <BreadcumbItemViewModel>() }, }; BreadcumbItemViewModel home = new BreadcumbItemViewModel { Name = "Ana səhifə", Controller = "Home", Action = "index" }; BreadcumbItemViewModel create = new BreadcumbItemViewModel { Name = "Elan yerləşdirmə" }; data.Breadcumb.Path.Add(home); data.Breadcumb.Path.Add(create); ViewBag.Partial = data.Breadcumb; return(View(data)); } }