Beispiel #1
0
        public ActionResult Index(int?page, string UPNO, string currentFilterUP, int filterBonderId = 0, int BONDERID = 0)
        {
            if (TempData["Message"] != null)
            {
                ViewBag.Message = TempData["Message"].ToString();
                TempData.Remove("Message");
            }

            var ups        = db.UPs.Include(u => u.BONDER);
            int pageSize   = recordNumbers;
            int pageNumber = (page ?? 1);

            ViewBag.BONDERID = new SelectList(db.BONDERs, "BONDERSLNO", "BONDERNAME");
            USERPERMISSION loggedinUser = new SessionAttributeRetreival().getStoredUserPermission();

            if (BONDERID == 0 && filterBonderId == 0 && !User.IsInRole("Bonder"))
            {
                List <UP> initialUps = new List <UP>();
                ViewBag.resultofbonderID = BONDERID;
                return(View(initialUps.ToList().ToPagedList(pageNumber, pageSize)));
            }
            if (UPNO != null || BONDERID != 0)
            {
                page = 1;
            }
            else
            {
                if (UPNO == null)
                {
                    UPNO = currentFilterUP;
                }
                if (BONDERID == 0)
                {
                    BONDERID = filterBonderId;
                }
            }
            ViewBag.filterBonderId  = BONDERID;
            ViewBag.CurrentFilterUP = UPNO;
            if (loggedinUser.BONDERID != null)
            {
                ViewBag.resultofbonderID = loggedinUser.BONDERID;
                ups = db.UPs.Include(u => u.BONDER).Where(e => e.BONDERID == loggedinUser.BONDERID);
            }
            else if (BONDERID > 0)
            {
                ViewBag.resultofbonderID = BONDERID;
                ups = db.UPs.Include(u => u.BONDER).Where(e => e.BONDERID == BONDERID);
            }
            if (UPNO != null)
            {
                ups = ups.Include(u => u.BONDER).Where(e => e.UPNO.Contains(UPNO));
            }
            ViewBag.userBonderId = loggedinUser.BONDERID;

            if (BONDERID != 0)
            {
                if (loggedinUser.BONDERID != null)
                {
                    ViewBag.resultofbonderID = loggedinUser.BONDERID;
                    ups = db.UPs.Include(u => u.BONDER).Where(e => e.BONDERID == loggedinUser.BONDERID);
                }
                else if (BONDERID > 0)
                {
                    ViewBag.resultofbonderID = BONDERID;
                    ups = db.UPs.Include(u => u.BONDER).Where(e => e.BONDERID == BONDERID);
                }
                if (UPNO != null)
                {
                    ups = ups.Include(u => u.BONDER).Where(e => e.UPNO.Contains(UPNO));
                }
            }
            return(View(ups.ToList().ToPagedList(pageNumber, pageSize)));
        }
