public ActionResult addMoreExbond(short id, int?page) { List <EXBOND> exbondList = new List <EXBOND>(); UPREQUEST uprequest = db.UPREQUESTs.Find(id); bool flag = false; int id1 = uprequest.BONDER.BONDERSLNO; ViewBag.resultofbonderID = uprequest.BONDER.BONDERSLNO; ViewBag.BONDERID = new SelectList(db.BONDERs, "BONDERSLNO", "BONDERNAME", uprequest.BONDER.BONDERNAME); var b2b = db.EXBONDs.Where(eb => eb.BONDERID == id1 && (eb.UPEXBONDLISTs.Count() < 1)).ToList(); for (int i = 0; i < b2b.Count(); i++) { EXBOND b2blc = db.EXBONDs.Find(b2b[i].ID); if (b2blc != null && b2blc.EXBONDBACKTOBACKs.Count() >= 1) { flag = true; exbondList.Add(b2blc); } } if (!flag) { return(RedirectToAction("Edit/" + id, new { error = "Sorry! There is no more Exbond exist to add for this bonder" })); } ViewBag.requestID = id; int pageSize = recordNumbers; int pageNumber = (page ?? 1); return(View("Exbondselector", exbondList.ToPagedList(pageNumber, pageSize))); }
public ActionResult addMoreAttachment(short id, int?page, string errorMessage) { List <EXBOND> exbondList = new List <EXBOND>(); UPREQUEST uprequest = db.UPREQUESTs.Find(id); int id1 = uprequest.BONDER.BONDERSLNO; var b2b = db.EXBONDs.Where(eb => eb.BONDERID == id1 && (eb.UPEXBONDLISTs.Count() < 1)).ToList(); for (int i = 0; i < b2b.Count(); i++) { EXBOND b2blc = db.EXBONDs.Find(b2b[i].ID); if (b2blc != null && b2blc.EXBONDBACKTOBACKs.Count() >= 1) { exbondList.Add(b2blc); } } ViewBag.requestID = id; ViewBag.resultofbonderID = id1; int pageSize = recordNumbers; int pageNumber = (page ?? 1); ViewBag.BONDERID = new SelectList(db.BONDERs, "BONDERSLNO", "BONDERSLNO"); if (errorMessage != null && !errorMessage.Trim().Equals("")) { ModelState.AddModelError("fileError", errorMessage); return(View("Exbondselector", exbondList.ToPagedList(pageNumber, pageSize))); } return(View("Exbondselector", exbondList.ToPagedList(pageNumber, pageSize))); }
public ActionResult Edit(short id = 0) { TempData["isAnyAttachment"] = true; TempData.Keep(); UPREQUEST uprequest = db.UPREQUESTs.Find(id); if (uprequest == null) { return(HttpNotFound()); } IList <EXBOND> exbondList = new List <EXBOND>(); IList <ATTACHMENT> attachmentList = new List <ATTACHMENT>(); var upUxbond = db.UPEXBONDLISTs.Where(eb => eb.UPREQUESTID == id).ToList(); for (int i = 0; i < upUxbond.Count(); i++) { EXBOND exbond = db.EXBONDs.Find(upUxbond[i].EXBONDID); exbondList.Add(exbond); } var attachments = db.ATTACHMENTs.Where(eb => eb.UPREQUESTID == id).ToList(); ViewBag.requestID = id; ViewBag.error = Request.QueryString["error"]; UpAttachmentViewModel viewModel = new UpAttachmentViewModel(); viewModel.ATTACHMENTs = attachments; viewModel.EXBONDs = exbondList; return(View(viewModel)); }
public ActionResult addMoreB2BLC(short id, int?page) { USERPERMISSION loggedinUser = sessionAttributeRetreival.getStoredUserPermission(); List <BACKTOBACKLC> b2bList = new List <BACKTOBACKLC>(); EXBOND exbond = db.EXBONDs.Find(id); int id1 = exbond.BONDER.BONDERSLNO; bool flag = false; var b2b = db.BACKTOBACKLCs.Where(eb => eb.BONDERID == id1 && (eb.BACKTOBACKPRODUCTs.Count() > 0)).ToList(); for (int i = 0; i < b2b.Count(); i++) { BACKTOBACKLC b2blc = db.BACKTOBACKLCs.Find(b2b[i].ID); if (b2blc != null && b2blc.EXBONDBACKTOBACKs.Count() < 1) { flag = true; b2bList.Add(b2blc); } } if (!flag) { return(RedirectToAction("Edit/" + id, new { error = "Sorry! There is no more Back to Back LC exist for this bonder" })); } ViewBag.ExbondID = id; ViewBag.resultofbonderID = exbond.BONDERID; ViewBag.BONDERID = new SelectList(db.BONDERs, "BONDERSLNO", "BONDERNAME", exbond.BONDER.BONDERNAME); int pageSize = recordNumbers; int pageNumber = (page ?? 1); return(View("Lcselector", b2bList.ToPagedList(pageNumber, pageSize))); // return View("Lcselector", b2bList); }
public ActionResult Delete(short id = 0) { EXBOND exbond = db.EXBONDs.Find(id); if (exbond == null) { return(HttpNotFound()); } return(View(exbond)); }
public ActionResult Save(short id) { EXBOND exbond = db.EXBONDs.Find(id); if (exbond.EXBONDBACKTOBACKs.Count() < 1) { db.EXBONDs.Remove(exbond); db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Edit(EXBOND exbond) { if (ModelState.IsValid) { db.Entry(exbond).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.BONDERID = new SelectList(db.BONDERs, "BONDERSLNO", "BONDERSLNO", exbond.BONDERID); return(View(exbond)); }
public ActionResult DeleteConfirmed(short id) { var childData = db.EXBONDBACKTOBACKs.Where(eb => eb.EXBONDID == id).ToList(); foreach (var data in childData) { db.EXBONDBACKTOBACKs.Remove(data); } EXBOND exbond = db.EXBONDs.Find(id); TempData["Message"] = string.Format("ExBond deleted successfully, Which Bonder Name was {0}", exbond.BONDER.BONDERNAME); db.EXBONDs.Remove(exbond); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit(short id = 0) { EXBOND exbond = db.EXBONDs.Find(id); if (exbond == null) { return(HttpNotFound()); } IList <BACKTOBACKLC> b2bList = new List <BACKTOBACKLC>(); var exbondb2b = db.EXBONDBACKTOBACKs.Where(eb => eb.EXBONDID == id).Select(u => new { ID = u.BACKTOBACKID }).ToList(); for (int i = 0; i < exbondb2b.Count(); i++) { BACKTOBACKLC b2blc = db.BACKTOBACKLCs.Find(exbondb2b[i].ID); b2bList.Add(b2blc); } ViewBag.ExbondID = id; ViewBag.BONDERID = new SelectList(db.BONDERs, "BONDERSLNO", "BONDERSLNO", exbond.BONDERID); return(View(b2bList)); }
public ActionResult Details(short id = 0) { ApprovedUPViewModel viewModel = new ApprovedUPViewModel(); UP up = db.UPs.Find(id); if (up == null) { return(HttpNotFound()); } List <UPREQUEST> uprequestList = new List <UPREQUEST>(); List <EXBOND> exbondList = new List <EXBOND>(); List <BACKTOBACKLC> b2bList = new List <BACKTOBACKLC>(); List <BACKTOBACKPRODUCT> productList = new List <BACKTOBACKPRODUCT>(); List <RAWMATERIAL> rawmaterialList = new List <RAWMATERIAL>(); List <ATTACHMENT> attachments = new List <ATTACHMENT>(); var uprequests = db.UPREQUESTLISTs.Where(eb => eb.UPID == id).ToList(); for (int i = 0; i < uprequests.Count(); i++) { UPREQUEST uprequest = db.UPREQUESTs.Find(uprequests[i].UPREQUESTID); if (uprequest != null) { for (int j = 0; j < uprequest.UPEXBONDLISTs.Count(); j++) { EXBOND exbond = db.EXBONDs.Find(uprequest.UPEXBONDLISTs[j].EXBONDID); if (exbond != null) { for (int k = 0; k < exbond.EXBONDBACKTOBACKs.Count(); k++) { BACKTOBACKLC backtoback = db.BACKTOBACKLCs.Find(exbond.EXBONDBACKTOBACKs.ElementAt(k).BACKTOBACKID); if (backtoback != null) { for (int l = 0; l < backtoback.BACKTOBACKPRODUCTs.Count(); l++) { BACKTOBACKPRODUCT product = db.BACKTOBACKPRODUCTs.Find(backtoback.BACKTOBACKPRODUCTs[l].ID); if (product != null) { if (product.RAWMATERIALs.Count() > 0) { rawmaterialList = product.RAWMATERIALs.ToList(); } productList.Add(product); } } b2bList.Add(backtoback); } } exbondList.Add(exbond); } } if (uprequest.ATTACHMENTs.Count() > 0) { attachments = uprequest.ATTACHMENTs.ToList(); } uprequestList.Add(uprequest); } } viewModel.UP = up; viewModel.UPREQUESTs = uprequestList; viewModel.BACKTOBACKLCs = b2bList; viewModel.BACKTOBACKPRODUCTs = productList; viewModel.EXBONDs = exbondList; viewModel.RAWMATERIALs = rawmaterialList; viewModel.ATTACHMENTs = attachments; return(View(viewModel)); }
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" })); } } } } } }
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)); } } }
public ActionResult CreateorEditExbond(IList <BACKTOBACKLC> backtobacklcs, short ID = 0) { USERPERMISSION loggedinUser = sessionAttributeRetreival.getStoredUserPermission(); IList <BACKTOBACKLC> b2bList = new List <BACKTOBACKLC>(); EXBOND exbond = new EXBOND(); if (backtobacklcs == null) { return(RedirectToAction("Create", new { error = "Please select at least one back to back lc" })); } bool flag = true; bool isanyselected = false; for (int i = 0; i < backtobacklcs.Count(); i++) { int id = backtobacklcs[i].ID; if (backtobacklcs[i].IsSelected) { isanyselected = true; BACKTOBACKLC back2backlc = db.BACKTOBACKLCs.Find(id); int productCount = back2backlc.BACKTOBACKPRODUCTs.Count(); if (productCount < 1) { flag = false; } else { exbond.BONDERID = backtobacklcs[i].BONDER.BONDERSLNO; b2bList.Add(back2backlc); } } } if (!isanyselected && ID <= 0) { return(RedirectToAction("Create", new { error = "Please select at least one back to back lc" })); } if (!flag && ID <= 0) { return(RedirectToAction("Create", new { error = "Sorry! please check all selected LC has at least one product" })); } else { short lastInserted = 0; //if (ModelState.IsValid) //{ if (ID <= 0) //add new exbond { if (loggedinUser != null) { exbond.CREATEDBY = loggedinUser.APPUSER.USERNAME; } //else //{ // exbond.CREATEDBY = "" + loggedinUser.USERID; //} exbond.CREATEDDATE = DateTime.Today; db.EXBONDs.Add(exbond); try { db.SaveChanges(); } catch (Exception e) { Console.WriteLine(e.ToString()); } lastInserted = db.EXBONDs.Max(item => item.ID); } else //edit new exbond { using (var db2 = new OracleEntitiesConnStr()) { exbond = db.EXBONDs.Find(ID); EXBOND newExbond = new EXBOND(); newExbond.ID = ID; newExbond.BONDERID = exbond.BONDERID; newExbond.DESCRIPTION = exbond.DESCRIPTION; if (loggedinUser != null) { newExbond.MODIFIEDBY = loggedinUser.APPUSER.USERNAME; } newExbond.MODIFIEDDATE = DateTime.Today; newExbond.CREATEDDATE = exbond.CREATEDDATE; newExbond.CREATEDBY = exbond.CREATEDBY; db2.Entry(newExbond).State = EntityState.Modified; db2.SaveChanges(); } lastInserted = ID; } for (int x = 0; x < b2bList.Count(); x++) { using (var db1 = new OracleEntitiesConnStr()) { EXBONDBACKTOBACK exbondb2b = new EXBONDBACKTOBACK(); exbondb2b.BACKTOBACKID = b2bList[x].ID; exbondb2b.EXBONDID = lastInserted; db1.EXBONDBACKTOBACKs.Add(exbondb2b); db1.SaveChanges(); } } // } if (ID <= 0) { return(RedirectToAction("Index")); } else { return(RedirectToAction("Edit/" + ID)); } } }