public JsonResult Get(EventFilterViewModel filter) { using (var context = new AppDbContext()) { var query = context.Events.AsQueryable(); if (filter.id.HasValue) { query = query.Where(p => p.Id == filter.id); } else if (filter.since.HasValue) { query = query.Where(x => x.Date >= filter.since); } else if (filter.until.HasValue) { query = query.Where(x => x.Date <= filter.until); } var agendaEvent = query.Select(x => new { x.Id, x.Description, x.Date, x.Start, x.End, x.Color, x.AllDay }).ToArray(); return(Json(agendaEvent, JsonRequestBehavior.AllowGet)); } }
public async Task <IActionResult> Index(string eventCategory, string searchString) { // get list of events var events = from l in _context.Events select l; // Use LINQ to get list of types IQueryable <string> categoryQuery = from t in _context.Events orderby t.Category select t.Category; // check for name search string if (!string.IsNullOrEmpty(searchString)) { events = events.Where(s => s.Title.Contains(searchString)); } // check for industry selection if (!string.IsNullOrEmpty(eventCategory)) { events = events.Where(x => x.Category == eventCategory); } var eventFilterVM = new EventFilterViewModel { Events = await events.ToListAsync(), Categories = new SelectList(await categoryQuery.Distinct().ToListAsync()), }; return(View(eventFilterVM)); }
public IEnumerable <EventDTO> EventsForAdmin(EventFilterViewModel model, out int count) { var events = Db.EventRepository.Get("Photo,Owner.Photo,City.Country,Categories.Category,Visitors"); events = !string.IsNullOrEmpty(model.KeyWord) ? events.Where(x => x.Title.Contains(model.KeyWord) || x.Description.Contains(model.KeyWord) || x.City.Name.Contains(model.KeyWord) || x.City.Country.Name.Contains(model.KeyWord)) : events; events = (model.DateFrom != DateTime.MinValue) ? events.Where(x => x.DateFrom >= model.DateFrom) : events; events = (model.DateTo != DateTime.MinValue) ? events.Where(x => x.DateTo <= model.DateTo) : events; events = (model.Blocked) ? events.Where(x => x.IsBlocked == model.Blocked) : events; events = (model.Unblocked) ? events.Where(x => x.IsBlocked == !(model.Unblocked)) : events; if (model.Categories != null) { var categoryIds = model.Categories.Split(",") .Select(x => (Guid.TryParse(x, out Guid item)) ? item : Guid.Empty) .Where(x => x != Guid.Empty) .ToList(); events = events.Where(x => x.Categories.Any(category => categoryIds.Contains(category.CategoryId))); } count = events.Count(); return(_mapper.Map <IEnumerable <EventDTO> >(events.OrderBy(x => x.DateFrom).Skip((model.Page - 1) * model.PageSize).Take(model.PageSize))); }
public IActionResult All([FromQuery] EventFilterViewModel filter) { filter.PageSize = 6; try { var viewModel = new IndexViewModel <EventPreviewDto> { Items = _mapper.Map <IEnumerable <EventPreviewDto> >(_eventService.Events(filter, out int count)), PageViewModel = new PageViewModel(count, filter.Page, filter.PageSize) }; return(Ok(viewModel)); } catch (ArgumentOutOfRangeException) { return(BadRequest()); } }
public async Task <IActionResult> GetEventsPageAsync( [FromQuery] EventFilterViewModel eventFilter) { var validator = new PageRequestViewModelValidator(); ValidationResult validationResult = validator.Validate(eventFilter); if (!validationResult.IsValid) { return(BadRequest(new ErrorResponseFormat( validationResult.Errors.First().ErrorMessage))); } string id = User.FindFirst(JwtRegisteredClaimNames.Jti).Value; UserModel user = await _accountService.GetUserByIdAsync(new Guid(id)); var result = await _service.GetEventsPageAsync( _mapper.Map <EventFilterModel>(eventFilter), _mapper.Map <UserModel>(user)); return(Ok(_mapper.Map <PageViewModel <EventViewModel> >(result))); }
public EventFilterViewModel GetEventData(int EventId, int Userid, int OrganizationId) { DbDataReader reader = null; EventFilterViewModel model = new EventFilterViewModel(); try { RepositoryContext.Database.Initialize(force: false); var cmd = RepositoryContext.Database.Connection.CreateCommand(); cmd.CommandText = "SP_GetEventData"; cmd.CommandType = System.Data.CommandType.StoredProcedure; SqlParameter parm1 = new SqlParameter(); parm1.ParameterName = "@EventId"; parm1.Value = EventId; parm1.SqlDbType = SqlDbType.Int; SqlParameter parm5 = new SqlParameter(); parm5.ParameterName = "@OrganizationId"; parm5.Value = OrganizationId; parm5.SqlDbType = SqlDbType.Int; cmd.Parameters.Add(parm1); cmd.Parameters.Add(parm5); if (RepositoryContext.Database.Connection.State == ConnectionState.Closed) { RepositoryContext.Database.Connection.Open(); } reader = cmd.ExecuteReader(); model.EventDataModel = (from n in ((IObjectContextAdapter)RepositoryContext) .ObjectContext.Translate <EventDataModel>(reader) select n).ToList(); reader.NextResult(); model.EventAttendeeDataModel = (from n in ((IObjectContextAdapter)RepositoryContext) .ObjectContext.Translate <EventAttendeeDataModel>(reader) select n).ToList(); reader.NextResult(); model.ActionDataModel = (from n in ((IObjectContextAdapter)RepositoryContext) .ObjectContext.Translate <ActionDataModel>(reader) select n).ToList(); reader.NextResult(); model.AgendaDataModel = (from n in ((IObjectContextAdapter)RepositoryContext) .ObjectContext.Translate <AgendaDataModel>(reader) select n).ToList(); if (model.ActionDataModel != null && model.ActionDataModel.Any()) { foreach (ActionDataModel actionModel in model.ActionDataModel) { var data = this._IActionResponsiblePersonRepository.GetByActionId(actionModel.ActionID, Userid, OrganizationId); actionModel.ActionResponsiblePersonDataModel = Mapper.Map <List <ActionResponsiblePerson>, List <ActionResponsiblePersonDataModel> >(data); } } } finally { if (reader != null) { if (!reader.IsClosed) { reader.Close(); } } if (RepositoryContext.Database.Connection.State == ConnectionState.Open) { RepositoryContext.Database.Connection.Close(); RepositoryContext.Database.Connection.Dispose(); } } return(model); }