Beispiel #2
0
        public ActionResult createOrEditRequest(IList <EXBOND> exbonds, IList <ATTACHMENT> attachments, short ID = 0)
        {
            USERPERMISSION loggedinUser = new SessionAttributeRetreival().getStoredUserPermission();

            if (TempData["isAnyAttachment"] != null)
            {
                bool isAnyAttachment = (bool)TempData["isAnyAttachment"];
                if (!isAnyAttachment)
                {
                    attachments = null;
                }
            }
            var files = Request.Files;

            //for (int i = 0; i < Request.Files.Count; i++)
            //{
            //    HttpPostedFileBase file = files[i];
            //    var fileName = Path.GetFileName(file.FileName);
            //}
            if (attachments != null)
            {
                foreach (ATTACHMENT attachment in attachments)
                {
                    if (attachment != null && attachment.CONTENT == null && attachment.ID == 0 && attachment.NAME == null)
                    {
                        if (ID <= 0)
                        {
                            return(RedirectToAction("Create", new { error = "Please provide a valid file" }));
                        }
                        else
                        {
                            return(RedirectToAction("AddMoreAttachment", new { ID, errorMessage = "Please provide a valid file" }));
                        }
                    }
                }
            }
            bool attachmentValid = false;

            foreach (string extensions in GlobalConstants.extensions)
            {
                try
                {
                    if (attachments.Any(item => item.CONTENT.EndsWith(extensions)))
                    {
                        attachmentValid = true;
                        break;
                    }
                }
                catch (Exception e) {
                    attachmentValid = true;
                }
            }
            if (!attachmentValid)
            {
                if (ID <= 0)
                {
                    return(RedirectToAction("Create", new { error = "Please provide a valid file" }));
                }
                else
                {
                    return(RedirectToAction("Edit", new { ID, error = "Please provide a valid file" }));
                }
            }
            List <ATTACHMENT> newAttachmentList = new List <ATTACHMENT>();

            if (attachments != null)
            {
                for (int i = 0; i < attachments.Count(); i++)
                {
                    if (attachments[i].CONTENT != null)
                    {
                        newAttachmentList.Add(attachments[i]);
                    }
                }
            }
            UPREQUEST      uprequest     = new UPREQUEST();
            IList <EXBOND> exbondList    = new List <EXBOND>();
            bool           flag          = true;
            bool           isanyselected = false;

            if (exbonds != null)
            {
                for (int i = 0; i < exbonds.Count(); i++)
                {
                    int id = exbonds[i].ID;
                    if (exbonds[i].IsSelected)
                    {
                        isanyselected = true;
                        EXBOND exbond   = db.EXBONDs.Find(id);
                        int    b2bCount = exbond.EXBONDBACKTOBACKs.Count();
                        if (exbond != null && b2bCount < 1)
                        {
                            flag = false;
                        }
                        else
                        {
                            uprequest.BONDERID = exbond.BONDERID;
                            exbondList.Add(exbond);
                        }
                    }
                }
            }
            if (!isanyselected && ID <= 0)
            {
                return(RedirectToAction("Create", new { error = "Please select at least one exbond" }));
            }
            if (!flag && ID <= 0)
            {
                return(RedirectToAction("Create", new { error = "Sorry! please check all selected Exbond has at least one backtoback" }));
            }
            else
            {
                short lastInserted = 0;
                //if (ModelState.IsValid)
                //{
                if (ID <= 0)
                {
                    DateTime thisDay = DateTime.Today;
                    uprequest.CREATEDDATE = thisDay;
                    if (loggedinUser != null)
                    {
                        uprequest.CREATEDBY = loggedinUser.APPUSER.USERNAME;
                    }
                    uprequest.STATUS = 2;
                    db.UPREQUESTs.Add(uprequest);
                    db.SaveChanges();
                    lastInserted = db.UPREQUESTs.Max(item => item.ID);
                }
                else
                {
                    uprequest = db.UPREQUESTs.Find(ID);
                    UPREQUEST newRequest = new UPREQUEST();
                    newRequest.ID           = ID;
                    newRequest.BONDERID     = uprequest.BONDERID;
                    newRequest.STATUS       = uprequest.STATUS;
                    newRequest.MODIFIEDDATE = DateTime.Today;
                    uprequest.CREATEDDATE   = uprequest.CREATEDDATE;
                    uprequest.CREATEDBY     = uprequest.CREATEDBY;
                    if (loggedinUser != null)
                    {
                        uprequest.MODIFIEDBY = loggedinUser.APPUSER.USERNAME;
                    }
                    using (var newdb2 = new OracleEntitiesConnStr())
                    {
                        newdb2.Entry(newRequest).State = EntityState.Modified;
                        newdb2.SaveChanges();
                    }
                    lastInserted = ID;
                }
                for (int x = 0; x < exbondList.Count(); x++)
                {
                    using (var db1 = new OracleEntitiesConnStr())
                    {
                        UPEXBONDLIST upexbond = new UPEXBONDLIST();
                        upexbond.EXBONDID    = exbondList[x].ID;
                        upexbond.UPREQUESTID = lastInserted;
                        db1.UPEXBONDLISTs.Add(upexbond);
                        db1.SaveChanges();
                    }
                }
                for (int k = 0; k < newAttachmentList.Count(); k++)
                {
                    string path = UploadedPath(files[k], newAttachmentList[k].CONTENT);
                    attachments[k].CONTENT = path;
                    using (var db2 = new OracleEntitiesConnStr())
                    {
                        attachments[k].UPREQUESTID = lastInserted;
                        db2.ATTACHMENTs.Add(attachments[k]);
                        db2.SaveChanges();
                    }
                }
                // }
                if (ID <= 0)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(RedirectToAction("Edit/" + ID));
                }
            }
        }
