Esempio n. 1
0
        // Convert From Auto Generated DB Model to APIModel
        private static OutstandingReqModel ConvertDBOutReqToAPIOutReq(outstandingrequisition outreq)
        {
            List <OutstandingReqDetailModel> details =
                new List <OutstandingReqDetailModel>();

            foreach (outstandingrequisitiondetail ord in outreq.outstandingrequisitiondetails)
            {
                details.Add(OutstandingReqDetailRepo.ConvertDBOutReqDetailToAPIModel(ord));
            }
            OutstandingReqModel orm = new OutstandingReqModel(
                outreq.outreqid,
                outreq.reqid,
                outreq.reason,
                outreq.status
                );

            orm.OutReqDetails = details;
            return(orm);
        }
Esempio n. 2
0
        // To add new outstanding requisition
        public static OutstandingReqModel CreateOutReq
            (OutstandingReqModel ordm, out string error)
        {
            LUSSISEntities entities = new LUSSISEntities();

            error = "";
            OutstandingReqModel    outreqm = new OutstandingReqModel();
            outstandingrequisition outreq  = new outstandingrequisition();

            try
            {
                // transfering data from API model to DB Model
                List <outstandingrequisitiondetail> details =
                    new List <outstandingrequisitiondetail>();
                foreach (OutstandingReqDetailModel ordModel in ordm.OutReqDetails)
                {
                    details.Add(OutstandingReqDetailRepo
                                .ConvertAPIOutReqDetailToDBModel(ordModel));
                }
                outreq.reqid  = ordm.ReqId;
                outreq.reason = ordm.Reason;
                outreq.status = ConOutstandingsRequisition.Status.PENDING;
                outreq.outstandingrequisitiondetails = details;

                // adding into DB
                entities.outstandingrequisitions.Add(outreq);
                entities.SaveChanges();

                // return the model
                outreqm = GetOutstandingReqById(outreq.outreqid, out error);
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(outreqm);
        }
        private static InventoryDetailModel CovertDBInventorytoAPIInventoryDet(inventory inv)
        {
            string         error    = "";
            LUSSISEntities entities = new LUSSISEntities();
            // to show the recommended order qty
            int?recommededorderqty = 0;

            // if the stock is less than or equal reorder level
            if (inv.stock <= inv.reorderlevel)
            {
                // the recommended order qty will be the minimum reorder level and reorder qty and the total qty stock of outstanding req
                recommededorderqty = (inv.reorderlevel - inv.stock) + inv.reorderqty;

                List <OutstandingItemModel> outs = OutstandingReqDetailRepo.GetAllPendingOutstandingItems(out error);

                List <PurchaseOrderModel> poms = new List <PurchaseOrderModel>();

                if (error == "" && outs != null)
                {
                    try
                    {
                        if (staticpoms == null)
                        {
                            staticpoms = new List <PurchaseOrderModel>();
                        }

                        bool PendingPOExists = false;

                        if (staticcount < 4)
                        {
                            poms = staticpoms;

                            foreach (PurchaseOrderModel pom in poms)
                            {
                                int count = 0;
                                count = pom.podms.Where(x => x.Itemid == inv.itemid).Count();
                                if (count > 0)
                                {
                                    PendingPOExists = true;
                                    staticcount++;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            PendingPOExists = true;
                        }
                        if (PendingPOExists)
                        {
                            recommededorderqty = 0;
                        }
                        else
                        {
                            int itemlist = outs.Where(p => p.ItemId == inv.itemid).Count <OutstandingItemModel>();
                            if (itemlist > 0)
                            {
                                OutstandingItemModel outItem = outs.Where(p => p.ItemId == inv.itemid).FirstOrDefault <OutstandingItemModel>();
                                recommededorderqty += outItem.Total;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        error = e.Message;
                    }
                }
            }
            InventoryDetailModel invdm = new InventoryDetailModel(inv.invid, inv.itemid, inv.item.description, inv.stock, inv.reorderlevel, inv.reorderqty, inv.item.catid, inv.item.category.name, inv.item.description, inv.item.uom, recommededorderqty, inv.item.category.shelflocation, inv.item.category.shelflevel);

            return(invdm);
        }