コード例 #1
0
 public async Task<IHttpActionResult> postBid(Bid bid)
 {
     if (!ModelState.IsValid)
     {
         return BadRequest(ModelState);
     }
     if (!(HttpContext.Current.Request.IsAuthenticated))
     {
         return BadRequest();
         //return BadRequest("you must be logged in post comment");
     }
     bid.time = DateTime.UtcNow;
     bid.postedBy = User.Identity.GetUserId();
     db.Bids.Add(bid);
     await db.SaveChangesAsync();
     var ret = db.Bids.Where(x => x.Id == bid.Id).Select(x => new
     {
         price = x.price,
         postedById = x.postedBy,
         postedByName = x.AspNetUser.UserName,
         time = x.time,
         id = x.Id,
     }).FirstOrDefault();
     return Ok(ret);
     // return CreatedAtRoute("DefaultApi", new { id = comment.Id }, comment);
 }
コード例 #2
0
        public async Task<IHttpActionResult> UpdateBid(Bid bid)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest();
            }
            db.Entry(bid).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }
            return StatusCode(HttpStatusCode.NoContent);
        }
コード例 #3
0
 public async Task<IHttpActionResult> postBid(Bid bid)
 {
     if (!ModelState.IsValid)
     {
         return BadRequest(ModelState);
     }
     if (!(HttpContext.Current.Request.IsAuthenticated))
     {
         return BadRequest("not login");
     }
     bid.postedBy = User.Identity.GetUserId();
     var BidAlreadyPlaced = await db.Bids.FirstOrDefaultAsync(x => x.adId.Equals(bid.adId) && x.postedBy.Equals(bid.postedBy));
     if (BidAlreadyPlaced != null)
     {
         BidAlreadyPlaced.price = bid.price;
         //db.Bids.Add(BidAlreadyPlaced);
     }
     else
     {
         bid.time = DateTime.UtcNow;
         db.Bids.Add(bid);
     }
     
     await db.SaveChangesAsync();
     var ret = db.Bids.Where(x => x.Id == bid.Id).Select(x => new
     {
         price = x.price,
         postedById = x.postedBy,
         postedByName = x.AspNetUser.Email,
         time = x.time,
         id = x.Id,
     }).FirstOrDefault();
     return Ok(ret);
 }