public IEnumerable <ScheduledEvent> GetAll(EventCriteria criteria)
        {
            if (criteria.IncludePrivate || criteria.IncludePublic)
            {
                IEnumerable <ScheduledEvent> items = _items;
                if (!criteria.IncludePrivate)
                {
                    items = items.Where(i => i.IsPublic);
                }
                if (!criteria.IncludePublic)
                {
                    items = items.Where(i => !i.IsPublic);
                }

                if (criteria.BeginDate.HasValue)
                {
                    items = items.Where(i => i.StartDate >= criteria.BeginDate.Value);
                }
                if (criteria.EndDate.HasValue)
                {
                    items = items.Where(i => i.EndDate <= criteria.EndDate.Value);
                }

                foreach (var item in items)
                {
                    yield return(CloneEvent(item));
                }
            }
            ;
        }
Exemplo n.º 2
0
        public ActionResult Edit(model model, EventCriteria criteria)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var item = model.ToDomain();
                    item.Id = model.Id;

                    _database.Update(model.Id, item);

                    if (item.IsPublic == true)
                    {
                        return(RedirectToAction("Public"));
                    }
                    else
                    {
                        return(RedirectToAction("My"));
                    }
                } catch (Exception e)
                {
                    ModelState.AddModelError("", e.Message);
                };
            }
            ;

            return(View(model));
        }
Exemplo n.º 3
0
        public ActionResult Delete(int id, FormCollection collection)
        {
            EventCriteria criteria = new EventCriteria();

            criteria.IncludePublic  = true;
            criteria.IncludePrivate = true;

            ScheduledEvent scheduledEvent = (from m in DatabaseFactory.Database.GetAll(criteria)
                                             where m.Id == id
                                             select m).SingleOrDefault();

            if (scheduledEvent == null)
            {
                return(new HttpNotFoundResult("Event not found."));
            }

            DatabaseFactory.Database.Remove(id);

            if (scheduledEvent.IsPublic)
            {
                return(RedirectToAction("Public", "Event"));
            }

            return(RedirectToAction("My", "Event"));
        }
Exemplo n.º 4
0
        // Get details of an event
        public ActionResult Details(int id)
        {
            EventCriteria criteria = new EventCriteria();

            criteria.IncludePublic  = true;
            criteria.IncludePrivate = true;

            ScheduledEvent scheduledEvent = (from m in DatabaseFactory.Database.GetAll(criteria)
                                             where m.Id == id
                                             select m).SingleOrDefault();

            if (scheduledEvent == null)
            {
                return(new HttpNotFoundResult("Event not found."));
            }

            ScheduledEventModel model = new ScheduledEventModel();

            model.Description = scheduledEvent.Description;
            model.EndDate     = scheduledEvent.EndDate;
            model.Id          = scheduledEvent.Id;
            model.Name        = scheduledEvent.Name;
            model.StartDate   = scheduledEvent.StartDate;
            model.IsPublic    = scheduledEvent.IsPublic;

            return(View(model));
        }
Exemplo n.º 5
0
        // Get only public events
        public ActionResult Public()
        {
            EventCriteria criteria = new EventCriteria();

            criteria.IncludePublic  = true;
            criteria.IncludePrivate = false;

            List <ScheduledEventModel> models = new List <ScheduledEventModel>();

            foreach (ScheduledEvent scheduledEvent in DatabaseFactory.Database.GetAll(criteria))
            {
                ScheduledEventModel model = new ScheduledEventModel();
                model.Description = scheduledEvent.Description;
                model.EndDate     = scheduledEvent.EndDate;
                model.Id          = scheduledEvent.Id;
                model.Name        = scheduledEvent.Name;
                model.StartDate   = scheduledEvent.StartDate;
                model.IsPublic    = scheduledEvent.IsPublic;

                if (DateTime.Now <= model.EndDate)
                {
                    models.Add(model);
                }
            }

            return(View(models.OrderBy(m => m.StartDate)));
        }
Exemplo n.º 6
0
    EventCriteria GenerateEventCriteria(JsonData jsonData)
    {
        EventCriteria criteria = new EventCriteria();

        criteria.criteriaVariable = jsonData["criteriaVariable"].ToString();
        criteria.criteriaNumber   = Convert.ToInt32(jsonData["criteriaNumber"].ToString());

        switch (jsonData["criteriaType"].ToString())
        {
        case "AtLeast":
            criteria.criteriaType = CriteriaType.AtLeast;
            break;

        case "AtMost":
            criteria.criteriaType = CriteriaType.AtMost;
            break;

        case "Exactly":
            criteria.criteriaType = CriteriaType.Exactly;
            break;

        case "Roughly":
            criteria.criteriaType = CriteriaType.Roughly;
            break;

        default:
            Debug.LogError(string.Format("Invalid criteriaType {0}! Json data: {1}",
                                         criteria.criteriaType, jsonData));
            break;
        }

        return(criteria);
    }