Beispiel #3
0
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            string idParam        = "";
            var    descriptor     = filterContext.ActionDescriptor;
            var    actionName     = descriptor.ActionName;
            var    controllerName = descriptor.ControllerDescriptor.ControllerName;

            if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
            {
                //if not logged, it will work as normal Authorize and redirect to the Login
                base.HandleUnauthorizedRequest(filterContext);
                return;
            }
            else if (!this.Roles.Split(',').Select(x => x.Trim()).Distinct().ToArray().Any(filterContext.HttpContext.User.IsInRole))
            {
                // The user is not in any of the listed roles =>
                // show the unauthorized view
                filterContext.Result = filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Error", action = "AccessDenied" }));
            }
            try
            {
                idParam = filterContext.Controller.ValueProvider.GetValue("id").AttemptedValue;
            }
            catch (NullReferenceException ex)
            {
                return;
            }
            int            id;
            string         username     = FormsAuthentication.Decrypt(HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name;
            APPUSER        appuser      = db.APPUSERs.SingleOrDefault(u => u.USERNAME.Equals(username, StringComparison.OrdinalIgnoreCase));
            USERPERMISSION loggedinUser = new SessionAttributeRetreival().getStoredUserPermission();

            if (int.TryParse(idParam, out id))
            {
                if (System.Web.HttpContext.Current.User.IsInRole("Bonder"))
                {
                    if (id != appuser.ID && controllerName.Equals("AppUser"))
                    {
                        filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Error", action = "AccessDenied" }));
                    }
                    if (controllerName.Equals("ExBond"))
                    {
                        if (loggedinUser == null)
                        {
                            filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Error", action = "AccessDenied" }));
                        }
                        else
                        {
                            EXBOND exbond = db.EXBONDs.SingleOrDefault(u => u.ID == id);
                            if (exbond != null && exbond.BONDERID != loggedinUser.BONDERID)
                            {
                                filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Error", action = "AccessDenied" }));
                            }
                        }
                    }
                    if (controllerName.Equals("InBond"))
                    {
                        if (loggedinUser == null)
                        {
                            filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Error", action = "AccessDenied" }));
                        }
                        else
                        {
                            INBOND inbond = db.INBONDs.SingleOrDefault(u => u.ID == id);
                            if (inbond != null && inbond.BONDERID != loggedinUser.BONDERID)
                            {
                                filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Error", action = "AccessDenied" }));
                            }
                        }
                    }

                    /*if (controllerName.Equals("Back2BackLC"))
                     * {
                     *  if (loggedinUser == null)
                     *  {
                     *      filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Error", action = "AccessDenied" }));
                     *  }
                     *  else
                     *  {
                     *      BACKTOBACKLC back2back = db.BACKTOBACKLCs.SingleOrDefault(u => u.ID == id);
                     *      if (back2back!=null && back2back.BONDERID != loggedinUser.BONDERID)
                     *      {
                     *          filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Error", action = "AccessDenied" }));
                     *      }
                     *  }
                     * }*/

                    if (controllerName.Equals("UP"))
                    {
                        if (loggedinUser == null)
                        {
                            filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Error", action = "AccessDenied" }));
                        }
                    }
                    if (controllerName.Equals("UPRequest"))
                    {
                        if (loggedinUser == null)
                        {
                            filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Error", action = "AccessDenied" }));
                        }
                        else
                        {
                            UPREQUEST uprequest = db.UPREQUESTs.SingleOrDefault(u => u.ID == id);
                            if (uprequest != null && uprequest.BONDERID != loggedinUser.BONDERID)
                            {
                                filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Error", action = "AccessDenied" }));
                            }
                        }
                    }
                }
            }
        }
