Beispiel #1
0
        public static List <LockerCollectionPointModel> GetLockerCPByLockersize(string lockersize, out string error)
        {
            error = "";
            // entites used only by Get Methods
            LUSSISEntities entities = new LUSSISEntities();
            List <lockercollectionpoint>      lcps  = new List <lockercollectionpoint>();
            LockerCollectionPointModel        lcpm  = new LockerCollectionPointModel();
            List <LockerCollectionPointModel> lcplm = new List <LockerCollectionPointModel>();

            try
            {
                // get lockercollectionpoint list from database by LockerSize
                lcps = entities.lockercollectionpoints.Where(p => p.lockersize == lockersize).ToList <lockercollectionpoint>();

                // convert the DB Model list to API Model list
                foreach (lockercollectionpoint lcp in lcps)
                {
                    lcplm.Add(ConvertBDLockerCPToAPILockerCP(lcp));
                }
            }
            // 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;
            }
            //returning the Lockercollectionpoint List
            return(lcplm);
        }
Beispiel #2
0
        public static LockerCollectionPointModel GetLockerCPByLockerid(int lockerid, out string error)
        {
            error = "";

            LUSSISEntities             entities = new LUSSISEntities();
            lockercollectionpoint      lcp      = new lockercollectionpoint();
            LockerCollectionPointModel lcpm     = new LockerCollectionPointModel();

            try
            {
                lcp  = entities.lockercollectionpoints.Where(p => p.lockerid == lockerid).FirstOrDefault <lockercollectionpoint>();
                lcpm = ConvertBDLockerCPToAPILockerCP(lcp);
            }
            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;
            }
            return(lcpm);
        }
Beispiel #3
0
        public static List <LockerCollectionPointModel> GetLockerCPByCPName(string cpname, out string error)
        {
            error = "";
            LUSSISEntities entities = new LUSSISEntities();
            List <lockercollectionpoint>      lcps  = new List <lockercollectionpoint>();
            LockerCollectionPointModel        lcpm  = new LockerCollectionPointModel();
            List <LockerCollectionPointModel> lcplm = new List <LockerCollectionPointModel>();

            try
            {
                lcps = entities.lockercollectionpoints.Where(p => p.collectionpoint.cpname == cpname).ToList <lockercollectionpoint>();

                foreach (lockercollectionpoint Lcp in lcps)
                {
                    lcplm.Add(ConvertBDLockerCPToAPILockerCP(Lcp));
                }
            }
            // 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 locker collection point list
            return(lcplm);
        }
Beispiel #4
0
        public static LockerCollectionPointModel CreateLockerCP(LockerCollectionPointModel lcp, string token, out string error)
        {
            string url = APIHelper.Baseurl + "/api/lockercollectionpoint/create/";
            LockerCollectionPointModel lpc = APIHelper.Execute <LockerCollectionPointModel>(token, url, out error);

            return(lcp);
        }
Beispiel #5
0
        public static LockerCollectionPointModel GetLockerCPByLockername(string lockername, string token, out string error)
        {
            string url = APIHelper.Baseurl + "/lockercollectionpoint/lockername" + lockername;
            LockerCollectionPointModel lcp = APIHelper.Execute <LockerCollectionPointModel>(token, url, out error);

            return(lcp);
        }
Beispiel #6
0
        // update the Requisition Pending to Preparing
        public static List <RequisitionWithDisbursementModel> UpdateAllRequestStatusToPreparing(out string error)
        {
            error = "";
            // declare and initialize new LUSSISEntities to perform update
            LUSSISEntities     entities = new LUSSISEntities();
            List <requisition> reqs     = new List <requisition>();
            List <RequisitionWithDisbursementModel> reqdisms = new List <RequisitionWithDisbursementModel>();

            try
            {
                reqs = entities.requisitions.Where(p => p.status == ConRequisition.Status.REQUESTPENDING).ToList();
                foreach (requisition req in reqs)
                {
                    req.status = ConRequisition.Status.PREPARING;
                    entities.SaveChanges();

                    DisbursementLockerModel dislm = new DisbursementLockerModel();
                    dislm.DisID  = req.disbursements.First().disid;
                    dislm.ReqID  = req.reqid;
                    dislm.DeptID = req.deptid;
                    List <LockerCollectionPointModel> lcpms = LockerCollectionPointRepo.GetAllLockerCP(out error);
                    LockerCollectionPointModel        lcpm  = lcpms.Where(p => p.Cpid == req.cpid && p.Status == ConLockerCollectionPoint.Active.AVAILABLE).FirstOrDefault();
                    if (lcpm == null)
                    {
                        List <DisbursementLockerModel> Currentdislms = new List <DisbursementLockerModel>();
                        Currentdislms = LockerCollectionPointRepo.GetDisbursementLockersByDeptIDAndStatus(req.deptid, 1, out error);
                        if (Currentdislms.Count > 0)
                        {
                            dislm = Currentdislms.First();
                        }
                        else
                        {
                            lcpm = new LockerCollectionPointModel();
                            lcpm = lcpms.Where(p => p.Cpid == req.cpid).FirstOrDefault();
                        }
                    }
                    else
                    {
                        dislm.LockerID = lcpm.Lockerid;
                    }
                    dislm = LockerCollectionPointRepo.CreateDisbursementLocker(dislm, out error);
                    reqdisms.Add(CovertDBRequisitionDistoAPIRequisitionDiswithDetails(req));
                }
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(reqdisms);
        }
Beispiel #7
0
        public IHttpActionResult CreateLockerCP(LockerCollectionPointModel lcp)
        {
            string error = "";
            LockerCollectionPointModel lcpm = LockerCollectionPointRepo.CreateLockerCP(lcp, out error);

            if (error != "" || lcpm == null)
            {
                return(Content(HttpStatusCode.BadRequest, error));
            }
            return(Ok(lcpm));
        }
Beispiel #8
0
        public IHttpActionResult GetLockerCPByLockername(string lockername)
        {
            string error = "";
            LockerCollectionPointModel lcpm = LockerCollectionPointRepo.GetLockerCPByLockername(lockername, out error);

            if (error != "" || lcpm == null)
            {
                if (error == ConError.Status.NOTFOUND)
                {
                    return(Content(HttpStatusCode.NotFound, "Locker Not Found"));
                }
                return(Content(HttpStatusCode.BadRequest, error));
            }
            return(Ok(lcpm));
        }
Beispiel #9
0
        public IHttpActionResult UpdateDisbursementLockerToCollected(DisbursementLockerModel disl)
        {
            string error = "";
            DisbursementLockerModel dislm = LockerCollectionPointRepo.UpdateDisbursementLocker(disl, out error);

            LockerCollectionPointModel lcpm = LockerCollectionPointRepo.GetLockerCPByLockerid(dislm.LockerID, out error);

            lcpm.Status = ConLockerCollectionPoint.Active.AVAILABLE;
            lcpm        = LockerCollectionPointRepo.UpdateLockerCP(lcpm, out error);

            if (error != "" || dislm == null)
            {
                return(Content(HttpStatusCode.BadRequest, error));
            }


            return(Ok(dislm));
        }
Beispiel #10
0
        public static DisbursementLockerModel CreateDisbursementLocker(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.disid         = lislm.DisID;
                disl.reqid         = lislm.ReqID;
                disl.lockerid      = lislm.LockerID;
                disl.deptid        = lislm.DeptID;
                disl.delivereddate = DateTime.Now.AddDays(2);
                disl.collecteddate = DateTime.Now.AddDays(9);
                disl.status        = 1;
                entities.disbursementlockers.Add(disl);
                entities.SaveChanges();

                LockerCollectionPointModel lcpm = GetLockerCPByLockerid(disl.lockerid, out error);
                lcpm.Status = ConLockerCollectionPoint.Active.NOTAVAILABLE;
                lcpm        = UpdateLockerCP(lcpm, out error);

                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);
        }
Beispiel #11
0
        public static LockerCollectionPointModel UpdateLockerCP(LockerCollectionPointModel lcpm, out string error)
        {
            // Initializing the error variable to return only blank if there is no error
            error = "";
            // declare and initialize new LUSSISEntities to perform update
            LUSSISEntities        entities = new LUSSISEntities();
            lockercollectionpoint lcp      = new lockercollectionpoint();

            try
            {
                // finding the lockercollectionpoint by lockerid
                lcp = entities.lockercollectionpoints.Where(p => p.lockerid == lcpm.Lockerid).First <lockercollectionpoint>();

                // transfering data from API model to DB Model
                lcp.lockername = lcpm.Lockername;
                lcp.lockersize = lcpm.Lockersize;
                lcp.cpid       = lcpm.Cpid;
                lcp.status     = lcpm.Status;

                // saving the update
                entities.SaveChanges();

                // return the updated model
                lcpm = ConvertBDLockerCPToAPILockerCP(lcp);
            }
            // 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;
            }
            //returning the lockercollectionpoint object
            return(lcpm);
        }
Beispiel #12
0
        public static LockerCollectionPointModel GetLockerCPByLockername(string lockername, out string error)
        {
            error = "";
            // declare and initialize new LUSSISEntities to get LockerCollectionPoint By LockerName
            LUSSISEntities entities = new LUSSISEntities();

            lockercollectionpoint      lcp  = new lockercollectionpoint();
            LockerCollectionPointModel lcpm = new LockerCollectionPointModel();

            try
            {
                lcp  = entities.lockercollectionpoints.Where(p => p.lockername == lockername).FirstOrDefault <lockercollectionpoint>();
                lcpm = ConvertBDLockerCPToAPILockerCP(lcp);
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(lcpm);
        }
Beispiel #13
0
        public static LockerCollectionPointModel CreateLockerCP(LockerCollectionPointModel lcpm, out string error)
        {
            error = "";
            // entites used only by Get Methods
            LUSSISEntities        entities = new LUSSISEntities();
            lockercollectionpoint lcp      = new lockercollectionpoint();

            try
            {
                // transfering data from API model to DB Model
                lcp.lockername = lcpm.Lockername;
                lcp.lockersize = lcpm.Lockersize;
                lcp.cpid       = lcpm.Cpid;
                lcp.status     = lcpm.Status;
                //Add the updated data to DB Model
                lcp = entities.lockercollectionpoints.Add(lcp);
                // saving the update
                entities.SaveChanges();
                //retrieving the LockerColletionPoint By Lockerid
                lcpm = GetLockerCPByLockerid(lcp.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(lcpm);
        }
Beispiel #14
0
        // Convert From Auto Generated DB Model to APIModel
        private static LockerCollectionPointModel ConvertBDLockerCPToAPILockerCP(lockercollectionpoint lcp)
        {
            LockerCollectionPointModel lcpm = new LockerCollectionPointModel(lcp.lockerid, lcp.lockername, lcp.lockersize, lcp.cpid, lcp.status, lcp.collectionpoint.cpname);

            return(lcpm);
        }