Exemplo n.º 1
0
        // POST: api/donations
        public IHttpActionResult Post(Donation item)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Not a valid model"));
            }

            //if it is not working create  a wish instance
            Donation donation = new Donation()
            {
                //ID = item.ID,
                Date   = item.Date,
                Sum    = item.Sum,
                UserId = User.Identity.GetUserId(),
                WishId = item.WishId,
            };

            service.Add(donation);
            service.Commit();

            //update the wish
            Wish wish = wishService.GetById(item.WishId);

            wish.FundRaised += item.Sum;
            wishService.Update(wish);
            wishService.Commit();

            return(Ok());
        }
        public HttpResponseMessage Create(HttpRequestMessage request, DonationViewModel controPanelVM)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                if (!ModelState.IsValid)
                {
                    response = request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    Donation newDonation = new Donation();
                    newDonation.UpdateDonation(controPanelVM);
                    newDonation.CreatedDate = DateTime.Now;
                    newDonation.CreatedBy = User.Identity.Name;
                    var page = _donationService.Add(newDonation);
                    _donationService.Save();
                    response = request.CreateResponse(HttpStatusCode.Created, page);
                }
                return response;
            }));
        }