Beispiel #4
0
        public ActionResult Index(int?page, int filterBonderId = 0, int BONDERID = 0, int STATUSID = 0)
        {
            if (TempData["Message"] != null)
            {
                ViewBag.Message = TempData["Message"].ToString();
                TempData.Remove("Message");
            }

            ViewBag.BONDERID = new SelectList(db.BONDERs, "BONDERSLNO", "BONDERNAME");
            ViewBag.STATUSID = new List <SelectListItem> {
                new SelectListItem {
                    Text = "Approved", Value = "20"
                },
                new SelectListItem {
                    Text = "Pending For Approval", Value = "2"
                },
                new SelectListItem {
                    Text = "Rejected", Value = "10"
                }
            };

            int pageSize   = recordNumbers;
            int pageNumber = (page ?? 1);

            USERPERMISSION loggedinUser = new SessionAttributeRetreival().getStoredUserPermission();
            var            uprequests   = db.UPREQUESTs.OrderByDescending(r => r.ID);

            if (User.IsInRole("Bonder"))
            {
                BONDERID = (int)loggedinUser.BONDERID;
            }

            if (BONDERID == 0 && filterBonderId == 0)
            {
                List <UPREQUEST> request = new List <UPREQUEST>();
                ViewBag.resultofbonderID = BONDERID;
                return(View(request.ToList().ToPagedList(pageNumber, pageSize)));
            }

            if (BONDERID != 0)
            {
                page = 1;
            }
            else
            {
                if (BONDERID == 0)
                {
                    BONDERID = filterBonderId;
                }
            }
            ViewBag.filterBonderId = BONDERID;
            if (loggedinUser.BONDERID > 0)
            {
                ViewBag.resultofbonderID = loggedinUser.BONDERID;
                uprequests = db.UPREQUESTs.Include(e => e.BONDER).Where(e => e.BONDERID == loggedinUser.BONDERID && e.STATUS == STATUSID).OrderBy(e => e.BONDERID).ThenByDescending(e => e.ID);
            }
            else if (BONDERID > 0)
            {
                ViewBag.resultofbonderID = BONDERID;
                uprequests = db.UPREQUESTs.Include(e => e.BONDER).Where(e => e.BONDERID == BONDERID && e.STATUS == STATUSID).OrderBy(e => e.BONDERID).ThenByDescending(e => e.ID);
            }

            if (BONDERID != 0)
            {
                if (loggedinUser.BONDERID > 0)
                {
                    ViewBag.resultofbonderID = loggedinUser.BONDERID;
                    uprequests = db.UPREQUESTs.Include(e => e.BONDER).Where(e => e.BONDERID == loggedinUser.BONDERID && e.STATUS == STATUSID).OrderBy(e => e.BONDERID).ThenByDescending(e => e.ID);
                }
                else if (BONDERID > 0)
                {
                    ViewBag.resultofbonderID = BONDERID;
                    uprequests = db.UPREQUESTs.Include(e => e.BONDER).Where(e => e.BONDERID == BONDERID && e.STATUS == STATUSID).OrderBy(e => e.BONDERID).ThenByDescending(e => e.ID);
                }
            }
            if (loggedinUser != null && loggedinUser.BONDERID != null)
            {
                ViewBag.resultofbonderID = loggedinUser.BONDERID;
                uprequests = uprequests.Where(i => i.BONDERID == loggedinUser.BONDERID && i.STATUS == STATUSID).OrderBy(i => i.BONDER.BONDERNAME).ThenByDescending(i => i.ID);
            }

            return(View(uprequests.ToPagedList(pageNumber, pageSize)));
        }
