예제 #1
0
        public IActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }

            Customer customer = _context.Clients
                                .Include(x => x.DistrictToClients)
                                .Include(x => x.TypesHousingToCustomers)
                                .Include(x => x.Phones)
                                .Single(m => m.Id == id);

            if (customer == null)
            {
                return(HttpNotFound());
            }

            var model = CustomerEditModel.Create(customer);

            return(View("Save", model));
        }
예제 #2
0
        public IActionResult Index(string filter, int page = 1)
        {
            var filtedObj = new CustomerIndexFilterModel();

            if (!string.IsNullOrEmpty(filter))
            {
                filtedObj = JsonConvert.DeserializeObject <CustomerIndexFilterModel>(filter);
            }

            if (User.IsInRole(RoleNames.Employee))
            {
                filtedObj.CityId = CurrentUser?.City?.Id;
            }

            var typesHousings = _context.TypesHousing.ToList();

            var filterData = new CustomersExtension.FilterParams
            {
                CityId    = filtedObj.CityId,
                PriceTo   = filtedObj.MinCost,
                PriceFrom = filtedObj.MaxCost,
                Page      = page,
                //IsArchived = filtedObj.IsArchive,
                IsSiteAccessOnly = filtedObj.IsSiteAccessOnly
            };

            if (filtedObj.DistrictId.HasValue)
            {
                filterData.DistrictIds = new int[] { filtedObj.DistrictId.Value };
            }

            if (filtedObj.HousingTypeId.HasValue)
            {
                filterData.HouseTypeIds = new int[] { filtedObj.HousingTypeId.Value };
            }

            var applicationDbContext = _context.Clients
                                       .Include(c => c.City)
                                       .Include(c => c.CustomerAccount)
                                       .Include(c => c.Smses)
                                       .Include(c => c.User)
                                       .Include(c => c.TypesHousingToCustomers)
                                       .Include(x => x.DistrictToClients)
                                       .Include(x => x.Phones);

            var query = applicationDbContext.Where(x => CustomersExtension.Filter(filterData)(x));

            int totalPages;
            int totalRows;
            var dbItems = query.PagedResult(page, 20, x => x.User, false, out totalRows, out totalPages).ToList();

            ViewBag.TotalItems         = _context.Clients.Count();
            ViewBag.FilteredItemsCount = totalRows;

            var model = new CustomerIndexModel
            {
                Items       = dbItems.Select(x => CustomerEditModel.Create(x)).ToList(),
                Filters     = filtedObj,
                TotalPages  = totalPages,
                CurrentPage = page
            };

            return(View(model));
        }