Exemplo n.º 7
0
        public ActionResult Index(EventCriteria criteria)
        {
            var items = _database.GetAll(criteria);

            return(View(items.Select(i => new model(i))));
            //return View("Index");
        }
Exemplo n.º 8
0
        private static ComparisonSource Get(InputCriteria input, EventCriteria e)
        {
            // cant both be null and can't both be not null.
            Contract.Requires(e != EventCriteria.None || input != InputCriteria.None);
            Contract.Requires(e == EventCriteria.None || input == InputCriteria.None);

            return(e == EventCriteria.None ? ComparisonSource.Input : ComparisonSource.Event);
        }
Exemplo n.º 9
0
        public ActionResult Delete(int id)
        {
            var criteria = new EventCriteria();

            criteria.IncludePrivate = true;
            criteria.IncludePublic  = true;
            var item = _database.GetAll(criteria).FirstOrDefault(i => i.Id == id);

            return(View(new EventModel(item)));
        }
Exemplo n.º 10
0
        private TestExpressionInfo(EventCriteria eventCriteria, InputCriteria globalCriteria, Condition condition, object value)
        {
            Contract.Requires(value != null);

            Event = eventCriteria;
            Input = globalCriteria;
            Condition = condition;
            _value = value;
            Source = Get(globalCriteria, eventCriteria);
        }
Exemplo n.º 11
0
        private TestExpressionInfo(EventCriteria eventCriteria, InputCriteria globalCriteria, Condition condition, object value)
        {
            Contract.Requires(value != null);

            Event     = eventCriteria;
            Input     = globalCriteria;
            Condition = condition;
            _value    = value;
            Source    = Get(globalCriteria, eventCriteria);
        }
        public ActionResult PublicEvents()
        {
            EventCriteria eventCriteria = default(EventCriteria);

            eventCriteria.IncludePublic  = true;
            eventCriteria.IncludePrivate = false;

            var events = DatabaseFactory._database.GetAll(eventCriteria);

            return(View(events.Select(i => new EventModel(i))));
        }
Exemplo n.º 13
0
        public ActionResult Public()
        {
            EventCriteria ec = default(EventCriteria);

            ec.IncludePrivate = false;
            ec.IncludePublic  = true;
            var events = DatabaseFactory.Database.GetAll(ec);

            return(View(events.Select(e => new EventModel(e))
                        .Where(e => e.EndDate > DateTime.Now)
                        .OrderBy(e => e.StartDate)));
        }
Exemplo n.º 14
0
        public ActionResult Public()
        {
            var criteria = new EventCriteria();

            criteria.IncludePublic = true;

            var items = from i in _database.GetAll(criteria)
                        where i.IsPublic == true && i.EndDate >= DateTime.Today
                        orderby i.StartDate
                        select i;

            return(View(items.Select(i => new model(i))));
        }
Exemplo n.º 15
0
        public ActionResult Multi()
        {
            if (ModelState.IsValid)
            {
                string content = Request["List"];
                content = content.Replace("\"", "");// 去掉excel导出时多余的双引号
                //C#实现字符串按多个字符采用Split方法分割  https://www.cnblogs.com/codingsilence/archive/2010/09/29/2146603.html
                List <string> t = Regex.Split(content, "#\r\n", RegexOptions.IgnoreCase).ToList();
                ViewBag.Content      = t;
                ViewBag.Count        = t.Count;
                ViewBag.FaultCount   = 0;
                ViewBag.SuccessCount = 0;
                //int order = 0;
                //if (db.Events.Count() > 0)
                //{
                //    order = db.Events.Max(record => record.MenuOrder);
                //}


                foreach (string item in t)
                {
                    if (!string.IsNullOrEmpty(item))
                    {
                        try
                        {
                            EventCriteria criteria = new EventCriteria();


                            string eventName = item.Split('\t')[0];
                            criteria.EventId  = db.Events.Where(c => c.Name == eventName).First().Id;
                            criteria.Title    = item.Split('\t')[1];
                            criteria.MinScore = Convert.ToInt32(item.Split('\t')[2]);
                            criteria.MaxScore = Convert.ToInt32(item.Split('\t')[3]);
                            criteria.Note     = item.Split('\t')[4];
                            criteria.SetName  = item.Split('\t')[5];
                            db.EventCriterias.Add(criteria);
                        }
                        catch
                        {
                            ViewBag.FaultCount++;
                        }
                    }
                }
                ViewBag.SuccessCount = db.SaveChanges();
                return(View());
            }


            return(View());
        }
        public ActionResult Public()
        {
            var criteria = new EventCriteria()
            {
                IncludePrivate = false,
                IncludePublic  = true,
                BeginDate      = DateTime.MinValue,
            };

            var results        = DatabaseFactory._database.GetAll(criteria);
            var filteredEvents = filterResults(results);

            return(View(filteredEvents.Select(i => new EventModel(i))));
        }
