public bool UpdateDuration(UsersBurns object1) { UsersBurns userBurns = new UsersBurns(); bool update = false; using (ApplicationDbContext db = new ApplicationDbContext()) { try { userBurns = db.UsersBurns.Where(x => x.BurnId == object1.BurnId && x.UserId == object1.UserId).FirstOrDefault(); userBurns.Duration = object1.Duration; if (object1.Duration > 0) { db.UsersBurns.Attach(userBurns); db.Entry(userBurns).State = System.Data.Entity.EntityState.Modified; } else { db.UsersBurns.Remove(userBurns); } db.SaveChanges(); update = true; } catch { } } return(update); }
public void FindByIdAndChangeTime(int id, string userId, int quantity) { UsersBurns userBurns = new UsersBurns(); Burn burn; using (ApplicationDbContext db = new ApplicationDbContext()) { burn = db.Burns.SingleOrDefault(x => x.BurnId == id); userBurns = db.UsersBurns.SingleOrDefault(x => x.UserId == userId && x.BurnId == id); if (userBurns == null) { UsersBurns userBurns1 = new UsersBurns() { BurnId = id, UserId = userId, Duration = quantity }; db.UsersBurns.Add(userBurns1); } else { userBurns.Duration = quantity; } db.SaveChanges(); } }
public IHttpActionResult Post(UsersBurns object1) { if (!ModelState.IsValid) { return(BadRequest()); } _userBurnsRepositoty.CreateQuantity(object1); return(Ok()); }
public void CreateQuantity(UsersBurns object1) { UsersBurns userBurns = new UsersBurns(); using (ApplicationDbContext db = new ApplicationDbContext()) { db.UsersBurns.Add(new UsersBurns { UserId = object1.UserId, BurnId = object1.BurnId, Duration = object1.Duration }); db.SaveChanges(); } }
public IHttpActionResult Patch(UsersBurns object1) { return(Ok(_userBurnsRepositoty.UpdateDuration(object1))); }