public static InventoryDetailModel GetInventoryDetailByItemid(int itemid, out string error) { LUSSISEntities entities = new LUSSISEntities(); error = ""; inventory inventory = new inventory(); InventoryDetailModel invdm = new InventoryDetailModel(); try { staticpoms = PurchaseOrderRepo.GetPurchaseOrderByStatus(ConPurchaseOrder.Status.PENDING, out error); staticcount = 1; inventory = entities.inventories.Where(p => p.itemid == itemid).FirstOrDefault <inventory>(); invdm = CovertDBInventorytoAPIInventoryDet(inventory); } catch (NullReferenceException) { error = ConError.Status.NOTFOUND; } catch (Exception e) { error = e.Message; } return(invdm); }
public static List <InventoryDetailModel> GetAllInventoryDetails(out string error) { LUSSISEntities entities = new LUSSISEntities(); // Initializing the error variable to return only blank if there is no error error = ""; List <InventoryDetailModel> invdms = new List <InventoryDetailModel>(); try { // get inventory list from database List <inventory> invs = entities.inventories.Where(x => x.item.itemid == (x.item.supplieritems.Where(p => p.supplier.active == ConSupplier.Active.ACTIVE).FirstOrDefault().itemid)).ToList <inventory>(); staticcount = 1; staticpoms = PurchaseOrderRepo.GetPurchaseOrderByStatus(ConPurchaseOrder.Status.PENDING, out error); // convert the DB Model list to API Model list for inv detail foreach (inventory inv in invs) { invdms.Add(CovertDBInventorytoAPIInventoryDet(inv)); } } // if inventory not found, will throw NOTFOUND exception catch (NullReferenceException) { // if there is NULL Exception error, error will be 404 error = ConError.Status.NOTFOUND; } catch (Exception e) { // for other exceptions error = e.Message; } //returning the list return(invdms); }
public static List <PurchaseOrderFor5MonthModel> GetPOFor5Months(out string error) { LUSSISEntities entities = new LUSSISEntities(); List <PurchaseOrderFor5MonthModel> pomfs = new List <PurchaseOrderFor5MonthModel>(); List <PurchaseOrderModel> poms = new List <PurchaseOrderModel>(); List <PurchaseOrderModel> FilteredPoms = new List <PurchaseOrderModel>(); int count = 0; try { poms = PurchaseOrderRepo.GetPurchaseOrderByStatus(ConPurchaseOrder.Status.RECEIVED, out error); if (poms == null) { count = 5; } while (count < 5) { PurchaseOrderFor5MonthModel po5m = new PurchaseOrderFor5MonthModel(); FilteredPoms = poms.Where(x => x.Podate.Value.Month == (DateTime.Today.Month - count)).ToList(); if (FilteredPoms == null || FilteredPoms.Count < 1) { po5m.Month = DateTime.Today.AddMonths((count) * -1).ToString("MMMM"); pomfs.Add(po5m); } else { double AllPOTotal = 0; foreach (PurchaseOrderModel pom in FilteredPoms) { double total = 0; foreach (PurchaseOrderDetailModel podm in pom.podms) { double amount = 0; amount = podm.Qty * podm.Price ?? default(double); total += amount; } AllPOTotal += total; } po5m.PurchaseOrderCount = FilteredPoms.Count; po5m.Total = AllPOTotal; po5m.Month = DateTime.Today.AddMonths((count) * -1).ToString("MMMM"); pomfs.Add(po5m); } count++; } } catch (NullReferenceException) { error = ConError.Status.NOTFOUND; pomfs = new List <PurchaseOrderFor5MonthModel>(); } catch (Exception e) { error = e.Message; pomfs = new List <PurchaseOrderFor5MonthModel>(); } return(pomfs); }