示例#1
0
        async public Task <IActionResult> Post(WebApi.Gift inputGift)
        {
            if (inputGift.Id > 0)
            {
                return(BadRequest("trying to post a new gift with positive id"));
            }
            var gift = inputGift.ToDatabase();

            gift.Id = 0;
            var userId = await UserAccessor.GetCurrentIndividualId();

            gift.OwnerId = userId;
            var result = DbContext.Gifts.Add(gift);
            await DbContext.SaveChangesAsync();

            return(CreatedAtRoute("GetGift", new { controller = "GiftApi", id = result.Entity.Id }, result.Entity.ToWeb()));
        }
示例#2
0
        async public Task <IActionResult> Put(int id, WebApi.Gift inputGift)
        {
            if (inputGift == null)
            {
                return(BadRequest("gift not provided"));
            }
            var storedGift = await FetchGift(id);

            if (storedGift == null)
            {
                return(Forbid());
            }
            inputGift.Id = id;
            DbContext.Entry(storedGift).CurrentValues.SetValues(inputGift.ToDatabase());
            await DbContext.SaveChangesAsync();

            return(Ok(inputGift));
        }