コード例 #1
0
        public IActionResult Index(SortState sortState = SortState.AppealFullNameAsc, int page = 1)
        {
            AppealsFilterViewModel filter = HttpContext.Session.Get <AppealsFilterViewModel>(filterKey);

            if (filter == null)
            {
                filter = new AppealsFilterViewModel {
                    FullName = string.Empty, Organization = string.Empty, ShowName = string.Empty, GoalRequest = string.Empty
                };
                HttpContext.Session.Set(filterKey, filter);
            }

            string modelKey = $"{typeof(Appeal).Name}-{page}-{sortState}-{filter.FullName}-{filter.Organization}-{filter.ShowName}-{filter.GoalRequest}";

            if (!cache.TryGetValue(modelKey, out AppealsViewModel model))
            {
                model = new AppealsViewModel();

                IQueryable <Appeal> appeals = GetSortedEntities(sortState, filter);

                int count    = appeals.Count();
                int pageSize = 10;
                model.PageViewModel = new PageViewModel(page, count, pageSize);

                model.Entities               = count == 0 ? new List <Appeal>() : appeals.Skip((model.PageViewModel.CurrentPage - 1) * pageSize).Take(pageSize).ToList();
                model.SortViewModel          = new SortViewModel(sortState);
                model.AppealsFilterViewModel = filter;

                cache.Set(modelKey, model);
            }

            return(View(model));
        }
コード例 #2
0
        public async Task <IActionResult> Create(AppealsViewModel model)
        {
            model.SelectList = db.Shows.ToList();

            var show = db.Shows.FirstOrDefault(s => s.Name == model.ShowName);

            if (show == null)
            {
                ModelState.AddModelError(string.Empty, "Please select show from list.");
                return(View(model));
            }

            model.Entity.Show = new Show {
                Name = model.ShowName
            };
            if (ModelState.IsValid & CheckUniqueValues(model.Entity))
            {
                model.Entity.Show   = null;
                model.Entity.ShowId = show.ShowId;

                await db.Appeals.AddAsync(model.Entity);

                await db.SaveChangesAsync();

                cache.Clean();

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
コード例 #3
0
        public IActionResult Create(int page)
        {
            AppealsViewModel model = new AppealsViewModel();

            model.PageViewModel = new PageViewModel {
                CurrentPage = page
            };
            model.SelectList = db.Shows.ToList();

            return(View(model));
        }
コード例 #4
0
        public IActionResult Index(AppealsViewModel filterModel)
        {
            AppealsFilterViewModel filter = HttpContext.Session.Get <AppealsFilterViewModel>(filterKey);

            if (filter != null)
            {
                filter.FullName     = filterModel.AppealsFilterViewModel.FullName;
                filter.Organization = filterModel.AppealsFilterViewModel.Organization;
                filter.ShowName     = filterModel.AppealsFilterViewModel.ShowName;
                filter.GoalRequest  = filterModel.AppealsFilterViewModel.GoalRequest;

                HttpContext.Session.Remove(filterKey);
                HttpContext.Session.Set(filterKey, filter);
            }

            return(RedirectToAction("Index", new { page = 1 }));
        }
コード例 #5
0
        public async Task <IActionResult> Edit(AppealsViewModel model)
        {
            model.SelectList = db.Shows.ToList();

            var show = db.Shows.FirstOrDefault(s => s.Name == model.ShowName);

            if (show == null)
            {
                ModelState.AddModelError(string.Empty, "Please select show from list.");
                return(View(model));
            }

            model.Entity.Show = new Show {
                Name = model.ShowName
            };
            if (ModelState.IsValid & CheckUniqueValues(model.Entity))
            {
                model.Entity.Show = null;

                Appeal appeal = await db.Appeals.FindAsync(model.Entity.AppealId);

                if (appeal != null)
                {
                    appeal.FullName     = model.Entity.FullName;
                    appeal.Organization = model.Entity.Organization;
                    appeal.ShowId       = show.ShowId;
                    appeal.GoalRequest  = model.Entity.GoalRequest;

                    db.Appeals.Update(appeal);
                    await db.SaveChangesAsync();

                    cache.Clean();

                    return(RedirectToAction("Index", "Appeals", new { page = model.PageViewModel.CurrentPage }));
                }
                else
                {
                    return(NotFound());
                }
            }

            return(View(model));
        }
コード例 #6
0
        public async Task <IActionResult> Edit(int id, int page)
        {
            Appeal appeal = await db.Appeals.Include(a => a.Show).FirstOrDefaultAsync(a => a.AppealId == id);

            if (appeal != null)
            {
                AppealsViewModel model = new AppealsViewModel();
                model.PageViewModel = new PageViewModel {
                    CurrentPage = page
                };
                model.Entity     = appeal;
                model.SelectList = db.Shows.ToList();
                model.ShowName   = model.Entity.Show.Name;

                return(View(model));
            }

            return(NotFound());
        }
コード例 #7
0
        public async Task <IActionResult> Delete(AppealsViewModel model)
        {
            Appeal appeal = await db.Appeals.FindAsync(model.Entity.AppealId);

            if (appeal == null)
            {
                return(NotFound());
            }

            db.Appeals.Remove(appeal);
            await db.SaveChangesAsync();

            cache.Clean();

            model.DeleteViewModel = new DeleteViewModel {
                Message = "The entity was successfully deleted.", IsDeleted = true
            };

            return(View(model));
        }
コード例 #8
0
        public async Task <IActionResult> Delete(int id, int page)
        {
            Appeal appeal = await db.Appeals.FindAsync(id);

            if (appeal == null)
            {
                return(NotFound());
            }

            bool   deleteFlag = false;
            string message    = "Do you want to delete this entity";

            AppealsViewModel model = new AppealsViewModel();

            model.Entity        = appeal;
            model.PageViewModel = new PageViewModel {
                CurrentPage = page
            };
            model.DeleteViewModel = new DeleteViewModel {
                Message = message, IsDeleted = deleteFlag
            };

            return(View(model));
        }