Ejemplo n.º 1
0
        public IHttpActionResult Add(NewStoryVM story)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            IHttpActionResult response;
            HttpResponseMessage responseMsg;

            try
            {
                string creatorId = Microsoft.AspNet.Identity.IdentityExtensions.GetUserId(RequestContext.Principal.Identity);
                story.CreatorId = creatorId;
                story.DateMade = DateTime.Now;
                story.LastEdit = story.DateMade;
                if (story.Date == null)
                    story.Date = story.DateMade;

                StoryVM s = _mngr.newStory(story);
                responseMsg = _helper.CreateCustomResponseMsg(s, HttpStatusCode.OK);

            }
            catch (Exception e)
            {
                responseMsg = _errHelper.CreateCustomResponseMsg(new HttpError(e.Message), HttpStatusCode.BadRequest);
            }
            response = ResponseMessage(responseMsg);

            return response;
        }
Ejemplo n.º 2
0
        public StoryVM newStory(NewStoryVM story)
        {
            var user = getUser(story.CreatorId);
            var trip = getTrip(story.TripId);

            var s = _db.Stories.Add(new Story {
                Title = story.Title,
                CreatorId = user.Id,
                TripId = trip.Id,
                DateMade = story.DateMade,
                Date = story.Date,
                LastEdit = story.LastEdit,
                Text = story.Text,
                Rating = 0,
                Rates = 0
            });

            _db.SaveChanges();

            return new StoryVM {
                Title = story.Title,
                Id = s.Id,
                LastEdit = s.LastEdit,
                Date = s.Date,
                DateMade = s.DateMade,
                CreatorId = s.CreatorId,
                CreatorUsername = user.UserName,
                Text = s.Text,
                Rating = s.Rating,
                Rates = s.Rates,
                TripId = s.TripId.Value
            };
        }