Exemplo n.º 17
0
        public ActionResult Public()
        {
            var criteria = new EventCriteria();

            criteria.IncludePrivate = false;
            criteria.IncludePublic  = true;
            criteria.BeginDate      = DateTime.Today;

            var items = from i in _database.GetAll(criteria)
                        orderby i.StartDate
                        select i;

            return(View(items.Select(i => new EventModel(i))));
        }
Exemplo n.º 18
0
        public void ToDictionary_ReturnsCorrectDictionary()
        {
            // Arrange
            var sut = new EventCriteria
            {
                Name           = "TestName999",
                NameStartsWith = "TestStartName0",
                ModifiedSince  = new DateTime(2015, 1, 15, 8, 59, 21),
                Comics         = new List <int>(),
                Series         = new List <int>(),
                Characters     = new List <int> {
                    1, 2, 3
                },
                Stories = new List <int> {
                    0
                },
                Creators = new List <int> {
                    11111, 558, 123
                },
                OrderBy = new List <EventOrder> {
                    EventOrder.StartDateAscending, EventOrder.ModifiedDescending
                }
            };

            // Act
            var result = sut.ToDictionary();

            // Assert
            Assert.AreEqual(7, result.Count);

            Assert.Contains(ParameterName, result.Keys);
            Assert.Contains(ParameterNameStartsWith, result.Keys);
            Assert.Contains(ParameterModifiedSince, result.Keys);
            Assert.Contains(ParameterCharacters, result.Keys);
            Assert.Contains(ParameterCreators, result.Keys);
            Assert.Contains(ParameterStories, result.Keys);
            Assert.Contains(ParameterOrderBy, result.Keys);

            Assert.IsFalse(result.Keys.Contains(ParameterEvents));
            Assert.IsFalse(result.Keys.Contains(ParameterSeries));

            Assert.AreEqual(sut.Name, result[ParameterName]);
            Assert.AreEqual(sut.NameStartsWith, result[ParameterNameStartsWith]);
            Assert.AreEqual(sut.ModifiedSince.Value.ToString(ParameterDateTimeFormat), result[ParameterModifiedSince]);
            Assert.AreEqual(string.Join(ParameterListSeparator, sut.Characters), result[ParameterCharacters]);
            Assert.AreEqual(string.Join(ParameterListSeparator, sut.Creators), result[ParameterCreators]);
            Assert.AreEqual(string.Join(ParameterListSeparator, sut.Stories), result[ParameterStories]);
            Assert.AreEqual(string.Join(ParameterListSeparator, sut.OrderBy.Select(o => o.GetStringValue())), result[ParameterOrderBy]);
        }
Exemplo n.º 19
0
        public ActionResult Details(int id)
        {
            try
            {
                var criteria = new EventCriteria();
                criteria.IncludePrivate = true;
                criteria.IncludePublic  = true;
                var item = _database.GetAll(criteria).FirstOrDefault(i => i.Id == id);

                return(View(new EventModel(item)));
            } catch (Exception e)
            {
                ModelState.AddModelError("", e.Message);
                return(HttpNotFound());
            }
        }
Exemplo n.º 20
0
        public ActionResult Delete(model model, EventCriteria criteria)
        {
            try
            {
                var item = model.ToDomain();
                item.Id = model.Id;

                _database.Remove(model.Id);

                if (model.IsPublic == true)
                {
                    return(RedirectToAction("Public"));
                }
                else
                {
                    return(RedirectToAction("My"));
                }
            } catch (Exception e)
            {
                ModelState.AddModelError("", e.Message);
            }

            return(View(model));
        }
Exemplo n.º 21
0
 public TestExpressionInfo(EventCriteria criteria, Condition condition, object value) :
     this(criteria, InputCriteria.None, condition, value)
 {
     Contract.Requires(value != null);
 }
Exemplo n.º 22
0
        private static ComparisonSource Get(InputCriteria input, EventCriteria e)
        {
            // cant both be null and can't both be not null.
            Contract.Requires(e != EventCriteria.None || input != InputCriteria.None);
            Contract.Requires(e == EventCriteria.None || input == InputCriteria.None);

            return e == EventCriteria.None ? ComparisonSource.Input : ComparisonSource.Event;
        }
