public IHttpActionResult PutOwnerProductMapping(int id, OwnerProductMapping ownerProductMapping) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != ownerProductMapping.Id) { return(BadRequest()); } db.Entry(ownerProductMapping).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!OwnerProductMappingExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult GetOwnerProductMapping(int id) { OwnerProductMapping ownerProductMapping = db.AddedProducts.Find(id); if (ownerProductMapping == null) { return(NotFound()); } return(Ok(ownerProductMapping)); }
public IHttpActionResult DeleteOwnerProductMapping(int id) { OwnerProductMapping ownerProductMapping = db.AddedProducts.Find(id); if (ownerProductMapping == null) { return(NotFound()); } db.AddedProducts.Remove(ownerProductMapping); db.SaveChanges(); return(Ok(ownerProductMapping)); }
public IHttpActionResult PostOwnerProductMapping(int productId) { OwnerProductMapping ownerProductMapping = new OwnerProductMapping(); var id = User.Identity.GetUserId(); ApplicationUser user = db.Users.Find(id); var ownersId = db.Owners.FirstOrDefault(element => element.UserId == user.Id).Id; ownerProductMapping.OwnerId = ownersId; ownerProductMapping.ProductId = productId; ownerProductMapping.CreateDate = DateTime.Today; ownerProductMapping.ModifiedDate = DateTime.Today; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.AddedProducts.Add(ownerProductMapping); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = ownerProductMapping.Id }, ownerProductMapping)); }