public static DepartmentCollectionPointModel UpdateDepartmentCollectionPoint(DepartmentCollectionPointModel dcpm, out string error)
        {
            error = "";
            // declare and initialize new LUSSISEntities to perform update
            LUSSISEntities            entities = new LUSSISEntities();
            departmentcollectionpoint dcp      = new departmentcollectionpoint();

            try
            {
                dcp = entities.departmentcollectionpoints.Where(p => p.deptcpid == dcpm.DeptCpID).FirstOrDefault <departmentcollectionpoint>();

                dcp.deptid = dcpm.DeptID;
                dcp.cpid   = dcpm.CpID;
                dcp.status = dcpm.Status;
                // saving the update
                entities.SaveChanges();

                // return the updated model
                dcpm = GetDepartmentCollectionPointByDcpID(dcp.deptcpid, out error);

                if (dcpm.Status == ConDepartmentCollectionPoint.Status.ACTIVE)
                {
                    NotificationModel nom = new NotificationModel();
                    nom.Deptid   = dcpm.DeptID;
                    nom.Role     = ConUser.Role.HOD;
                    nom.Title    = "Approved Collection Point";
                    nom.NotiType = ConNotification.NotiType.ClerkApprovedCollectionPointChange;
                    nom.ResID    = dcpm.DeptCpID;
                    nom.Remark   = "The new collection point change request has been approved by the store";
                    nom          = NotificationRepo.CreatNotification(nom, out error);
                }
                else if (dcpm.Status == ConDepartmentCollectionPoint.Status.REJECTED)
                {
                    NotificationModel nom = new NotificationModel();
                    nom.Deptid   = dcpm.DeptID;
                    nom.Role     = ConUser.Role.HOD;
                    nom.Title    = "Rejected Collection Point";
                    nom.NotiType = ConNotification.NotiType.ClerkRejectedCollectionPointChange;
                    nom.ResID    = dcpm.DeptCpID;
                    nom.Remark   = "The new collection point change request has been rejected by the store";
                    nom          = NotificationRepo.CreatNotification(nom, out error);
                }
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(dcpm);
        }
        public static DepartmentCollectionPointModel AddDepartmentCollectionPoint(DepartmentCollectionPointModel dcpm, out string error)
        {
            error = "";
            // declare and initialize new LUSSISEntities to perform update
            LUSSISEntities entities = new LUSSISEntities();

            try
            {
                departmentcollectionpoint dcp = new departmentcollectionpoint
                {
                    deptid = dcpm.DeptID,
                    cpid   = dcpm.CpID,
                    status = dcpm.Status
                };
                entities.departmentcollectionpoints.Add(dcp);

                // saving the update
                entities.SaveChanges();

                // return the updated model
                dcpm = GetDepartmentCollectionPointByDcpID(dcp.deptcpid, out error);

                NotificationModel nom = new NotificationModel();
                nom.Deptid   = 11;
                nom.Role     = ConUser.Role.CLERK;
                nom.Title    = "Collection Point Request";
                nom.NotiType = ConNotification.NotiType.CollectionPointChangeRequestApproval;
                nom.ResID    = dcpm.DeptCpID;
                nom.Remark   = "The new collection point change has been requested!";
                nom          = NotificationRepo.CreatNotification(nom, out error);
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(dcpm);
        }
        public static DepartmentCollectionPointModel GetActiveDepartmentCollectionPointByDeptID(int deptid, out string error)
        {
            error = "";
            // declare and initialize new LUSSISEntities to perform update
            LUSSISEntities                 entities = new LUSSISEntities();
            departmentcollectionpoint      dcp      = new departmentcollectionpoint();
            DepartmentCollectionPointModel dcpm     = new DepartmentCollectionPointModel();

            try
            {
                dcp  = entities.departmentcollectionpoints.Where(p => p.deptid == deptid && p.status == ConDepartmentCollectionPoint.Status.ACTIVE).FirstOrDefault <departmentcollectionpoint>();
                dcpm = CovertDBDCPtoAPIDCP(dcp);
            }
            catch (NullReferenceException)
            {
                error = ConError.Status.NOTFOUND;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return(dcpm);
        }
        private static DepartmentCollectionPointModel CovertDBDCPtoAPIDCP(departmentcollectionpoint dcp)
        {
            DepartmentCollectionPointModel dcpm = new DepartmentCollectionPointModel(dcp.deptcpid, dcp.deptid, dcp.department.deptname, dcp.cpid, dcp.status, dcp.collectionpoint.cpname, dcp.collectionpoint.cplocation);

            return(dcpm);
        }