public static CollectionPointModel GetCollectionPointBycpid(string token, int cpid, out string error)
        {
            string url = APIHelper.Baseurl + "/collectionpoint/" + cpid;
            CollectionPointModel cpm = APIHelper.Execute <CollectionPointModel>(token, url, out error);

            return(cpm);
        }
        public static CollectionPointModel GetCollectionPointByCpid(int cpid, out string error)
        {
            LUSSISEntities entities = new LUSSISEntities();

            error = "";

            collectionpoint cp = new collectionpoint();

            CollectionPointModel cpm = new CollectionPointModel();

            try
            {
                cp  = entities.collectionpoints.Where(p => p.cpid == cpid).FirstOrDefault <collectionpoint>();
                cpm = CovertDBCptoAPICp(cp);
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(cpm);
        }
        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);
        }
        public static CollectionPointModel UpdateCollectionPoint(string token, CollectionPointModel cpm, out string error)
        {
            error = "";
            string url          = APIHelper.Baseurl + "/collectionpoint/update";
            string objectstring = JsonConvert.SerializeObject(cpm);

            cpm = APIHelper.Execute <CollectionPointModel>(token, objectstring, url, out error);
            return(cpm);
        }
        public IHttpActionResult CreateCollectionPoint(CollectionPointModel cp)
        {
            string error             = "";
            CollectionPointModel cpm = CollectionPointRepo.CreateCollectionPoint(cp, out error);

            if (error != "" || cpm == null)
            {
                return(Content(HttpStatusCode.BadRequest, error));
            }
            return(Ok(cpm));
        }
        public IHttpActionResult GetCollectionPointByCpid(int cpid)
        {
            string error             = "";
            CollectionPointModel cpm = CollectionPointRepo.GetCollectionPointByCpid(cpid, out error);

            if (error != "" || cpm == null)
            {
                if (error == ConError.Status.NOTFOUND)
                {
                    return(Content(HttpStatusCode.NotFound, "CollectionPoint Not Found"));
                }
                return(Content(HttpStatusCode.BadRequest, error));
            }
            return(Ok(cpm));
        }
Ejemplo n.º 7
0
        public ActionResult CollectionPoint()
        {
            string    token = GetToken();
            UserModel um    = GetUser();
            DepartmentCollectionPointModel dcpm = new DepartmentCollectionPointModel();

            ViewBag.PendingCPR = false;
            List <CodeValue>                      CollectionPointsList = new List <CodeValue>();
            List <CollectionPointModel>           cpms  = new List <CollectionPointModel>();
            List <DepartmentCollectionPointModel> dcpms = new List <DepartmentCollectionPointModel>();

            try
            {
                // to show active collection point
                dcpms = APICollectionPoint.GetDepartmentCollectionPointByStatus(token, ConDepartmentCollectionPoint.Status.PENDING, out string error);

                dcpm = APICollectionPoint.GetActiveDepartmentCollectionPointByDeptID(token, um.Deptid, out error);
                ViewBag.ActiveCollectionPoint = dcpm.CpName;

                CollectionPointModel current =
                    APICollectionPoint.GetCollectionPointBycpid(token, dcpm.CpID, out error);

                ViewBag.Latitude  = current.Latitude;
                ViewBag.Longitude = current.Longitude;

                // to show pending list if exists
                dcpms = dcpms.Where(p => p.DeptID == um.Deptid).ToList();
                ViewBag.PendingCollectionPoints = dcpms;
                if (dcpms.Count > 0)
                {
                    ViewBag.PendingCPR = true;
                }


                // for radio button
                cpms = APICollectionPoint.GetAllCollectionPoints(token, out error);

                ViewBag.CollectionPointsList = cpms;
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Index", "Error", new { error = ex.Message }));
            }


            return(View(cpms));
        }
Ejemplo n.º 8
0
        public ActionResult CollectionPoint(int id)
        {
            string                         token = GetToken();
            UserModel                      um    = GetUser();
            CollectionPointModel           cpm   = new CollectionPointModel();
            DepartmentCollectionPointModel dcpm  = new DepartmentCollectionPointModel();

            try
            {
                cpm         = APICollectionPoint.GetCollectionPointBycpid(token, id, out string error);
                dcpm.CpID   = cpm.Cpid;
                dcpm.DeptID = um.Deptid;
                dcpm        = APICollectionPoint.CreateDepartmentCollectionPoint(token, dcpm, out error);
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Index", "Error", new { error = ex.Message }));
            }
            return(RedirectToAction("CollectionPoint"));
        }
        public static CollectionPointModel UpdateCollectionPoint(CollectionPointModel cpm, out string error)
        {
            error = "";
            // declare and initialize new LUSSISEntities to perform update
            LUSSISEntities  entities = new LUSSISEntities();
            collectionpoint cp       = new collectionpoint();

            try
            {
                // finding the collectionpoint object using CollectionPoint API model
                cp = entities.collectionpoints.Where(p => p.cpid == cpm.Cpid).First <collectionpoint>();

                // transfering data from API model to DB Model
                cp.cpname     = cpm.Cpname;
                cp.cplocation = cpm.Cplocation;
                cp.latitude   = cpm.Latitude;
                cpm.Longitude = cpm.Longitude;



                // saving the update
                entities.SaveChanges();

                // return the updated model
                cpm = CovertDBCptoAPICp(cp);
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(cpm);
        }
        // Convert From Auto Generated DB Model to APIModel
        private static CollectionPointModel CovertDBCptoAPICp(collectionpoint cp)
        {
            CollectionPointModel cpm = new CollectionPointModel(cp.cpid, cp.cpname, cp.cplocation, cp.latitude, cp.longitude);

            return(cpm);
        }