public IHttpActionResult PutUser(int id, User user) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != user.ID) { return(BadRequest()); } List <int> sitesUserHasPermissionFor = Global.CheckUserIDAndPassword(db, user.UILoginUserID, user.UILoginPassword, "PutUser"); if (sitesUserHasPermissionFor.Count() < 1) { return(BadRequest()); } if (sitesUserHasPermissionFor.Count() == 1 && sitesUserHasPermissionFor[0] == -1) { db.Entry(user).State = EntityState.Modified; } else { var query = from userx in db.Users join userSite in db.UserSites on userx.ID equals userSite.UserID join siteUserHasPermissionFor in sitesUserHasPermissionFor on userSite.SiteID equals siteUserHasPermissionFor join usery in db.Users on userx.CreatedByUserID equals usery.ID where userx.ID == user.ID && usery.IsSiteAdmin && usery.ID == user.UILoginUserID && userx.CreatedByUserID == user.UILoginUserID select userx; if (query.Count() == 1) { db.Entry(user).State = EntityState.Modified; } else { return(BadRequest()); } } try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!UserExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutInventory(int id, Inventory inventory) { if (!Global.CheckUserIDAndPasswordWithSiteID(db, inventory.UILoginUserID, inventory.UILoginPassword, inventory.SiteID, "PutInventory")) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != inventory.ID) { return(BadRequest()); } Inventory i = db.Inventories.AsNoTracking().SingleOrDefault(p => p.ID == id); if (i == null) { return(NotFound()); } if (i.SiteID != inventory.SiteID) { return(BadRequest()); } User user = db.Users.Find(inventory.UILoginUserID); if (!user.IsRootUser && !user.IsSiteAdmin && i.EntryByUserID != user.ID) { return(BadRequest()); } if (i.ProductTypeID != inventory.ProductTypeID) { return(BadRequest()); } db.Entry(inventory).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!InventoryExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutSite(int id, Site site) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != site.ID) { return(BadRequest()); } if (!Global.CheckUserIDAndPasswordWithSiteID(db, site.UILoginUserID, site.UILoginPassword, site.ID, "PutSite")) { return(BadRequest()); } UserSite userSite = db.UserSites.Where(u => u.SiteID == site.ID && u.UserID == site.UILoginUserID).SingleOrDefault(); if (userSite == null) { return(BadRequest()); } User user = db.Users.Find(site.UILoginUserID); if (user == null) { return(BadRequest()); } if (!user.IsSiteAdmin && !user.IsRootUser) { return(BadRequest()); } db.Entry(site).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!SiteExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutMenuItemIngredient(int id, MenuItemIngredient menuItemIngredient) { if (!Global.CheckUserIDAndPasswordWithSiteID(db, menuItemIngredient.UILoginUserID, menuItemIngredient.UILoginPassword, menuItemIngredient.SiteID, "PutMenuItemIngredient")) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != menuItemIngredient.ID) { return(BadRequest()); } MenuItemIngredient mii = db.MenuItemIngredients.AsNoTracking().SingleOrDefault(p => p.ID == id); if (mii == null) { return(NotFound()); } if (mii.SiteID != menuItemIngredient.SiteID) { return(BadRequest()); } User user = db.Users.Find(menuItemIngredient.UILoginUserID); if (!user.IsRootUser && !user.IsSiteAdmin && mii.EntryByUserID != user.ID) { return(BadRequest()); } db.Entry(menuItemIngredient).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!MenuItemIngredientExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutOrderItem(int id, OrderItem orderItem) { if (!Global.CheckUserIDAndPasswordWithSiteID(db, orderItem.UILoginUserID, orderItem.UILoginPassword, orderItem.SiteID, "PutOrderItem")) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != orderItem.ID) { return(BadRequest()); } OrderItem oi = db.OrderItems.AsNoTracking().SingleOrDefault(p => p.ID == id); if (oi == null) { return(NotFound()); } if (oi.SiteID != orderItem.SiteID) { return(BadRequest()); } User user = db.Users.Find(orderItem.UILoginUserID); if (!user.IsRootUser && !user.IsSiteAdmin && oi.EntryByUserID != user.ID) { return(BadRequest()); } db.Entry(orderItem).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!OrderItemExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutVendorProductType(int id, VendorProductType vendorProductType) { if (!Global.CheckUserIDAndPasswordWithSiteID(db, vendorProductType.UILoginUserID, vendorProductType.UILoginPassword, vendorProductType.SiteID, "PutVendorProductType")) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != vendorProductType.ID) { return(BadRequest()); } VendorProductType vpt = db.VendorProductTypes.AsNoTracking().SingleOrDefault(p => p.ID == id); if (vpt == null) { return(NotFound()); } if (vpt.SiteID != vendorProductType.SiteID) { return(BadRequest()); } User user = db.Users.Find(vendorProductType.UILoginUserID); if (!user.IsRootUser && !user.IsSiteAdmin && vpt.EntryByUserID != user.ID) { return(BadRequest()); } db.Entry(vendorProductType).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!VendorProductTypeExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutRequisition(int id, Requisition requisition) { if (!Global.CheckUserIDAndPasswordWithSiteID(db, requisition.UILoginUserID, requisition.UILoginPassword, requisition.SiteID, "PutRequisition")) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != requisition.ID) { return(BadRequest()); } Requisition req = db.Requisitions.AsNoTracking().SingleOrDefault(p => p.ID == id); if (req == null) { return(NotFound()); } if (req.SiteID != requisition.SiteID) { return(BadRequest()); } User user = db.Users.Find(requisition.UILoginUserID); if (!user.IsRootUser && !user.IsSiteAdmin && req.EntryByUserID != user.ID) { return(BadRequest()); } db.Entry(requisition).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!RequisitionExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutPurchaseOrder(int id, PurchaseOrder purchaseOrder) { if (!Global.CheckUserIDAndPasswordWithSiteID(db, purchaseOrder.UILoginUserID, purchaseOrder.UILoginPassword, purchaseOrder.SiteID, "PutPurchaseOrder")) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != purchaseOrder.ID) { return(BadRequest()); } PurchaseOrder po = db.PurchaseOrders.AsNoTracking().SingleOrDefault(p => p.ID == id); if (po == null) { return(NotFound()); } if (po.SiteID != purchaseOrder.SiteID) { return(BadRequest()); } User user = db.Users.Find(purchaseOrder.UILoginUserID); if (!user.IsRootUser && !user.IsSiteAdmin && po.EntryByUserID != user.ID) { return(BadRequest()); } db.Entry(purchaseOrder).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!PurchaseOrderExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutReceived(int id, Receiving receiving) { if (!Global.CheckUserIDAndPasswordWithSiteID(db, receiving.UILoginUserID, receiving.UILoginPassword, receiving.SiteID, "PutReceiving")) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != receiving.ID) { return(BadRequest()); } Receiving r = db.Received.AsNoTracking().SingleOrDefault(p => p.ID == id); if (r == null) { return(NotFound()); } if (r.SiteID != receiving.SiteID) { return(BadRequest()); } User user = db.Users.Find(receiving.UILoginUserID); if (!user.IsRootUser && !user.IsSiteAdmin && r.EntryByUserID != user.ID) { return(BadRequest()); } VendorProductType vpt = db.VendorProductTypes.Find(receiving.VendorProductTypeID); if (vpt == null) { return(BadRequest()); } Inventory i = db.Inventories.AsNoTracking().SingleOrDefault(u => u.ProductTypeID == vpt.ProductTypeID); if (i != null) { if (r.VendorProductTypeID == receiving.VendorProductTypeID && r.Quantity != receiving.Quantity) { i.Quantity += receiving.Quantity - r.Quantity; db.Entry(i).State = EntityState.Modified; } else if (r.VendorProductTypeID != receiving.VendorProductTypeID) { VendorProductType vpt2 = db.VendorProductTypes.Find(r.VendorProductTypeID); Inventory i2 = db.Inventories.AsNoTracking().SingleOrDefault(u => u.ProductTypeID == vpt2.ProductTypeID); i2.Quantity -= r.Quantity; db.Entry(i2).State = EntityState.Modified; i.Quantity += receiving.Quantity; db.Entry(i).State = EntityState.Modified; } } else { Inventory inew = new Inventory(); inew.EntryByUserID = receiving.UILoginUserID; inew.TransactionDateTime = DateTime.Now; inew.ProductTypeID = vpt.ProductTypeID; inew.Quantity = receiving.Quantity; inew.SiteID = receiving.SiteID; db.Inventories.Add(inew); } db.Entry(receiving).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ReceivedExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }