public IHttpActionResult PutIngNotiPost(int id, IngNotiPost ingNotiPost) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != ingNotiPost.IngNotiPostId) { return BadRequest(); } db.Entry(ingNotiPost).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!IngNotiPostExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult PostIngNotiPost(IngNotiPostDTO ingNotiPostDTO) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var notification = db.IngNotifications.Where(x => x.IngNotificationId == ingNotiPostDTO.IngNotificationId).FirstOrDefault(); IngNotiPost ingNotiPost = new IngNotiPost() { UnitCost = ingNotiPostDTO.UnitCost, DateExpired = ingNotiPostDTO.DateExpired, ProviderId = ((ClaimsIdentity)User.Identity).GetUserId(), CreatedBy = ((ClaimsIdentity)User.Identity).GetUserId(), CreatedDate = DateTime.Now, ModifiedBy = ((ClaimsIdentity)User.Identity).GetUserId(), ModifiedDate = DateTime.Now, IsActive = true, IngNotification = notification, RestaurantId = notification.RestaurantId }; try { db.IngNotiPosts.Add(ingNotiPost); db.SaveChanges(); } catch (Exception e) { ErrorSignal.FromCurrentContext().Raise(e); throw new Exception("There was a problem saving this record: " + e.Message); } return CreatedAtRoute("DefaultApi", new { id = ingNotiPost.IngNotiPostId }, ingNotiPost); }