public IHttpActionResult PutUserRole(int id, UserRole userRole) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != userRole.UserRoleID) { return(BadRequest()); } db.Entry(userRole).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!UserRoleExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutCustomer(int id, Customer customer) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != customer.CustomerID) { return(BadRequest()); } db.Entry(customer).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CustomerExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public void Insert(UserRole userRole) { using (CRContext db = new CRContext()) { db.UserRoles.Add(userRole); db.SaveChanges(); } }
public void Delete(Menu menu) { using (CRContext db = new CRContext()) { db.Menus.Attach(menu); db.Menus.Remove(menu); db.SaveChanges(); } }
public void Delete(User user) { using (CRContext db = new CRContext()) { db.Users.Attach(user); db.Users.Remove(user); db.SaveChanges(); } }
public void Update(UserRole userRole) { using (CRContext db = new CRContext()) { db.UserRoles.Attach(userRole); db.Entry(userRole).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } }
public void Insert(User user) { using (CRContext db = new CRContext()) { db.Users.Add(user); db.UserRoles.Attach(user.UserRole); db.Entry(user.UserRole).State = System.Data.Entity.EntityState.Unchanged; db.SaveChanges(); } }
public IHttpActionResult PutUser(int id, User user) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != user.UserID) { return(BadRequest()); } if (!String.IsNullOrEmpty(user.SecretPhrase)) { user.SecretPhrase = new Cypher().Encrypt(user.SecretPhrase); } user.Password = new Cypher().Encrypt(user.Password); db.UserRoles.Attach(user.UserRole); user.UserRoleID = user.UserRole.UserRoleID; db.Entry(user).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!UserExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutMenu(int id, Menu menu) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != menu.MenuID) { return(BadRequest()); } Menu parentMenu = (menu.ParentMenu != null ? menu.ParentMenu : null); if (parentMenu != null) { db.Menus.Attach(menu.ParentMenu); menu.ParentMenuID = menu.ParentMenu.ParentMenuID; } db.Entry(menu).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!MenuExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public void Insert(Menu menu) { using (CRContext db = new CRContext()) { db.Menus.Add(menu); Menu parentMenu = (menu.ParentMenu != null ? menu.ParentMenu : null); if (parentMenu != null) { db.Menus.Attach(parentMenu); db.Entry(menu.ParentMenu).State = EntityState.Unchanged; } db.SaveChanges(); } }
public void Update(Menu menu) { using (CRContext db = new CRContext()) { Menu parentMenu = (menu.ParentMenu != null ? menu.ParentMenu : null); if (parentMenu != null) { db.Menus.Attach(menu.ParentMenu); menu.ParentMenuID = menu.ParentMenu.ParentMenuID; } db.Entry(menu).State = EntityState.Modified; db.SaveChanges(); } }