public ActionResult Update(EventRest @event)
        {
            if ([email protected])
            {
                Logger.I("Attempt to update transaction without id");
                Response.StatusCode = 400;
                return(Json(new { Field = "Id", Message = "Missing Id" }));
            }

            using (var db = DbFactory.Open())
            {
                JsonResult nameAssertResult;
                if (!AssertNameUnique(@event, db, out nameAssertResult))
                {
                    return(nameAssertResult);
                }

                var dlEvent = EventFromRest(@event, db);
                db.Session.Update(dlEvent);
                db.Commit();

                var response = new EventRest(dlEvent);
                Logger.I("Updated event {0}", response.ToJson());
                return(Json(response));
            }
        }
Esempio n. 2
0
        public async Task <IList <Event> > GetAsync(int cityId, string search = "", int skip = 0, int take = Constants.Pagination.Take)
        {
            var service = new EventRest();
            var items   = await service.GetAsync(cityId, search, skip, take);

            return(items.OrderBy(o => o.Name).ToList());
        }
Esempio n. 3
0
        public async Task <Event> GetAsync(Guid eventId)
        {
            var service = new EventRest();
            var item    = await service.GetAsync(eventId);

            return(item);
        }
        private Event EventFromRest(EventRest source, Db db)
        {
            var target = new Event();

            if (source.Id.HasValue)
            {
                target.Id = source.Id.Value;
            }
            target.Name        = source.Name;
            target.StartDate   = JsonDate.Parse(source.StartDate);
            target.Description = source.Description ?? "";
            target.Bros.AddRange(source.Bros.Load <Bro>(db));
            return(target);
        }
        private bool AssertNameUnique(EventRest @event, Db db, out JsonResult result)
        {
            result = null;
            bool conflict = @event.Id.HasValue
                ? db.Query <Event>().Any(e => e.Id != @event.Id.Value && e.Name == @event.Name)
                : db.Query <Event>().Any(e => e.Name == @event.Name);

            if (!conflict)
            {
                return(true);
            }

            Logger.E("Attempt to create duplicate event {0}", @event.Name);
            result = Json(new { Field = "Name", Message = "Event with name {0} already exists.".F(@event.Name) });
            Response.StatusCode = 400;
            return(false);
        }
        public ActionResult Create(EventRest @event)
        {
            using (var db = DbFactory.Open())
            {
                JsonResult nameAssertResult;
                if (!AssertNameUnique(@event, db, out nameAssertResult))
                {
                    return(nameAssertResult);
                }

                var dlEvent = EventFromRest(@event, db);
                db.Session.Save(dlEvent);
                db.Commit();

                var response = new EventRest(dlEvent);
                Logger.I("Created event {0}", response.ToJson());
                return(Json(response));
            }
        }