Beispiel #5
0
        public ActionResult Create(int?page, int BONDERID = 0, int filterBonderId = 0)
        {
            TempData["isAnyAttachment"] = false;
            TempData.Keep();
            ViewBag.BONDERID = new SelectList(db.BONDERs, "BONDERSLNO", "BONDERNAME");
            int            pageSize     = recordNumbers;
            int            pageNumber   = (page ?? 1);
            var            exbonds      = db.EXBONDs.OrderByDescending(b => b.ID).Where(b => b.UPEXBONDLISTs.Count() < 1);
            var            requestType  = this.HttpContext.Request.RequestType;
            USERPERMISSION loggedinUser = new SessionAttributeRetreival().getStoredUserPermission();

            ViewBag.error     = Request.QueryString["error"];
            ViewBag.requestID = (short)0;
            if (BONDERID == 0 && filterBonderId == 0 && !User.IsInRole("Bonder"))
            {
                List <EXBOND> exbond = new List <EXBOND>();
                ViewBag.resultofbonderID = BONDERID;
                return(View("Exbondselector", exbond.ToList().ToPagedList(pageNumber, pageSize)));
            }
            if (BONDERID != 0)
            {
                page = 1;
            }
            else
            {
                if (BONDERID == 0)
                {
                    BONDERID = filterBonderId;
                }
            }
            ViewBag.filterBonderId = BONDERID;


            if (requestType == "GET")
            {
                if (BONDERID > 0)
                {
                    exbonds = db.EXBONDs.Where(u => u.BONDERID == BONDERID && u.UPEXBONDLISTs.Count() < 1).OrderByDescending(r => r.ID);
                    ViewBag.resultofbonderID = BONDERID;
                }
                if (loggedinUser != null && loggedinUser.BONDERID != null)
                {
                    ViewBag.resultofbonderID = loggedinUser.BONDERID;
                    exbonds = exbonds.Where(i => i.BONDERID == loggedinUser.BONDERID && i.UPEXBONDLISTs.Count() < 1).OrderBy(i => i.BONDER.BONDERNAME).ThenByDescending(i => i.ID);
                }
                return(View("Exbondselector", exbonds.ToPagedList(pageNumber, pageSize)));
            }
            else if (requestType == "POST")
            {
                if (BONDERID > 0)
                {
                    ViewBag.resultofbonderID = BONDERID;
                    exbonds = db.EXBONDs.Where(u => u.BONDERID == BONDERID && u.UPEXBONDLISTs.Count() < 1).OrderByDescending(r => r.ID);
                }
            }
            if (loggedinUser != null && loggedinUser.BONDERID != null)
            {
                ViewBag.resultofbonderID = loggedinUser.BONDERID;
                exbonds = exbonds.Where(i => i.BONDERID == loggedinUser.BONDERID && i.UPEXBONDLISTs.Count() < 1).OrderBy(i => i.BONDER.BONDERNAME).ThenByDescending(i => i.ID);
            }
            return(View("Exbondselector", exbonds.ToPagedList(pageNumber, pageSize)));
        }
Beispiel #6
0
        public ActionResult Index(int?page, string FromDate, string ToDate, int BONDERID = 0)
        {
            ViewBag.BONDERID = new SelectList(db.BONDERs, "BONDERSLNO", "BONDERNAME");
            List <ANNUALENTLRAWMATERIAL> aerawmaterials = new List <ANNUALENTLRAWMATERIAL>();
            int            pageSize     = recordNumbers;
            int            pageNumber   = (page ?? 1);
            USERPERMISSION loggedinUser = new SessionAttributeRetreival().getStoredUserPermission();

            if (BONDERID == 0 && !User.IsInRole("Bonder"))
            {
                ViewBag.resultofbonderID = BONDERID;
                return(View(aerawmaterials.ToList().ToPagedList(pageNumber, pageSize)));
            }
            if (loggedinUser != null && loggedinUser.BONDERID != null)
            {
                BONDERID = (int)loggedinUser.BONDERID;
            }
            var annualentlrawmaterials = db.ANNUALENTLRAWMATERIALs.Include(a => a.MATERIAL).Include(a => a.MEASUREMENTUNIT);

            if ((FromDate == String.Empty || ToDate == String.Empty) && BONDERID != 0)
            {
                BONDREGISTRATION registrationInfo = db.BONDREGISTRATIONs.Where(br => br.BONDERSLNO == BONDERID).SingleOrDefault();
                FromDate = registrationInfo.ISSUEDATE.ToString();
                ToDate   = registrationInfo.EXPIRYDATE.ToString();
            }
            if ((FromDate != null && FromDate != String.Empty) && (ToDate != null && ToDate != String.Empty) && BONDERID != 0)
            {
                DateTime fromAEDate = Convert.ToDateTime(FromDate);
                DateTime toAEDate   = Convert.ToDateTime(ToDate);
                annualentlrawmaterials = annualentlrawmaterials.Where(ae => ae.BONDERSLNO == BONDERID);
                if (annualentlrawmaterials != null)
                {
                    foreach (var item in annualentlrawmaterials.ToList())
                    {
                        var bonderAE = db.BONDERANNUALENTITLEMENTs.Where(bae => bae.AESLNO == item.AESLNO && bae.BONDERSLNO == item.BONDERSLNO && bae.ENTITLEFROM >= fromAEDate && bae.ENTITLETO <= toAEDate).Select(bae => new
                        {
                            From = bae.ENTITLEFROM,
                            To   = bae.ENTITLETO
                        }).SingleOrDefault();
                        if (bonderAE != null && bonderAE.From != null && bonderAE.To != null)
                        {
                            item.ENTITLEFROM = bonderAE.From;
                            item.ENTITLETO   = bonderAE.To;
                            aerawmaterials.Add(item);
                        }
                    }
                }
                ViewBag.resultofbonderID    = BONDERID;
                ViewBag.CurrentFilterFrDate = FromDate;
                ViewBag.CurrentFilterToDate = ToDate;
            }
            else if ((FromDate == String.Empty || ToDate == String.Empty) && BONDERID != 0)
            {
                annualentlrawmaterials = annualentlrawmaterials.Where(ae => ae.BONDERSLNO == BONDERID);
                foreach (var item in annualentlrawmaterials.ToList())
                {
                    var bonderAE = db.BONDERANNUALENTITLEMENTs.Where(bae => bae.AESLNO == item.AESLNO && bae.BONDERSLNO == item.BONDERSLNO).Select(bae => new
                    {
                        From = bae.ENTITLEFROM,
                        To   = bae.ENTITLETO
                    }).FirstOrDefault();
                    if (bonderAE != null && bonderAE.From != null && bonderAE.To != null)
                    {
                        item.ENTITLEFROM = bonderAE.From;
                        item.ENTITLETO   = bonderAE.To;
                        aerawmaterials.Add(item);
                    }
                }
                ViewBag.resultofbonderID    = BONDERID;
                ViewBag.CurrentFilterFrDate = FromDate;
                ViewBag.CurrentFilterToDate = ToDate;
            }
            ViewBag.BONDERID = new SelectList(db.BONDERs, "BONDERSLNO", "BONDERNAME", ViewBag.resultofbonderID);
            return(View(aerawmaterials.ToPagedList(pageNumber, pageSize)));
        }
