Exemplo n.º 1
0
        public IHttpActionResult Post(DreamCreate dream)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateDreamService();

            if (!service.CreateDream(dream))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
Exemplo n.º 2
0
        public bool CreateDream(DreamCreate model)
        {
            var entity =
                new Dream()
            {
                OwnerId     = _userId,
                Title       = model.Title,
                Description = model.Description,
                Location    = model.Location,
                Takeaway    = model.Takeaway,
                Rating      = model.Rating
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Dreams.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }