Ejemplo n.º 1
0
        //Create new Requisition with Detials
        public static RequisitionModel CreateRequisitionwithDetails(RequisitionModel reqm, List <RequisitionDetailsModel> reqd, out string error)
        {
            error = "";
            LUSSISEntities           entities = new LUSSISEntities();
            requisition              req      = new requisition();
            List <requisitiondetail> reqlist  = new List <requisitiondetail>();

            try
            {
                req.reqid      = reqm.Reqid;
                req.raisedby   = reqm.Raisedby;
                req.approvedby = reqm.Approvedby;
                req.deptid     = reqm.Depid;
                req.cpid       = reqm.Cpid;
                req.status     = ConRequisition.Status.PENDING;
                req.reqdate    = DateTime.Now;

                req = entities.requisitions.Add(req);
                entities.SaveChanges();

                foreach (RequisitionDetailsModel rdm in reqd)
                {
                    requisitiondetail rqd = new requisitiondetail
                    {
                        reqid  = req.reqid,
                        itemid = rdm.Itemid,
                        qty    = rdm.Qty
                    };
                    rqd = entities.requisitiondetails.Add(rqd);
                    entities.SaveChanges();
                    reqlist.Add(rqd);
                }

                reqm = GetRequisitionByRequisitionId(req.reqid, out error);



                NotificationModel nom = new NotificationModel();
                nom.Deptid   = DepartmentRepo.GetDepartmentByUserid(reqm.Raisedby ?? default(int), out error).Deptid;
                nom.Role     = ConUser.Role.HOD;
                nom.Title    = "Requisition Approval";
                nom.NotiType = ConNotification.NotiType.RequisitionApproval;
                nom.ResID    = reqm.Reqid;
                nom.Remark   = "A new requisition has been raised by " + reqm.Rasiedbyname + "!";
                nom          = NotificationRepo.CreatNotification(nom, out error);
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(reqm);
        }
        // update the disbursement
        public static DisbursementModel UpdateDisbursement(DisbursementModel dism, out string error)
        {
            error = "";
            // declare and initialize new LUSSISEntities to perform update
            LUSSISEntities entities = new LUSSISEntities();
            disbursement   ndism    = new disbursement();

            try
            {
                // finding the inventory object using Inventory API model
                ndism = entities.disbursements.Where(p => p.disid == dism.Disid).First <disbursement>();

                // transfering data from API model to DB Model
                ndism.disid = dism.Disid;
                ndism.reqid = dism.Reqid;
                ndism.ackby = dism.Ackby;

                // saving the update
                entities.SaveChanges();

                // return the updated model
                dism = GetDisbursementByDisbursementId(ndism.disid, out error);
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(dism);
        }
        //create the disbursement
        public static DisbursementModel CreateDisbursement(DisbursementModel dism, out string error)
        {
            // initialize the error variable to return only blank if there is no error
            error = "";
            //initialize the entities , dibursement
            LUSSISEntities entities = new LUSSISEntities();
            disbursement   disb     = new disbursement();

            try
            {
                //add the data to the disbursement  database
                disb.reqid = dism.Reqid;
                disb.ackby = dism.Ackby;
                disb       = entities.disbursements.Add(disb);
                entities.SaveChanges();
                //get the newly added disbursement
                dism = GetDisbursementByDisbursementId(disb.disid, out error);
            }

            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(dism);
        }
Ejemplo n.º 4
0
        public static UserModel AssignDepRep(int id)
        {
            LUSSISEntities entities = new LUSSISEntities();
            user           um       = entities.users.Where(p => p.userid == id).First <user>();
            user           um1      = entities.users.Where(p => p.deptid == um.deptid && p.role == ConUser.Role.DEPARTMENTREP).First <user>();

            um1.role = ConUser.Role.EMPLOYEEREP;
            um.role  = ConUser.Role.DEPARTMENTREP;
            entities.SaveChanges();
            UserModel umm = CovertDBUsertoAPIUser(um);

            NotificationModel nom = new NotificationModel();

            nom.Deptid   = um.deptid;
            nom.Role     = ConUser.Role.DEPARTMENTREP;
            nom.Title    = "Department Representative";
            nom.NotiType = ConNotification.NotiType.DeptRepAssigned;
            nom.ResID    = um.userid;
            nom.Remark   = um.fullname + " has been assigned as a Department Representative!";
            nom          = NotificationRepo.CreatNotification(nom, out string error);


            nom.Deptid   = um.deptid;
            nom.Role     = ConUser.Role.EMPLOYEEREP;
            nom.Title    = "Department Representative";
            nom.NotiType = ConNotification.NotiType.DeptRepAssigned;
            nom.ResID    = um.userid;
            nom.Remark   = um.fullname + " has been assigned as a Department Representative!";
            nom          = NotificationRepo.CreatNotification(nom, out error);

            return(umm);
        }
        // create Requistion Details
        public static List <RequisitionDetailsModel> CreateRequisitionDetails(RequisitionDetailsModel reqd, out string error)
        {
            error = "";
            LUSSISEntities    entities = new LUSSISEntities();
            requisitiondetail reqdn    = new requisitiondetail();

            try
            {
                reqdn.reqid  = reqd.Reqid;
                reqdn.itemid = reqd.Itemid;
                reqdn.qty    = reqd.Qty;

                reqdn = entities.requisitiondetails.Add(reqdn);
                entities.SaveChanges();
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(GetRequisitionDetailsByRequisitionId(reqdn.reqid, out error));
        }
Ejemplo n.º 6
0
        //Create Category
        public static CategoryModel CreateCategory(CategoryModel cat, out string error)
        {
            error = "";
            LUSSISEntities entities = new LUSSISEntities();
            category       c        = new category();

            try
            {
                c.name          = cat.Name;
                c.shelflocation = cat.Shelflocation;
                c.shelflevel    = cat.Shelflevel;
                c = entities.categories.Add(c);
                entities.SaveChanges();
                cat = ConvertDBCategorytoAPICategory(c);
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(cat);
        }
        //Update Adjustmentdetail
        public static AdjustmentDetailModel UpdateAdjustmentDetail(AdjustmentDetailModel adjdm, out string error)
        {
            error = "";
            LUSSISEntities   entities = new LUSSISEntities();
            adjustmentdetail adjd     = new adjustmentdetail();

            try
            {
                adjd = entities.adjustmentdetails.Where(a => a.adjid == adjdm.Adjid && a.itemid == adjdm.Itemid).First <adjustmentdetail>();
                //adjd.adjid = adjdm.adjid;
                //adjd.itemid = adjdm.itemid;
                adjd.reason      = adjdm.Reason;
                adjd.adjustedqty = adjdm.Adjustedqty;

                entities.SaveChanges();
                adjdm = GetAdjustDetailByItemandAdjustID(adjd.itemid, adjd.adjid, out error);
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(adjdm);
        }
Ejemplo n.º 8
0
        public static DisbursementLockerModel UpdateDisbursementLocker(DisbursementLockerModel lislm, out string error)
        {
            error = "";
            // entites used only by Get Methods
            LUSSISEntities          entities = new LUSSISEntities();
            disbursementlocker      disl     = new disbursementlocker();
            DisbursementLockerModel dislm    = new DisbursementLockerModel();

            try
            {
                disl = entities.disbursementlockers.Where(p => p.reqid == lislm.ReqID && p.lockerid == lislm.LockerID).FirstOrDefault();

                disl.collecteddate = DateTime.Now;
                disl.status        = lislm.Status;
                entities.SaveChanges();

                dislm = GetDisbursementLockerByReqIDAndLockerID(disl.reqid, disl.lockerid, out error);
            }

            // if locker 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;
            }
            //retuning the lockercollectionpoint object
            return(dislm);
        }
        public static SupplierModel ActivateSupplier(SupplierModel sm, out string error)
        {
            LUSSISEntities entities = new LUSSISEntities();
            supplier       sup      = new supplier();

            error = "";
            try
            {
                sup = entities.suppliers
                      .Where(x => x.supid == sm.SupId)
                      .First();
                sup.active = ConSupplier.Active.ACTIVE;
                entities.SaveChanges();
                sm = ConvertDBSupToAPISup(sup);
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(sm);
        }
        public static SupplierModel CreateSupplier(SupplierModel sm, out string error)
        {
            LUSSISEntities entities = new LUSSISEntities();

            error = "";
            supplier sup = new supplier();

            try
            {
                sup.supname     = sm.SupName;
                sup.supemail    = sm.SupEmail;
                sup.supphone    = sm.SupPhone;
                sup.contactname = sm.ContactName;
                sup.gstregno    = sm.GstRegNo;
                sup.active      = ConSupplier.Active.ACTIVE;

                entities.suppliers.Add(sup);
                entities.SaveChanges();
                sm = ConvertDBSupToAPISup(sup);
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(sm);
        }
Ejemplo n.º 11
0
        public static InventoryTransactionModel CreateInventoryTransaction(InventoryTransactionModel invtm, out string error)
        {
            error = "";
            LUSSISEntities       entities = new LUSSISEntities();
            inventorytransaction d        = new inventorytransaction();

            try
            {
                d.datetime = DateTime.Now;
                d.invid    = invtm.InvID;
                d.itemid   = invtm.ItemID;
                d.trantype = invtm.TransType;
                d.qty      = invtm.Qty;
                d.remark   = invtm.Remark;
                d          = entities.inventorytransactions.Add(d);
                entities.SaveChanges();
                invtm = GetInventoryTransactionByTransID(d.tranid, out error);
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(invtm);
        }
        public static DepartmentModel CreateDepartment(DepartmentModel dm, out string error)
        {
            error = "";
            LUSSISEntities entities = new LUSSISEntities();
            department     d        = new department();

            try
            {
                d.deptname        = dm.Deptname;
                d.deptcontactname = dm.Deptcontactname;
                d.deptphone       = dm.Deptphone;
                d.deptemail       = dm.Deptemail;
                d = entities.departments.Add(d);
                entities.SaveChanges();
                dm = CovertDBDepttoAPIDept(d);
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(dm);
        }
        public static DepartmentModel UpdateDepartment(DepartmentModel dm, out string error)
        {
            error = "";
            // declare and initialize new LUSSISEntities to perform update
            LUSSISEntities entities = new LUSSISEntities();
            department     d        = new department();

            try
            {
                // finding the department object using Department API model
                d = entities.departments.Where(p => p.deptid == dm.Deptid).First <department>();

                // transfering data from API model to DB Model
                d.deptname        = dm.Deptname;
                d.deptcontactname = dm.Deptcontactname;
                d.deptphone       = dm.Deptphone;
                d.deptemail       = dm.Deptemail;

                // saving the update
                entities.SaveChanges();

                // return the updated model
                dm = CovertDBDepttoAPIDept(d);
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(dm);
        }
        public static CollectionPointModel CreateCollectionPoint(CollectionPointModel cpm, out string error)
        {
            error = "";
            LUSSISEntities  entities = new LUSSISEntities();
            collectionpoint cp       = new collectionpoint();

            try
            {
                cp.cpname     = cpm.Cpname;
                cp.cplocation = cpm.Cplocation;
                cp.latitude   = cpm.Latitude;
                cpm.Longitude = cpm.Longitude;

                cp = entities.collectionpoints.Add(cp);
                entities.SaveChanges();
                cpm = GetCollectionPointByCpid(cp.cpid, out error);
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(cpm);
        }
        //Update PurchaseOrder
        public static PurchaseOrderModel UpdatePurchaseOrder(PurchaseOrderModel pom, out string error)
        {
            error = "";
            LUSSISEntities entities = new LUSSISEntities();
            purchaseorder  po       = new purchaseorder();

            try
            {
                po = entities.purchaseorders.Where(p => p.poid == pom.PoId).FirstOrDefault <purchaseorder>();

                po.purchasedby = pom.Purchasedby;
                po.supid       = pom.Supid;
                po.status      = pom.Status;
                entities.SaveChanges();

                pom = GetPurchaseOrderByID(po.poid, out error);
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(pom);
        }
        public static List <DisbursementDetailsModel> UpdateDisbursementDetails(DisbursementDetailsModel dism, out string error)
        {
            error = "";
            // declare and initialize new LUSSISEntities to perform update
            LUSSISEntities     entities = new LUSSISEntities();
            disbursementdetail ndism    = new disbursementdetail();

            try
            {
                // finding the inventory object using Inventory API model
                ndism = entities.disbursementdetails.Where(p => p.disid == dism.Disid && p.itemid == dism.Itemid).First <disbursementdetail>();

                // transfering data from API model to DB Model
                ndism.disid  = dism.Disid;
                ndism.itemid = dism.Itemid;
                ndism.qty    = dism.Qty;

                // saving the update
                entities.SaveChanges();

                // return the updated model
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            // return the updated model
            return(GetDisbursementDetailsByDisbursementId(ndism.disid, out error));
        }
        public static InventoryModel UpdateInventory(InventoryModel invm, out string error)
        {
            error = "";
            // declare and initialize new LUSSISEntities to perform update
            LUSSISEntities entities = new LUSSISEntities();
            inventory      inv      = new inventory();

            try
            {
                // finding the inventory object using Inventory API model
                inv = entities.inventories.Where(p => p.invid == invm.Invid).First <inventory>();

                // transfering data from API model to DB Model
                inv.itemid       = invm.Itemid;
                inv.stock        = invm.Stock;
                inv.reorderlevel = invm.ReorderLevel;
                inv.reorderqty   = invm.ReorderQty;

                // saving the update
                entities.SaveChanges();

                // return the updated model
                invm = CovertDBInventorytoAPIInventory(inv);
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(invm);
        }
        //Create new PurchaseOrder
        public static PurchaseOrderDetailModel CreatePurchaseOrderDetail(PurchaseOrderDetailModel podm, out string error)
        {
            error = "";
            LUSSISEntities      entities = new LUSSISEntities();
            purchaseorderdetail pod      = new purchaseorderdetail();

            try
            {
                pod.poid     = podm.PoId;
                pod.itemid   = podm.Itemid;
                pod.qty      = podm.Qty;
                pod.delivqty = podm.DelivQty;
                pod.price    = podm.Price;
                entities.purchaseorderdetails.Add(pod);
                entities.SaveChanges();
                podm = GetPurchaseOrderDetailByIDAndItemID(pod.poid, pod.itemid, out error);
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(podm);
        }
        public static InventoryModel CreateInventory(InventoryModel invm, out string error)
        {
            error = "";
            LUSSISEntities entities = new LUSSISEntities();
            inventory      inv      = new inventory();

            try
            {
                inv.itemid       = invm.Itemid;
                inv.stock        = invm.Stock;
                inv.reorderlevel = invm.ReorderLevel;
                inv.reorderqty   = invm.ReorderQty;
                inv = entities.inventories.Add(inv);
                entities.SaveChanges();
                // retrieving the inserted inventory model by using the GetInventory method
                invm = GetInventoryByInventoryid(inv.invid, out error);
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(invm);
        }
Ejemplo n.º 20
0
        //Update Category
        public static CategoryModel UpdateCategory(CategoryModel cat, out string error)
        {
            error = "";
            LUSSISEntities entities = new LUSSISEntities();
            category       ca       = new category();

            try
            {
                ca               = entities.categories.Where(c => c.catid == cat.Catid).First <category>();
                ca.name          = cat.Name;
                ca.shelflocation = cat.Shelflocation;
                ca.shelflevel    = cat.Shelflevel;
                entities.SaveChanges();
                cat = ConvertDBCategorytoAPICategory(ca);
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(cat);
        }
        public static Boolean RemoveInventory(InventoryModel invm, out string error)
        {
            error = "";
            LUSSISEntities entities = new LUSSISEntities();
            inventory      inv      = new inventory();

            try
            {
                if (entities.inventories.Where(p => p.itemid == invm.Itemid).Count() > 0)
                {
                    inv = entities.inventories.Where(p => p.invid == invm.Itemid).First <inventory>();
                    entities.inventories.Remove(inv);
                    entities.SaveChanges();
                }
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
                return(false);
            }
            catch (Exception e)
            {
                error = e.Message;
                return(false);
            }
            return(true);
        }
Ejemplo n.º 22
0
        public static NotificationModel CreatNotification(NotificationModel nm, out string error)
        {
            error = "";
            LUSSISEntities entities = new LUSSISEntities();
            notification   n        = new notification();

            try
            {
                n.datetime = DateTime.Now;
                n.deptid   = nm.Deptid;
                n.role     = nm.Role;
                n.title    = nm.Title;
                n.remark   = nm.Remark;
                n.isread   = false;
                n.resid    = nm.ResID;
                n.notitype = nm.NotiType;
                n          = entities.notifications.Add(n);
                entities.SaveChanges();

                nm = GetNotiBynotiid(n.notiid, out error);
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(nm);
        }
Ejemplo n.º 23
0
        public static NotificationModel UpdateNotiRead(int id, out string error)
        {
            error = "";
            LUSSISEntities    entities = new LUSSISEntities();
            notification      n        = new notification();
            NotificationModel nm       = new NotificationModel();

            try
            {
                n        = entities.notifications.Where(x => x.notiid == id).FirstOrDefault();
                n.isread = true;
                entities.SaveChanges();

                nm = GetNotiBynotiid(n.notiid, out error);
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(nm);
        }
        // update the Requisition Details
        public static RequisitionDetailsModel UpdateRequisitionDetail(RequisitionDetailsModel reqdm, out string error)
        {
            error = "";
            // declare and initialize new LUSSISEntities to perform update
            LUSSISEntities    entities = new LUSSISEntities();
            requisitiondetail reqd     = new requisitiondetail();

            try
            {
                // finding the inventory object using Inventory API model
                reqd = entities.requisitiondetails.Where(p => p.reqid == reqdm.Reqid && p.itemid == reqdm.Itemid).FirstOrDefault <requisitiondetail>();

                // transfering data from API model to DB Model
                reqd.reqid  = reqdm.Reqid;
                reqd.itemid = reqdm.Itemid;
                reqd.qty    = reqdm.Qty;

                // saving the update
                entities.SaveChanges();

                // return the updated model
                reqdm = CovertDBRequisitionDetailstoAPIRequisitionDetails(reqd);
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(reqdm);
        }
        public static DisbursementDetailsModel CreateDisbursementDetails(DisbursementDetailsModel disdm, out string error)
        {
            error = "";
            LUSSISEntities           entities = new LUSSISEntities();
            disbursementdetail       disdb    = new disbursementdetail();
            DisbursementDetailsModel ddm      = new DisbursementDetailsModel();

            try
            {
                disdb.disid  = disdm.Disid;
                disdb.itemid = disdm.Itemid;
                disdb.qty    = disdm.Qty;
                disdb        = entities.disbursementdetails.Add(disdb);
                entities.SaveChanges();

                ddm = new DisbursementDetailsModel(disdb.disid, disdb.itemid, disdb.item.description, disdb.qty, disdb.item.category.name, disdb.item.uom);
            }

            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(ddm);
        }
Ejemplo n.º 26
0
        //update Delegation
        public static DelegationModel UpdateDelegation(DelegationModel dm, out String error)
        {
            error = "";
            // declare and initialize new LUSSISEntities to perform update
            LUSSISEntities entities = new LUSSISEntities();
            delegation     d        = new delegation();

            try
            {
                // finding the delegation object using delegation API model
                d = entities.delegations.Where(p => p.delid == dm.Delid).First <delegation>();

                // transfering data from API model to DB Model
                d.startdate  = dm.Startdate;
                d.enddate    = dm.Enddate;
                d.userid     = dm.Userid;
                d.active     = dm.Active;
                d.assignedby = dm.AssignedbyId;

                // saving the update
                entities.SaveChanges();

                // return the updated model
                dm = CovertDBDelegationtoAPIUser(d);
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(dm);
        }
        //Create new PurchaseOrder
        public static PurchaseOrderModel CreatePurchaseOrder(PurchaseOrderModel pom, out string error)
        {
            error = "";
            LUSSISEntities             entities = new LUSSISEntities();
            purchaseorder              po       = new purchaseorder();
            List <purchaseorderdetail> pods     = new List <purchaseorderdetail>();

            try
            {
                po.purchasedby = pom.Purchasedby;
                po.supid       = pom.Supid;
                po.podate      = DateTime.Now;
                po.status      = pom.Status;
                po             = entities.purchaseorders.Add(po);
                entities.SaveChanges();
                pom = GetPurchaseOrderByID(po.poid, out error);
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(pom);
        }
Ejemplo n.º 28
0
        public static ItemModel UpdateItem(ItemModel im, out string error)
        {
            error = "";
            // declare and initialize new LUSSISEntities to perform update
            LUSSISEntities entities = new LUSSISEntities();
            item           item     = new item();

            try
            {
                // finding the item object using Item API model
                item = entities.items.Where(p => p.itemid == im.Itemid).First <item>();

                // transfering data from API model to DB Model
                item.catid       = im.Catid;
                item.description = im.Description;
                item.uom         = im.Uom;

                // saving the update
                entities.SaveChanges();

                // return the updated model
                im = CovertDBItemtoAPIItem(item);
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(im);
        }
Ejemplo n.º 29
0
        public static ItemModel CreateItem(ItemModel im, out string error)
        {
            error = "";
            LUSSISEntities entities = new LUSSISEntities();
            item           item     = new item();

            try
            {
                item.catid       = im.Catid;
                item.description = im.Description;
                item.uom         = im.Uom;
                item             = entities.items.Add(item);
                entities.SaveChanges();
                // retrieving the inserted item model by using the GetItem method
                im = GetItemByItemid(item.itemid, out error);
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(im);
        }
Ejemplo n.º 30
0
        // To change the status from pending to complete
        public static RequisitionWithOutstandingModel Complete
            (RequisitionWithOutstandingModel ordm, out string error)
        {
            LUSSISEntities entities = new LUSSISEntities();

            error = "";
            outstandingrequisition          req                 = new outstandingrequisition();
            RequisitionWithOutstandingModel reqoutm             = new RequisitionWithOutstandingModel();
            List <RequisitionDetailsWithOutstandingModel> reqdm = new List <RequisitionDetailsWithOutstandingModel>();

            try
            {
                // finding the db object using API model
                req = entities.outstandingrequisitions
                      .Where(x => x.requisition.reqid == ordm.Reqid)
                      .FirstOrDefault();

                if (req.requisition.status == ConRequisition.Status.OUTSTANDINGREQUISITION || req.status == ConOutstandingsRequisition.Status.DELIVERED)
                {
                    req.status             = ConOutstandingsRequisition.Status.COMPLETE;
                    req.requisition.status = ConRequisition.Status.COMPLETED;
                    entities.SaveChanges();
                    foreach (outstandingrequisitiondetail rqdm in req.outstandingrequisitiondetails)
                    {
                        reqdm.Add(new RequisitionDetailsWithOutstandingModel(req.reqid, rqdm.itemid, rqdm.item.description,
                                                                             rqdm.qty, rqdm.item.category.name, rqdm.item.uom,
                                                                             rqdm.qty));
                    }
                    reqoutm = new RequisitionWithOutstandingModel(req.reqid, req.requisition.raisedby, req.requisition.user.fullname
                                                                  , req.requisition.approvedby, req.requisition.user1.fullname, req.requisition.cpid, req.requisition.collectionpoint.cpname
                                                                  , req.requisition.deptid, req.requisition.department.deptname, req.status, req.requisition.reqdate, 999,
                                                                  "Z" + req.requisition.deptid, reqdm);
                    NotificationModel nom = new NotificationModel();
                    nom.Datetime = DateTime.Now;
                    nom.Deptid   = 11;
                    nom.Remark   = "The Outstanding Items with Requisition ID (" + req.reqid + ") is now collected";
                    nom.Role     = ConUser.Role.CLERK;
                    nom.Title    = "Outstanding Items Collected";
                    nom.NotiType = ConNotification.NotiType.OutstandingItemsCollected;
                    nom.ResID    = req.reqid;
                    nom          = NotificationRepo.CreatNotification(nom, out error);
                }
                else
                {
                    error   = "Status not Outstanding";
                    reqoutm = new RequisitionWithOutstandingModel();
                }
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(reqoutm);
        }