Beispiel #7
0
        public ActionResult Index(int?page, int filterBonderId = 0, int BONDERID = 0)
        {
            int pageSize               = recordNumbers;
            int pageNumber             = (page ?? 1);
            var annualentlrawmaterials = db.ANNUALENTLRAWMATERIALs.Include(a => a.MATERIAL).Include(a => a.MEASUREMENTUNIT);

            ViewBag.BONDERID = new SelectList(db.BONDERs, "BONDERSLNO", "BONDERNAME");
            if (BONDERID == 0 && filterBonderId == 0 && !User.IsInRole("Bonder"))
            {
                List <ANNUALENTLRAWMATERIAL> aerawmaterials = new List <ANNUALENTLRAWMATERIAL>();
                ViewBag.resultofbonderID = BONDERID;
                return(View(aerawmaterials.ToList().ToPagedList(pageNumber, pageSize)));
            }

            USERPERMISSION loggedinUser = new SessionAttributeRetreival().getStoredUserPermission();

            if (BONDERID != 0)
            {
                page = 1;
            }
            else
            {
                if (BONDERID == 0)
                {
                    BONDERID = filterBonderId;
                }
            }
            ViewBag.filterBonderId = BONDERID;
            if (loggedinUser != null && loggedinUser.BONDERID > 0)
            {
                ViewBag.resultofbonderID = loggedinUser.BONDERID;
                annualentlrawmaterials   = db.ANNUALENTLRAWMATERIALs.Include(a => a.MATERIAL).Include(a => a.MEASUREMENTUNIT).Where(e => e.BONDERSLNO == loggedinUser.BONDERID);
            }
            else if (BONDERID > 0)
            {
                ViewBag.resultofbonderID = BONDERID;
                annualentlrawmaterials   = db.ANNUALENTLRAWMATERIALs.Include(a => a.MATERIAL).Include(a => a.MEASUREMENTUNIT).Where(e => e.BONDERSLNO == BONDERID);
            }

            if (BONDERID != 0)
            {
                if (loggedinUser.BONDERID > 0)
                {
                    ViewBag.resultofbonderID = loggedinUser.BONDERID;
                    annualentlrawmaterials   = db.ANNUALENTLRAWMATERIALs.Include(a => a.MATERIAL).Include(a => a.MEASUREMENTUNIT).Where(e => e.BONDERSLNO == loggedinUser.BONDERID);
                }
                else if (BONDERID > 0)
                {
                    ViewBag.resultofbonderID = BONDERID;
                    annualentlrawmaterials   = db.ANNUALENTLRAWMATERIALs.Include(a => a.MATERIAL).Include(a => a.MEASUREMENTUNIT).Where(e => e.BONDERSLNO == BONDERID);
                }
            }
            if (loggedinUser != null && loggedinUser.BONDERID != null)
            {
                ViewBag.resultofbonderID = loggedinUser.BONDERID;
                annualentlrawmaterials   = annualentlrawmaterials.Where(i => i.BONDERSLNO == loggedinUser.BONDERID);
            }
            foreach (var item in annualentlrawmaterials.ToList())
            {
                var bonderAE = db.BONDERANNUALENTITLEMENTs.Where(bae => bae.AESLNO == item.AESLNO && bae.BONDERSLNO == item.BONDERSLNO).Select(bae => new
                {
                    From = bae.ENTITLEFROM,
                    To   = bae.ENTITLETO
                }).Single();

                item.ENTITLEFROM = bonderAE.From;
                item.ENTITLETO   = bonderAE.To;
            }
            ViewBag.BONDERID = new SelectList(db.BONDERs, "BONDERSLNO", "BONDERNAME", ViewBag.resultofbonderID);
            return(View(annualentlrawmaterials.ToList().ToPagedList(pageNumber, pageSize)));
        }
