Example #1
0
        public IActionResult Remove(int id)
        {
            if (_auth.User == null)
            {
                return(RedirectToAction("index", "account"));
            }

            Addvertisiment SelectedAdd = _context.Addvertisiments.Include("User").Where(a => a.AddvertisimentID == id && a.UserId == _auth.User.UserId).FirstOrDefault();

            if (SelectedAdd == null)
            {
                return(BadRequest());
            }

            SelectedAdd.AddStatus = AddStatus.Hidden;

            _context.Entry(SelectedAdd).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            _context.SaveChanges();

            List <Addvertisiment> DeactivatedAdds = _context.Addvertisiments.Where(a => a.AddStatus == AddStatus.Deactive && a.UserId == _auth.User.UserId).ToList();
            List <Addvertisiment> AllAdds         = _context.Addvertisiments.Where(a => a.AddStatus != AddStatus.Hidden && a.UserId == _auth.User.UserId).ToList();

            int DeactivatedAddsCount = DeactivatedAdds.Count();
            int AllAddsCount         = AllAdds.Count();

            return(Ok(
                       new
            {
                DeactivatedAddsCount,
                AllAddsCount
            }
                       ));
        }
Example #2
0
        public IActionResult Deactivate(int id)
        {
            if (_auth.User == null)
            {
                return(RedirectToAction("index", "account"));
            }

            Addvertisiment SelectedAdd = _context.Addvertisiments.Include("User").Where(a => a.AddvertisimentID == id && a.UserId == _auth.User.UserId).FirstOrDefault();

            if (SelectedAdd == null)
            {
                return(BadRequest());
            }

            SelectedAdd.AddStatus = AddStatus.Deactive;

            _context.Entry(SelectedAdd).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            _context.SaveChanges();

            //return RedirectToAction("index", "cabinet", new { id = _auth.User.UserId });

            List <Addvertisiment> DeactivatedAdds = _context.Addvertisiments.Where(a => a.AddStatus == AddStatus.Deactive && a.UserId == _auth.User.UserId).ToList();
            int DeactivatedAddsCount = DeactivatedAdds.Count();

            List <Addvertisiment> ActivedAdds = _context.Addvertisiments.Where(a => a.AddStatus == AddStatus.Active && a.UserId == _auth.User.UserId).ToList();
            int ActiveAddsCount = ActivedAdds.Count();

            List <Addvertisiment> WaitingdAdds = _context.Addvertisiments.Where(a => a.AddStatus == AddStatus.Waiting && a.UserId == _auth.User.UserId).ToList();
            int WaitingAddsCount = WaitingdAdds.Count();

            List <Addvertisiment> RentAdds = _context.Addvertisiments.Where(a => a.AddStatus == AddStatus.Active && a.AddTypeID < 3 && a.UserId == _auth.User.UserId).ToList();
            int RentAddsCount = RentAdds.Count();

            List <Addvertisiment> SaleAdds = _context.Addvertisiments.Where(a => a.AddStatus == AddStatus.Active && a.AddTypeID == 3 && a.UserId == _auth.User.UserId).ToList();
            int SaleAddsCount = SaleAdds.Count();

            return(Ok(
                       new
            {
                DeactivatedAddsCount,
                ActiveAddsCount,
                WaitingAddsCount,
                RentAddsCount,
                SaleAddsCount
            }));
        }
Example #3
0
        public IActionResult Remove(int id)
        {
            if (_auth.APuser == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            Addvertisiment SelectedAdd = _context.Addvertisiments.Find(id);

            if (SelectedAdd == null || _auth.APuser.isSuperAdmin == false)
            {
                return(NotFound());
            }

            List <PropPhoto> propPhotos = _context.PropPhotos.Where(p => p.PropertyId == SelectedAdd.PropertyID).ToList();


            foreach (PropPhoto item in propPhotos)
            {
                string FilePath = Path.Combine(_hosting.WebRootPath, "img", "property", item.PropPhotoName);
                _context.PropPhotos.Remove(item);

                if (System.IO.File.Exists(FilePath))
                {
                    try
                    {
                        System.IO.File.Delete(FilePath);
                    }
                    catch (Exception)
                    {
                        return(RedirectToAction("index", "Add"));
                    }
                }
            }

            Property prop = _context.Properties.Find(SelectedAdd.PropertyID);

            _context.Properties.Remove(prop);


            _context.Addvertisiments.Remove(SelectedAdd);

            _context.SaveChanges();

            return(RedirectToAction("index", "Add"));
        }
Example #4
0
        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"));
        }
Example #5
0
        public IActionResult Detail(int id)
        {
            Addvertisiment Add = _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.AddvertisimentID == id).FirstOrDefault();

            if (Add == null || ((Add.AddStatus == AddStatus.Deactive || Add.AddStatus == AddStatus.Hidden || Add.AddStatus == AddStatus.Waiting) && _auth.APuser == null)) //Dont show Hidden, Waiting, Deactive adds to Users or Quests
            {
                return(NotFound());
            }
            else
            {
                AddViewModel data = new AddViewModel
                {
                    AddDetailIndex = new AddDetailIndexViewModel
                    {
                        Add            = Add,
                        PropertyPhotos = _context.PropPhotos.Where(pp => pp.PropertyId == Add.PropertyID).ToList(),
                        Features       = _context.PropFeatures.Include(pf => pf.Feature).Where(pf => pf.PropertyID == Add.PropertyID).ToList(),
                    },
                    Owner = new OwnerPanelViewModel
                    {
                        Owner           = _context.Users.Include(u => u.Adds).Where(u => u.UserId == Add.UserId).FirstOrDefault(),
                        OwnerActiveAdds = _context.Addvertisiments.Where(a => a.UserId == Add.UserId && a.AddStatus == AddStatus.Active).Count()
                    },
                    AddsPanel = new AddsPanelViewModel
                    {
                        Type    = ViewType.normal,
                        AddList = _context.Addvertisiments.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 && a.AddTypeID == Add.AddTypeID && a.Property.PropertySortId == Add.Property.PropertySortId && a.AddvertisimentID != Add.AddvertisimentID).
                                  OrderByDescending(a => a.CreatedAt).Take(8).ToList(),
                    },
                    Breadcumb = new BreadcumbViewModel
                    {
                        Title = "Elan haqqında",
                        Path  = new List <BreadcumbItemViewModel>()
                    }
                };

                BreadcumbItemViewModel home = new BreadcumbItemViewModel
                {
                    Name       = "Ana səhifə",
                    Controller = "Home",
                    Action     = "index"
                };

                BreadcumbItemViewModel adds = new BreadcumbItemViewModel
                {
                    Name       = "Bütün elanlar",
                    Controller = "Add",
                    Action     = "index"
                };

                BreadcumbItemViewModel detail = new BreadcumbItemViewModel
                {
                    Name = "Elan haqqında"
                };

                data.Breadcumb.Path.Add(home);
                data.Breadcumb.Path.Add(adds);
                data.Breadcumb.Path.Add(detail);
                ViewBag.Partial = data.Breadcumb;
                ViewBag.Adds    = data.AddsPanel;
                ViewBag.Owner   = data.Owner;
                return(View(data));
            }
        }