public PartialViewResult GetPartial(DateTime?startDate, DateTime?endDate)
        {
            var historyIndexViewModel = new HistoryIndexViewModel
            {
                StartDate = startDate,
                EndDate   = endDate
            };

            return(PartialView("_Details", historyIndexViewModel));
        }
        public ViewResult Index()
        {
            var currentYearStart      = new DateTime(DateTime.Now.Year, 1, 1);
            var historyIndexViewModel = new HistoryIndexViewModel
            {
                StartDate = currentYearStart
            };

            ViewBag.Title = "History";
            return(View(historyIndexViewModel));
        }
Exemplo n.º 3
0
        // GET: Histories/5     - history for all or an item or a person
        // id = item, peopleId = person
        public async Task <ActionResult> Index(int?id, int?peopleId, int page = 1)
        {
            List <History> items;
            var            model = new HistoryIndexViewModel();

            if (id == null)
            {
                //entire history
                if (peopleId == null)
                {
                    items = await _db.Histories.OrderByDescending(h => h.Date).ToListAsync();
                }
                //history for a person
                else
                {
                    var person = _db.Persons.Find(peopleId);
                    if (person == null)
                    {
                        return(HttpNotFound());
                    }
                    items = await _db.Histories.Where(h => h.WhoTook.Id == peopleId && !h.Recieved).OrderByDescending(h => h.Date).ToListAsync();

                    model.PersonName   = person.FullName;
                    model.PersonId     = peopleId;
                    model.GrantHistory = true;
                }
                model.MonthGrant   = 0;
                model.MonthRecieve = 0;
            }
            else
            {
                //history for an item
                var item = _db.Items.Find(id);
                if (item == null)
                {
                    return(HttpNotFound());
                }
                items = await _db.Histories.Where(h => h.Item.Id == id).OrderByDescending(h => h.Date).ToListAsync();

                model.ItemName     = item.Name;
                model.ItemId       = id;
                model.MonthGrant   = StaticData.CountItemGrant((int)id, 30);
                model.MonthRecieve = StaticData.CountRecieve((int)id, 30);
            }
            var pager = new Pager(items.Count, page, 18);

            model.Histories = items.Skip((pager.CurrentPage - 1) * pager.PageSize).Take(pager.PageSize);
            model.Pager     = pager;
            return(View(model));
        }
Exemplo n.º 4
0
        // --------------
        // Index
        // --------------

        public async Task <IActionResult> Index(int id)
        {
            // Get history point
            var history = await _entityHistoryStore.GetByIdAsync(id);

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

            // Get entity for history point
            var entity = await _entityStore.GetByIdAsync(history.EntityId);

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

            // Ensure we have permission
            if (!await _authorizationService.AuthorizeAsync(HttpContext.User,
                                                            entity.CategoryId, history.EntityReplyId > 0
                    ? Permissions.viewReplyHistory
                    : Permissions.ViewEntityHistory))
            {
                return(Unauthorized());
            }

            // Get previous history
            var previousHistory = await _entityHistoryStore.QueryAsync()
                                  .Take(1, false)
                                  .Select <EntityHistoryQueryParams>(q =>
            {
                q.Id.LessThan(history.Id);
                q.EntityId.Equals(history.EntityId);
                q.EntityReplyId.Equals(history.EntityReplyId);
            })
                                  .OrderBy("Id", OrderBy.Desc)
                                  .ToList();

            // Get newest / most recent history entry
            var latestHistory = await _entityHistoryStore.QueryAsync()
                                .Take(1, false)
                                .Select <EntityHistoryQueryParams>(q =>
            {
                q.EntityId.Equals(history.EntityId);
                q.EntityReplyId.Equals(history.EntityReplyId);
            })
                                .OrderBy("Id", OrderBy.Desc)
                                .ToList();

            // Compare previous to current
            var html = history.Html;

            if (previousHistory?.Data != null)
            {
                html = PrepareDifAsync(previousHistory.Data[0].Html, history.Html);
            }

            // Build model
            var viewModel = new HistoryIndexViewModel()
            {
                History       = history,
                LatestHistory = latestHistory?.Data[0],
                Html          = html
            };

            return(View(viewModel));
        }