Beispiel #8
0
        public ActionResult Index(string LCNo, string FromDate, string ToDate, string currentFilterLC, String currentFilterFrDate, String currentFilterToDate, int?page, int filterBonderId = 0, int BONDERID = 0)
        {
            if (TempData["Message"] != null)
            {
                ViewBag.Message = TempData["Message"].ToString();
                TempData.Remove("Message");
            }

            var requestType = this.HttpContext.Request.RequestType;

            System.Diagnostics.Debug.WriteLine("requestType = " + requestType);
            USERPERMISSION loggedinUser  = new SessionAttributeRetreival().getStoredUserPermission();
            var            backtobacklcs = db.BACKTOBACKLCs.OrderByDescending(b => b.ID).Include(b => b.BANKBRANCH).Include(b => b.BANK).Include(b => b.BONDER);
            int            pageSize      = recordNumbers;
            int            pageNumber    = (page ?? 1);

            if (LCNo != null || FromDate != null || ToDate != null || BONDERID != 0)
            {
                page = 1;
            }
            else
            {
                if (LCNo == null)
                {
                    LCNo = currentFilterLC;
                }
                if (FromDate == null)
                {
                    FromDate = currentFilterFrDate;
                }
                if (ToDate == null)
                {
                    ToDate = currentFilterToDate;
                }
                if (BONDERID == 0)
                {
                    BONDERID = filterBonderId;
                }
            }
            ViewBag.CurrentFilterLC     = LCNo;
            ViewBag.CurrentFilterFrDate = FromDate;
            ViewBag.CurrentFilterToDate = ToDate;
            ViewBag.filterBonderId      = BONDERID;
            ViewBag.BONDERID            = new SelectList(db.BONDERs, "BONDERSLNO", "BONDERNAME");
            if ("GET" == requestType)
            {
                if (LCNo != null || FromDate != null || ToDate != null || BONDERID != 0)
                {
                    ViewBag.resultofbonderID = BONDERID;
                    backtobacklcs            = GetBackToBackRolesBySearchCriterial(LCNo, FromDate, ToDate, loggedinUser, BONDERID);
                }
                if (loggedinUser != null && loggedinUser.BONDERID != null)
                {
                    ViewBag.resultofbonderID = loggedinUser.BONDERID;
                    backtobacklcs            = backtobacklcs.Where(i => i.BONDERID == loggedinUser.BONDERID).OrderByDescending(b => b.ID).Include(b => b.BANKBRANCH).Include(b => b.BANK).Include(b => b.BONDER);
                }
                else if (BONDERID == 0 && filterBonderId == 0 && !User.IsInRole("Bonder"))
                {
                    ViewBag.resultofbonderID = BONDERID;
                    List <BACKTOBACKLC> backtobacklc = new List <BACKTOBACKLC>();
                    return(View(backtobacklc.ToPagedList(pageNumber, pageSize)));
                }

                return(View(backtobacklcs.ToList().ToPagedList(pageNumber, pageSize)));
            }
            else if ("POST" == requestType)
            {
                if (BONDERID == 0 && filterBonderId == 0 && !User.IsInRole("Bonder"))
                {
                    ViewBag.resultofbonderID = BONDERID;
                    List <BACKTOBACKLC> backtobacklc = new List <BACKTOBACKLC>();
                    return(View(backtobacklc.ToPagedList(pageNumber, pageSize)));
                }
                if (!string.IsNullOrEmpty(LCNo))
                {
                    LCNo = LCNo.Trim();
                }
                System.Diagnostics.Debug.WriteLine("LCNo = " + LCNo + ", FromDate = " + FromDate + ", ToDate = " + ToDate);

                if (LCNo.Equals(String.Empty) && FromDate.Equals(String.Empty) && ToDate.Equals(String.Empty))
                {
                    System.Diagnostics.Debug.WriteLine("if");
                }
                else if ((LCNo != null && !LCNo.Equals(String.Empty)) && (FromDate != null && !FromDate.Equals(String.Empty)) && (ToDate != null && !ToDate.Equals(String.Empty)))
                {
                    System.Diagnostics.Debug.WriteLine("else if 1");
                    DateTime fromLCDate = Convert.ToDateTime(FromDate);
                    DateTime toLCDate   = Convert.ToDateTime(ToDate);
                    backtobacklcs = backtobacklcs.Where(b => b.LCNUMBER.Contains(LCNo) && (b.LCDATE >= fromLCDate && b.LCDATE <= toLCDate)).Include(b => b.BANKBRANCH).OrderByDescending(b => b.ID);
                }
                else if ((FromDate != null && !FromDate.Equals(String.Empty)) && (ToDate != null && !ToDate.Equals(String.Empty)))
                {
                    System.Diagnostics.Debug.WriteLine("else if 2");
                    DateTime fromLCDate = Convert.ToDateTime(FromDate);
                    DateTime toLCDate   = Convert.ToDateTime(ToDate);
                    backtobacklcs = backtobacklcs.Where(b => (b.LCDATE >= fromLCDate && b.LCDATE <= toLCDate)).Include(b => b.BANKBRANCH).OrderByDescending(b => b.ID);
                }
                else if (LCNo != null && !LCNo.Equals(String.Empty))
                {
                    System.Diagnostics.Debug.WriteLine("else if 3");
                    backtobacklcs = backtobacklcs.Where(b => b.LCNUMBER.Contains(LCNo)).Include(b => b.BANKBRANCH).OrderByDescending(b => b.ID);
                }
                else if (FromDate != null && !FromDate.Equals(String.Empty))
                {
                    System.Diagnostics.Debug.WriteLine("else if 4");
                    DateTime fromLCDate = Convert.ToDateTime(FromDate);
                    backtobacklcs = backtobacklcs.Where(b => b.LCDATE >= fromLCDate).OrderByDescending(b => b.ID);
                }
                else if (ToDate != null && !ToDate.Equals(String.Empty))
                {
                    System.Diagnostics.Debug.WriteLine("else if 5");
                    DateTime toLCDate = Convert.ToDateTime(ToDate);
                    backtobacklcs = backtobacklcs.Where(b => b.LCDATE <= toLCDate).OrderByDescending(b => b.ID);
                }
                if (loggedinUser.BONDERID > 0)
                {
                    ViewBag.resultofbonderID = loggedinUser.BONDERID;
                    backtobacklcs            = backtobacklcs.Where(e => e.BONDERID == loggedinUser.BONDERID).OrderByDescending(b => b.ID);
                }
                else if (BONDERID > 0)
                {
                    ViewBag.resultofbonderID = BONDERID;
                    backtobacklcs            = backtobacklcs.Where(e => e.BONDERID == BONDERID).OrderByDescending(b => b.ID);
                }
                if (loggedinUser != null && loggedinUser.BONDERID != null)
                {
                    ViewBag.resultofbonderID = loggedinUser.BONDERID;
                    backtobacklcs            = backtobacklcs.Where(i => i.BONDERID == loggedinUser.BONDERID).OrderByDescending(b => b.ID).Include(b => b.BANKBRANCH).Include(b => b.BANK).Include(b => b.BONDER);
                }
            }
            else
            {
                // Error handel
            }
            pageSize   = recordNumbers;
            pageNumber = (page ?? 1);

            return(View(backtobacklcs.ToPagedList(pageNumber, pageSize)));
        }