public RequestStatus CreateNewInventory(string token, ref Inventory newInventory) { if (string.IsNullOrWhiteSpace(token) || newInventory == null || string.IsNullOrWhiteSpace(newInventory.ProductName) || newInventory.InventoryTypeID < 1 || string.IsNullOrWhiteSpace(newInventory.Status)) { return RequestStatus.InvalidInput; } var p = Person.GetByToken(token); if (p == null || !p.IsAdmin()) { return RequestStatus.AccessDenied; } newInventory = Inventory.NewInventory(newInventory); return newInventory != null ? RequestStatus.Success : RequestStatus.InvalidInput; }
public static Inventory NewInventory(Inventory newInventory) { Inventory inventory = null; if (newInventory != null && Configuration.IsAStatus(newInventory.Status) && !string.IsNullOrWhiteSpace(newInventory.ProductName) && newInventory.InventoryTypeID >= 0) { inventory = new Inventory { ProductName = newInventory.ProductName, Status = newInventory.Status, InventoryTypeID = newInventory.InventoryTypeID, InventoryType = InventoryType.All.FirstOrDefault(it => it.ID == newInventory.InventoryTypeID), RoomID = null }; BookITContext.Db.Inventories.Add(inventory); BookITContext.Db.SaveChanges(); } return inventory; }
public RequestStatus DeleteInventory(string token, Inventory inventory) { if (string.IsNullOrWhiteSpace(token) || inventory == null) { return RequestStatus.InvalidInput; } var p = Person.GetByToken(token); if (p == null || !p.IsAdmin()) { return RequestStatus.AccessDenied; } inventory = Inventory.GetInventoryByID(inventory.ID); if (inventory == null) { return RequestStatus.InvalidInput; } inventory.Remove(); return RequestStatus.Success; }
public RequestStatus ChangeInventory(string token, ref Inventory inventory) { if (string.IsNullOrWhiteSpace(token) || inventory == null) { return RequestStatus.InvalidInput; } var p = Person.GetByToken(token); if (p == null || !p.IsAdmin()) { return RequestStatus.AccessDenied; } var inv = Inventory.GetInventoryByID(inventory.ID); if (inv == null) { return RequestStatus.InvalidInput; } var rs = inventory.Edit(inventory); inventory = inv; return rs; }
public RequestStatus Edit(Inventory updatedInventory) { if (updatedInventory == null) { return RequestStatus.InvalidInput; } this.ProductName = !string.IsNullOrWhiteSpace(updatedInventory.ProductName) ? updatedInventory.ProductName : this.ProductName; this.Status = Configuration.IsAStatus(updatedInventory.Status) ? updatedInventory.Status : this.Status; this.InventoryTypeID = updatedInventory.InventoryTypeID > 0 ? updatedInventory.InventoryTypeID : this.InventoryTypeID; this.RoomID = updatedInventory.RoomID >= 0 ? updatedInventory.RoomID : this.RoomID; BookITContext.Db.SaveChanges(); return RequestStatus.Success; }
public RequestStatus GetInventoryByID(ref Inventory inventory) { if (inventory == null) { return RequestStatus.InvalidInput; } inventory = Inventory.GetInventoryByID(inventory.ID); return inventory != null ? RequestStatus.Success : RequestStatus.InvalidInput; }