Exemplo n.º 23
0
 public TestExpressionInfo(EventCriteria criteria, Condition condition, object value)
     : this(criteria, InputCriteria.None, condition, value)
 {
     Contract.Requires(value != null);
 }
Exemplo n.º 24
0
 /// <summary>
 ///     Fetches a list of events, with optional filters
 /// </summary>
 /// <param name="limit">Limit the result set to the specified number of resources.</param>
 /// <param name="offset">Skip the specified number of resources in the result set.</param>
 /// <param name="criteria">Filter the result set by the specified criteria.</param>
 /// <returns></returns>
 public async Task <Response <List <Event> > > GetAllEventsAsync(int?limit = null, int?offset = null,
                                                                 EventCriteria criteria = null)
 {
     return(await _eventService.GetAllAsync(limit, offset, criteria));
 }
Exemplo n.º 25
0
 /// <summary>
 ///     Fetches a list of events in which the specified story appears, with optional filters
 /// </summary>
 /// <param name="storyId">The story ID.</param>
 /// <param name="limit">Limit the result set to the specified number of resources.</param>
 /// <param name="offset">Skip the specified number of resources in the result set.</param>
 /// <param name="criteria">Filter the result set by the specified criteria.</param>
 /// <returns></returns>
 public async Task <Response <List <Event> > > GetStoryEventsAsync(int storyId, int?limit = null, int?offset = null,
                                                                   EventCriteria criteria = null)
 {
     return(await _eventService.GetByStoryAsync(storyId, limit, offset, criteria));
 }
Exemplo n.º 26
0
 /// <summary>
 ///     Fetches a list of events featuring the work of a specific creator, with optional filters
 /// </summary>
 /// <param name="creatorId">The creator ID.</param>
 /// <param name="limit">Limit the result set to the specified number of resources.</param>
 /// <param name="offset">Skip the specified number of resources in the result set.</param>
 /// <param name="criteria">Filter the result set by the specified criteria.</param>
 /// <returns></returns>
 public async Task <Response <List <Event> > > GetCreatorEventsAsync(int creatorId, int?limit = null,
                                                                     int?offset = null, EventCriteria criteria = null)
 {
     return(await _eventService.GetByCreatorAsync(creatorId, limit, offset, criteria));
 }
Exemplo n.º 27
0
    EventCriteria GenerateEventCriteria(JsonData jsonData)
    {
        EventCriteria criteria = new EventCriteria();
        criteria.criteriaVariable = jsonData["criteriaVariable"].ToString();
        criteria.criteriaNumber = Convert.ToInt32(jsonData["criteriaNumber"].ToString());
        
        switch (jsonData["criteriaType"].ToString())
        {
            case "AtLeast":
                criteria.criteriaType = CriteriaType.AtLeast;
                break;
            case "AtMost":
                criteria.criteriaType = CriteriaType.AtMost;
                break;
            case "Exactly":
                criteria.criteriaType = CriteriaType.Exactly;
                break;
            case "Roughly":
                criteria.criteriaType = CriteriaType.Roughly;
                break;
            default:
                Debug.LogError(string.Format("Invalid criteriaType {0}! Json data: {1}", 
                                             criteria.criteriaType, jsonData));
                break;
        }

        return criteria;
    }
Exemplo n.º 28
0
 internal async Task <Response <List <Event> > > GetAllAsync(int?limit = null, int?offset = null, EventCriteria criteria = null)
 {
     return(await GetList(UrlSuffixAllEvents, limit, offset, criteria));
 }
Exemplo n.º 29
0
 internal async Task <Response <List <Event> > > GetByStoryAsync(int storyId, int?limit = null, int?offset = null, EventCriteria criteria = null)
 {
     return(await GetList(string.Format(UrlSuffixStoryEvents, storyId), limit, offset, criteria));
 }
Exemplo n.º 30
0
 internal async Task <Response <List <Event> > > GetByCharacterAsync(int characterId, int?limit = null, int?offset = null, EventCriteria criteria = null)
 {
     return(await GetList(string.Format(UrlSuffixCharacterEvents, characterId), limit, offset, criteria));
 }
Exemplo n.º 31
0
 public IEnumerable <ScheduledEvent> GetAll(EventCriteria criteria)
 {
     throw new NotImplementedException();
 }
        public Task <IAsyncEnumerable <RecordedEvent> > Get(IEventCriteria criteria)
        {
            EventCriteria c = (EventCriteria)criteria;

            return(GetAll(c.Filter));
        }