public ActionResult FileUpload(FormCollection formCollection) { using (BTCEntities db = new BTCEntities()) { string attachmentsForVal = "Unknown", retrunToVal = "Index"; string IDVal = ""; int QuoteID = Convert.ToInt32(formCollection["QuotationID"]); int ID = Convert.ToInt32(formCollection["ID"]); if (Request.Files != null && Request.Files.Count > 0) { string fileName = string.Empty; string destinationPath = string.Empty; List <Attachments> uploadFileModel = new List <Attachments>(); SetQuotation(pageNo, ID, out attachmentsForVal, out IDVal, out retrunToVal); fileName = Path.GetFileName(Request.Files[0].FileName); destinationPath = Path.Combine(Server.MapPath("~/UploadedFiles/" + attachmentsForVal) + "/", fileName); Directory.CreateDirectory(Server.MapPath("~/UploadedFiles/" + attachmentsForVal)); Request.Files[0].SaveAs(destinationPath); var isFileNameRepete = (db.Attachments.AsEnumerable().Where(x => x.FileName == fileName).ToList()); if (isFileNameRepete == null || isFileNameRepete.Count <= 0) { Attachments attachments = new Attachments { FileName = fileName, FileType = Request.Files[0].ContentType, FilePath = destinationPath, UploadedDate = DateTime.Now, UploadedBy = dbuser.ID }; db.Attachments.Add(attachments); db.SaveChanges(); AttachmentLink attachmentLink = new AttachmentLink { AttachmentFor = attachmentsForVal, AttachmentForID = attachments.ID }; db.AttachmentLink.Add(attachmentLink); db.SaveChanges(); ViewBag.SuccessMessage = "File Uploaded Successfully"; } else { ViewBag.WarningMessage = "File is already exists"; } } ViewBag.fileUploader = db.AttachmentLink.Where(a => a.AttachmentFor.Contains(attachmentsForVal)).Select(x => x.Attachments).Include(a => a.AttachmentLink).Include(a => a.Users)?.ToList(); switch (pageNo) { case 1: return(RedirectToAction(retrunToVal, new { QuoteID, atquoteID = ID })); case 2: return(RedirectToAction(retrunToVal, new { QuoteID, hsquoteID = ID })); case 3: return(RedirectToAction(retrunToVal, new { QuoteID, pcquoteID = ID })); default: return(RedirectToAction(retrunToVal, new { QuoteID })); } } }
public ActionResult Create([Bind(Include = "Cust_Code,Cust_Name,Cust_City,Working_Area,Cust_Country,Grade,Opening_Amt,Receive_Amt,Payment_Amt,Outstanding_Amt,Phone_No,Agent_Code")] Customer customer) { if (ModelState.IsValid) { db.Customers.Add(customer); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Agent_Code = new SelectList(db.Agents, "Agent_Code", "Agent_Name", customer.Agent_Code); return(View(customer)); }
public ActionResult RemoveRFQ(int?id) { using (BTCEntities db = new BTCEntities()) { RFQ rfqlist = db.RFQ.Where(a => a.ID == id).FirstOrDefault(); if (ModelState.IsValid) { rfqlist.IsDeleted = true; db.RFQ.Attach(rfqlist); var entry = db.Entry(rfqlist); entry.Property(a => a.IsDeleted).IsModified = true; db.SaveChanges(); } else { var errlist = ModelState.Values.Where(e => e.Errors.Count > 0).Select(a => a.Errors); List <string> sberr = new List <string>(); foreach (var item in errlist) { sberr.Add(item[0].ErrorMessage); } TempData["ErrorMessage"] = sberr.ToList(); } int TravelRequestID = rfqlist.TravelRequestID.Value; return(RedirectToAction("RFQProcessing", new { id = TravelRequestID })); } }
public ActionResult LPOCreation(string id) { try { int i = Convert.ToInt32(id); if (i > 0) { using (BTCEntities db = new BTCEntities()) { var lpodata = db.LPO.Where(a => a.QuotationID == i).FirstOrDefault(); if (lpodata.IsDeleted == null || (bool)lpodata.IsDeleted) { lpodata.IsDeleted = false; db.Entry(lpodata).State = EntityState.Modified; db.LPO.Attach(lpodata); db.Entry(lpodata).Property(x => x.IsDeleted).IsModified = true; db.SaveChanges(); var rfq = db.RFQ.Where(a => a.ID == lpodata.RFQID).FirstOrDefault(); rfq.Processing = (int)ProcessingStatus.Processed; var travelreq = db.TravelRequests.Where(a => a.ID == rfq.TravelRequestID).FirstOrDefault(); travelreq.ApprovalLevel = (int)ApprovalLevels.ApprovedbyTravelCo; db.Configuration.ValidateOnSaveEnabled = false; db.SaveChanges(); } return(Json("LPO Successfully Created", JsonRequestBehavior.AllowGet)); } } else { return(Json("LPO Creation Failed", JsonRequestBehavior.AllowGet)); } } catch (Exception) { return(Json("LPO Creation Failed", JsonRequestBehavior.AllowGet)); throw; } }
public ActionResult FileUpload(FormCollection formCollection) { using (BTCEntities db = new BTCEntities()) { if (Request.Files != null && Request.Files.Count > 0) { string fileName = string.Empty; string destinationPath = string.Empty; List <Attachments> uploadFileModel = new List <Attachments>(); fileName = Path.GetFileName(Request.Files[0].FileName); if (formCollection.AllKeys.Contains("RFQname") && !string.IsNullOrEmpty(formCollection["RFQname"].ToString()) && formCollection.AllKeys.Contains("RFQSections") && !string.IsNullOrEmpty(formCollection["RFQSections"].ToString())) { destinationPath = Path.Combine(Server.MapPath("~/UploadedFiles/" + MasterRFQ.RFQName + "Pro" + MasterRFQ.ProcessingSection + "Trav" + MasterRFQ.TravelAgencyID) + "/", fileName); Directory.CreateDirectory(Server.MapPath("~/UploadedFiles/" + MasterRFQ.RFQName + "Pro" + MasterRFQ.ProcessingSection + "Trav" + MasterRFQ.TravelAgencyID)); Request.Files[0].SaveAs(destinationPath); var isFileNameRepete = (db.Attachments.AsEnumerable().Where(x => x.FileName == destinationPath).ToList()); if (isFileNameRepete == null || isFileNameRepete.Count <= 0) { Attachments attachments = new Attachments { FileName = fileName, FileType = Request.Files[0].ContentType, FilePath = destinationPath, UploadedDate = DateTime.Now, UploadedBy = dbuser.ID }; db.Attachments.Add(attachments); db.SaveChanges(); AttachmentLink attachmentLink = new AttachmentLink { AttachmentFor = formCollection["RFQname"].ToString() + "Pro" + formCollection["RFQSections"].ToString() + "Trav" + MasterRFQ.TravelAgencyID, AttachmentForID = attachments.ID }; db.AttachmentLink.Add(attachmentLink); db.SaveChanges(); ViewBag.SuccessMessage = "File Uploaded Successfully"; } else { ViewBag.WarningMessage = "File is already exists"; } } } ViewBag.fileUploader = db.AttachmentLink.Where(a => a.AttachmentFor == (MasterRFQ.RFQName + "Pro" + MasterRFQ.ProcessingSection + "Trav" + MasterRFQ.TravelAgencyID)).Select(x => x.Attachments).ToList(); return(RedirectToAction("PreviewRFQ", new { id = MasterRFQ.ID })); } }
public ActionResult DeleteATQuotation(int id) { using (BTCEntities db = new BTCEntities()) { var dbatquote = db.ATQuotation.Find(id); dbatquote.IsDeleted = true; db.ATQuotation.Attach(dbatquote); var entry = db.Entry(dbatquote); entry.Property(a => a.IsDeleted).IsModified = true; db.SaveChanges(); return(RedirectToAction("AddQuotation", new { id = dbatquote.Quotation.RFQID })); } }
public ActionResult DeleteRFQProcessing(int id) { using (BTCEntities db = new BTCEntities()) { var rfqVal = db.RFQ.Where(a => a.ID == id).FirstOrDefault(); var travelRequestID = rfqVal.TravelRequestID; rfqVal.IsDeleted = true; db.RFQ.Add(rfqVal); db.Entry(rfqVal).State = EntityState.Modified; db.SaveChanges(); ViewBag.SuccessMessage = "Entry Marked for Deletion"; if (db.RFQ.Where(a => a.TravelRequestID == travelRequestID && a.Processing == 0 && a.IsDeleted == false).Count() <= 0) { return(RedirectToAction("RFQProcessing", new { id = travelRequestID })); } return(RedirectToAction("RFQMerger", new { id = rfqVal.TravelRequestID })); } }
public ActionResult RemoveUploadFile(string fileName, FormCollection formCollection) { using (BTCEntities db = new BTCEntities()) { string attachmentsForVal = "Unknown", retrunToVal = "Index"; string IDVal = ""; int QuoteID = Convert.ToInt32(formCollection["QuotationID"]); int ID = Convert.ToInt32(formCollection["ID"]); if (fileName != null && fileName != string.Empty) { var dbfile = db.Attachments.Include(a => a.AttachmentLink).Include(a => a.Users).Where(x => x.FileName == fileName).FirstOrDefault(); db.AttachmentLink.RemoveRange(dbfile.AttachmentLink); db.Attachments.Remove(dbfile); db.SaveChanges(); SetQuotation(pageNo, ID, out attachmentsForVal, out IDVal, out retrunToVal); FileInfo file = new FileInfo(Server.MapPath("~/UploadedFiles/" + fileName)); if (file.Exists) { file.Delete(); } ViewBag.SuccessMessage = "File Deleted Successfully"; } ViewBag.fileUploader = db.AttachmentLink.Where(a => a.AttachmentFor.Contains(attachmentsForVal)).Select(x => x.Attachments).Include(a => a.AttachmentLink).Include(a => a.Users)?.ToList(); switch (pageNo) { case 1: return(RedirectToAction(retrunToVal, new { QuoteID, atquoteID = ID })); case 2: return(RedirectToAction(retrunToVal, new { QuoteID, hsquoteID = ID })); case 3: return(RedirectToAction(retrunToVal, new { QuoteID, pcquoteID = ID })); default: return(RedirectToAction(retrunToVal, new { QuoteID })); } } }
public ActionResult DeleteRFQ(int?id) { using (BTCEntities db = new BTCEntities()) { RFQ rfqitem = db.RFQ.Include(a => a.TravelRequests).Include(a => a.TravelAgency).Include(a => a.Users).Where(a => a.ID == id).FirstOrDefault(); if (ModelState.IsValid) { rfqitem.IsDeleted = true; db.RFQ.Attach(rfqitem); var entry = db.Entry(rfqitem); entry.Property(a => a.IsDeleted).IsModified = true; db.SaveChanges(); return(RedirectToAction("Index")); } else { var errlist = ModelState.Values.Where(e => e.Errors.Count > 0).Select(a => a.Errors); List <string> sberr = new List <string>(); foreach (var item in errlist) { sberr.Add(item[0].ErrorMessage); } TempData["ErrorMessage"] = sberr.ToList(); } ViewBag.TravelAgency = db.TravelAgency.ToList(); ViewBag.Cities = db.City.ToList(); ViewBag.Currencies = db.Currency.ToList(); ViewBag.ApprovalBy = db.Users.ToList(); ViewBag.fileUploader = db.AttachmentLink.Where(a => a.AttachmentFor == (rfqitem.RFQName + "Pro" + rfqitem.ProcessingSection + "Trav" + rfqitem.TravelAgencyID)).Select(x => x.Attachments).ToList(); MasterRFQ = rfqitem; using (EmployeeDetailsDBService EmpDBService = new EmployeeDetailsDBService("", rfqitem.TravelRequests.Users1.HREmployeeID.ToString())) { ViewBag.FullEmployeeDetails = EmpDBService.FullEmployeeDetails(); } return(View(rfqitem)); } }
public ActionResult ApproveManagerRequest(FormCollection collection) { using (BTCEntities db = new BTCEntities()) { var id = Convert.ToInt32(collection["ID"]); TravelRequests travelRequest = db.TravelRequests.Include(a => a.Users).Include(a => a.Users1).Include("Users1.HRW_Employee").Include("Users.HRW_Employee").SingleOrDefault(s => s.ID == id); if (ModelState.IsValid) { travelRequest.AdditionalAllowance = Convert.ToInt32(collection["AdditionalAllowance"]); travelRequest.ApprovalLevel = (int)ApprovalLevels.ApprovedByManager; travelRequest.ApprovalBy = dbuser.ID; travelRequest.ApprovalRemarks = travelRequest.ApprovalRemarks + "\n Manager Remarks: Approved By -" + dbuser.FirstName + ", " + dbuser.LastName + " \n Updated On: " + DateTime.Now.ToLongDateString() + " \n Comments: " + collection["ApprovalRemarksUser"]; db.Entry(travelRequest).State = EntityState.Modified; db.SaveChanges(); //NotificationEmail(travelRequest, true); return(RedirectToAction("ManagerDashboard")); } else { var errlist = ModelState.Values.Where(e => e.Errors.Count > 0).Select(a => a.Errors); List <string> sberr = new List <string>(); foreach (var item in errlist) { sberr.Add(item[0].ErrorMessage); } TempData["ErrorMessage"] = sberr.ToList(); } ViewBag.Cities = db.City.ToList(); ViewBag.Currencies = db.Currency.ToList(); ViewBag.ApprovalBy = db.Users.ToList(); using (EmployeeDetailsDBService EmpDBService = new EmployeeDetailsDBService(travelRequest.Users1.HRW_Employee.EmployeeCode)) { ViewBag.FullEmployeeDetails = EmpDBService.FullEmployeeDetails(); } return(View(travelRequest)); } }
public ActionResult RemoveUploadFile(string fileName) { using (BTCEntities db = new BTCEntities()) { if (fileName != null && fileName != string.Empty) { var dbfile = db.Attachments.Include(a => a.AttachmentLink).Include(a => a.Users).Where(x => x.FileName == fileName).FirstOrDefault(); db.AttachmentLink.RemoveRange(dbfile.AttachmentLink); db.Attachments.Remove(dbfile); db.SaveChanges(); var destinationPath = Path.Combine(Server.MapPath("~/UploadedFiles/" + MasterRFQ.RFQName + "Pro" + MasterRFQ.ProcessingSection + "Trav" + MasterRFQ.TravelAgencyID) + "/", fileName); FileInfo file = new FileInfo(destinationPath); if (file.Exists) { file.Delete(); } ViewBag.SuccessMessage = "File Deleted Successfully"; } ViewBag.fileUploader = db.AttachmentLink.Where(a => a.AttachmentFor == (MasterRFQ.RFQName + "Pro" + MasterRFQ.ProcessingSection + "Trav" + MasterRFQ.TravelAgencyID)).Select(x => x.Attachments).ToList(); return(RedirectToAction("PreviewRFQ", new { id = MasterRFQ.ID })); } }
public ActionResult AddATQuotation(int?quoteid, int?atquoteid) { ModelState.Clear(); using (BTCEntities db = new BTCEntities()) { ATQuotation atQuote = new ATQuotation(); ViewBag.Cities = db.City.ToList(); quotation = db.Quotation.Include(a => a.TravelRequests).Where(x => x.ID == quoteid).FirstOrDefault(); if (TempData["ATQuotationVal"] != null) { atQuote = (ATQuotation)TempData["ATQuotationVal"]; ViewBag.fileUploader = db.AttachmentLink.Where(a => a.AttachmentFor == quotation.TravelRequests.ApplicationNumber + ".AT-Q" + atQuote.ID).Select(x => x.Attachments).Include(a => a.AttachmentLink).Include(a => a.Users)?.ToList(); ViewBag.ATfileUploader = db.AttachmentLink.Where(a => a.AttachmentFor == quotation.TravelRequests.ApplicationNumber + ".AT-Q" + atQuote.ID).Select(x => x.Attachments).Include(a => a.AttachmentLink).Include(a => a.Users)?.ToList(); } else { var atquotes = db.ATQuotation.Include(x => x.Quotation).Include(x => x.Quotation.TravelRequests).Where(a => a.QuotationID == quoteid && a.IsDeleted == false)?.ToList(); if (atquoteid > 0 && atquotes.Where(a => a.ID == atquoteid).Count() > 0) { atQuote = db.ATQuotation.Include(x => x.Quotation).Include(x => x.Quotation.TravelRequests).Where(a => a.QuotationID == quoteid && a.ID == atquoteid && a.IsDeleted == false).FirstOrDefault(); ViewBag.fileUploader = db.AttachmentLink.Where(a => a.AttachmentFor == quotation.TravelRequests.ApplicationNumber + ".AT-Q" + atQuote.ID).Select(x => x.Attachments).Include(a => a.AttachmentLink).Include(a => a.Users)?.ToList(); ViewBag.ATfileUploader = db.AttachmentLink.Where(a => a.AttachmentFor == quotation.TravelRequests.ApplicationNumber + ".AT-Q" + atQuote.ID).Select(x => x.Attachments).Include(a => a.AttachmentLink).Include(a => a.Users)?.ToList(); } else { if (atquotes.Where(a => a.IsActive == false).Count() <= 0) { var tempatQuote = db.ATQuotation.Include(x => x.Quotation).Include(x => x.Quotation.TravelRequests).Where(a => a.QuotationID == quoteid).FirstOrDefault(); atQuote.IsActive = false; atQuote.IsDeleted = false; atQuote.IsLowest = false; atQuote.OriginID = tempatQuote.OriginID; atQuote.QuotationID = tempatQuote.QuotationID; atQuote.QuotationName = tempatQuote.QuotationName; atQuote.ReturnDate = tempatQuote.ReturnDate; atQuote.ReturnTime = tempatQuote.ReturnTime; atQuote.TicketClass = tempatQuote.TicketClass; atQuote.DepartureDate = tempatQuote.DepartureDate; atQuote.DepartureTime = tempatQuote.DepartureTime; atQuote.DestinationID = tempatQuote.DestinationID; atQuote.City = tempatQuote.City; atQuote.City1 = tempatQuote.City1; atQuote.Quotation = tempatQuote.Quotation; db.ATQuotation.Add(atQuote); db.Configuration.ValidateOnSaveEnabled = false; db.SaveChanges(); ViewBag.fileUploader = db.AttachmentLink.Where(a => a.AttachmentFor == quotation.TravelRequests.ApplicationNumber + ".AT-Q" + atQuote.ID).Select(x => x.Attachments).Include(a => a.AttachmentLink).Include(a => a.Users)?.ToList(); ViewBag.ATfileUploader = db.AttachmentLink.Where(a => a.AttachmentFor == quotation.TravelRequests.ApplicationNumber + ".AT-Q" + atQuote.ID).Select(x => x.Attachments).Include(a => a.AttachmentLink).Include(a => a.Users)?.ToList(); } else { atQuote = db.ATQuotation.Include(x => x.Quotation).Include(x => x.Quotation.TravelRequests).Where(a => a.QuotationID == quoteid && a.IsActive == false).FirstOrDefault(); ViewBag.fileUploader = db.AttachmentLink.Where(a => a.AttachmentFor == quotation.TravelRequests.ApplicationNumber + ".AT-Q" + atQuote.ID).Select(x => x.Attachments).Include(a => a.AttachmentLink).Include(a => a.Users)?.ToList(); ViewBag.ATfileUploader = db.AttachmentLink.Where(a => a.AttachmentFor == quotation.TravelRequests.ApplicationNumber + ".AT-Q" + atQuote.ID).Select(x => x.Attachments).Include(a => a.AttachmentLink).Include(a => a.Users)?.ToList(); } } } pageNo = 1; quotation.ATQuotation.Add(atQuote); quotation.HSQuotation.Clear(); quotation.PCQuotation.Clear(); CheckErrorMessages(); return(View(atQuote)); } }
public ActionResult PreviewRFQ(RFQ rfq) { using (BTCEntities db = new BTCEntities()) { if (ModelState.IsValid) { var dbrfq = db.RFQ.Find(rfq.ID); dbrfq.Processing = (int)ProcessingStatus.BeingProcessed; dbrfq.UserID = dbuser.ID; dbrfq.Remarks = rfq.Remarks; dbrfq.IsDeleted = rfq.IsDeleted; db.RFQ.Attach(dbrfq); var entry = db.Entry(dbrfq); entry.State = EntityState.Modified; entry.Property(a => a.Remarks).IsModified = true; entry.Property(a => a.UserID).IsModified = true; entry.Property(a => a.Processing).IsModified = true; entry.Property(a => a.IsDeleted).IsModified = true; db.SaveChanges(); Quotation quote = new Quotation { TravelRequestID = (int)dbrfq.TravelRequestID, IsDeleted = true, RFQID = rfq.ID }; db.Quotation.Add(quote); db.SaveChanges(); db.Configuration.ValidateOnSaveEnabled = false; var travelreq = db.TravelRequests.Where(a => a.ID == rfq.TravelRequestID).FirstOrDefault(); ATQuotation ATquote = new ATQuotation() { QuotationID = quote.ID, QuotationName = travelreq.ApplicationNumber + " / AT - Q", City = travelreq.City, City1 = travelreq.City1, DepartureDate = travelreq.DepartureDate, DepartureTime = travelreq.DepartureTime, DestinationID = travelreq.City.ID, OriginID = travelreq.City1.ID, ReturnDate = travelreq.ReturnDate, ReturnTime = travelreq.ReturnTime, TicketClass = travelreq.TicketClass, IsActive = false, IsDeleted = false }; db.ATQuotation.Add(ATquote); HSQuotation HSquote = new HSQuotation() { QuotationID = quote.ID, QuotationName = db.TravelRequests.Where(a => a.ID == rfq.TravelRequestID).FirstOrDefault().ApplicationNumber + " / HS - Q", CheckInDate = travelreq.CheckInDate, CheckInTime = travelreq.CheckInTime, CheckOutDate = travelreq.CheckOutDate, CheckOutTime = travelreq.CheckOutTime, HotelCategory = travelreq.HotelCategory, RoomCategory = travelreq.RoomCategory, RoomType = travelreq.RoomType, IsActive = false, IsDeleted = false }; db.HSQuotation.Add(HSquote); PCQuotation PCquote = new PCQuotation() { QuotationID = quote.ID, QuotationName = db.TravelRequests.Where(a => a.ID == rfq.TravelRequestID).FirstOrDefault().ApplicationNumber + " / PC - Q", DropOffDate = travelreq.DropOffDate, DropoffLocation = travelreq.DropOffLocation, DropOffTime = travelreq.DropOffTime, PickUpDate = travelreq.PickUpDate, PickupLocation = travelreq.PickUpLocation, PickUpTime = travelreq.PickUpTime, PreferredVehicle = travelreq.PreferredVehicle, IsActive = false, IsDeleted = false }; db.PCQuotation.Add(PCquote); db.SaveChanges(); MasterRFQ = dbrfq; return(RedirectToAction("RFQPostMerger", new { id = rfq.TravelRequestID })); } else { var errlist = ModelState.Values.Where(e => e.Errors.Count > 0).Select(a => a.Errors); List <string> sberr = new List <string>(); foreach (var item in errlist) { sberr.Add(item[0].ErrorMessage); } TempData["ErrorMessage"] = sberr.ToList(); } ViewBag.TravelAgency = db.TravelAgency.ToList(); ViewBag.Cities = db.City.ToList(); ViewBag.Currencies = db.Currency.ToList(); ViewBag.ApprovalBy = db.Users.ToList(); RFQ rfqitem = db.RFQ.Include(a => a.TravelRequests).Include(a => a.TravelAgency).Include(a => a.Users).Where(a => a.ID == rfq.ID).FirstOrDefault(); ViewBag.fileUploader = db.AttachmentLink.Where(a => a.AttachmentFor == (rfqitem.RFQName + "Pro" + rfqitem.ProcessingSection + "Trav" + rfqitem.TravelAgencyID)).Select(x => x.Attachments).ToList(); MasterRFQ = rfqitem; using (EmployeeDetailsDBService EmpDBService = new EmployeeDetailsDBService("", rfqitem.TravelRequests.Users1.HREmployeeID.ToString())) { ViewBag.FullEmployeeDetails = EmpDBService.FullEmployeeDetails(); } return(View(rfqitem)); } }
public ActionResult RFQProcessing(TravelRequests travelRequest, FormCollection formCollection) { RFQ rfq = new RFQ { TravelRequestID = travelRequest.ID }; if (formCollection.AllKeys.Contains("checkAll") && formCollection["checkAll"].ToString().ToLower() == "on") { rfq.ProcessingSection = (int)ProcessingSections.ATHSPC; } else { if ((formCollection.AllKeys.Contains("ATCheck") && formCollection["ATCheck"].ToString().ToLower() == "on") && (formCollection.AllKeys.Contains("HSCheck") && formCollection["HSCheck"].ToString().ToLower() == "on")) { rfq.ProcessingSection = (int)ProcessingSections.ATHS; } else if ((formCollection.AllKeys.Contains("ATCheck") && formCollection["ATCheck"].ToString().ToLower() == "on") && (formCollection.AllKeys.Contains("PCCheck") && formCollection["PCCheck"].ToString().ToLower() == "on")) { rfq.ProcessingSection = (int)ProcessingSections.ATPC; } else if ((formCollection.AllKeys.Contains("PCCheck") && formCollection["PCCheck"].ToString().ToLower() == "on") && (formCollection.AllKeys.Contains("HSCheck") && formCollection["HSCheck"].ToString().ToLower() == "on")) { rfq.ProcessingSection = (int)ProcessingSections.HSPC; } else if ((formCollection.AllKeys.Contains("ATCheck") && formCollection["ATCheck"].ToString().ToLower() == "on")) { rfq.ProcessingSection = (int)ProcessingSections.AT; } else if ((formCollection.AllKeys.Contains("HSCheck") && formCollection["HSCheck"].ToString().ToLower() == "on")) { rfq.ProcessingSection = (int)ProcessingSections.HS; } else if ((formCollection.AllKeys.Contains("PCCheck") && formCollection["PCCheck"].ToString().ToLower() == "on")) { rfq.ProcessingSection = (int)ProcessingSections.PC; } } rfq.Processing = (int)ProcessingStatus.NotProcessed; rfq.IsDeleted = false; rfq.UserID = dbuser.ID; rfq.TravelAgencyID = Convert.ToInt32((formCollection["TravelAgencySelected"].ToString()).Split(',')[0]); using (BTCEntities db = new BTCEntities()) { if (db.RFQ.Where(a => a.ProcessingSection == rfq.ProcessingSection && a.TravelRequestID == travelRequest.ID && a.TravelAgencyID == rfq.TravelAgencyID && a.IsDeleted == false).Count() < 1 && rfq.ProcessingSection != 0) { if (db.RFQ.Where(a => a.ProcessingSection == rfq.ProcessingSection && a.TravelRequestID == travelRequest.ID && a.TravelAgencyID == rfq.TravelAgencyID).Count() < 1) { rfq.RFQName = db.TravelRequests.Where(a => a.ID == travelRequest.ID).FirstOrDefault().ApplicationNumber; db.RFQ.Add(rfq); } else { RFQ rfqlist = db.RFQ.Where(a => a.ProcessingSection == rfq.ProcessingSection && a.TravelRequestID == travelRequest.ID && a.TravelAgencyID == rfq.TravelAgencyID).FirstOrDefault(); rfqlist.IsDeleted = false; db.RFQ.Attach(rfqlist); var entry = db.Entry(rfqlist); entry.Property(a => a.IsDeleted).IsModified = true; } db.SaveChanges(); } else if (rfq.ProcessingSection == 0) { ViewBag.ErrorMessage = new List <string>() { "Selet Processing Section" }; } else { ViewBag.ErrorMessage = new List <string>() { "Record already exists" }; } ViewBag.Cities = db.City.ToList(); ViewBag.Currencies = db.Currency.ToList(); ViewBag.ApprovalBy = db.Users.ToList(); ViewBag.TravelAgency = db.TravelAgency.ToList(); travelRequest = db.TravelRequests.Include(a => a.RFQ).Where(a => a.ID == rfq.TravelRequestID).FirstOrDefault(); using (EmployeeDetailsDBService EmpDBService = new EmployeeDetailsDBService("", travelRequest.Users1.HREmployeeID.ToString())) { ViewBag.FullEmployeeDetails = EmpDBService.FullEmployeeDetails(); } ViewBag.AvailableCombinations = db.RFQ.Where(a => a.TravelRequestID == rfq.TravelRequestID && a.IsDeleted == false).ToList(); return(View(travelRequest)); } }
public ActionResult CreateUser([Bind(Include = "ID,Username,FirstName,LastName,Email,Password,IsActive,ActivationCode")] Users userObj, FormCollection form) { try { bool statusRegistration = false; string messageRegistration = string.Empty; int empValue = Convert.ToInt32(form["EmployeeID"].ToString()); userObj.HREmployeeID = empValue; int DDLValue = Convert.ToInt32(form["RoleID"].ToString()); string userName = Membership.GetUserNameByEmail(userObj.Email); if (!string.IsNullOrEmpty(userName)) { ModelState.AddModelError("Warning Email", "Sorry: Email already Exists"); var errlist = ModelState.Values.Where(e => e.Errors.Count > 0).Select(a => a.Errors); List <string> sberr = new List <string>(); foreach (var item in errlist) { sberr.Add(item[0].ErrorMessage); } TempData["ErrorMessage"] = sberr.ToList(); CheckErrorMessages(); return(RedirectToAction("CreateUser", userObj)); } using (BTCEntities db = new BTCEntities()) { List <Roles> allRoles = db.Roles.ToList(); List <FullEmployeeDetail> allEmployees = new List <FullEmployeeDetail>(); using (EmployeeDetailsDBService employeeDetailsDBService = new EmployeeDetailsDBService(empCode)) { allEmployees = employeeDetailsDBService.AllEmployeeDetails(); } ViewBag.allRoles = allRoles; ViewBag.allEmployees = allEmployees; var role = db.Roles.Where(a => a.ID == DDLValue).FirstOrDefault(); var user = new Users() { Username = userObj.Username, FirstName = userObj.FirstName, LastName = userObj.LastName, Email = userObj.Email, Password = userObj.Password, HREmployeeID = userObj.HREmployeeID, ActivationCode = Guid.NewGuid(), }; user.Roles.Add(role); db.Users.Add(user); db.SaveChanges(); } //VerificationEmail(userObj.Email, userObj.ActivationCode.ToString()); messageRegistration = "Your account has been created successfully. ^_^"; statusRegistration = true; ViewBag.Message = messageRegistration; ViewBag.Status = statusRegistration; return(RedirectToAction("ManageUsers")); } catch (Exception) { return(View("CreateUser", userObj)); } }
public ActionResult AddPCQuotation(PCQuotation pcquote, FormCollection formCollection) { ModelState.Remove("PickUpTime"); ModelState.Remove("DropOffTime"); if (ModelState.IsValid) { using (BTCEntities db = new BTCEntities()) { pcquote.ID = string.IsNullOrEmpty(Convert.ToString(formCollection["PCId"])) ? 0 : Convert.ToInt32(formCollection["PCId"]); if ((bool)pcquote.IsLowest && db.PCQuotation.Include(a => a.Quotation).Where(a => a.QuotationID == pcquote.QuotationID && a.ID != pcquote.ID && (bool)a.IsLowest).Count() > 0) { pcquote.Quotation = db.Quotation.Where(a => a.ID == pcquote.QuotationID).FirstOrDefault(); TempData["ErrorMessage"] = new List <string>() { "Only One quotaiton can be the lowest" }; TempData["PCQuotationVal"] = pcquote; return(RedirectToAction("AddPCQuotation", new { quoteid = pcquote.QuotationID })); } var dbpcquote = db.PCQuotation.Include(a => a.Quotation).Where(a => a.QuotationID == pcquote.QuotationID && a.ID == pcquote.ID).FirstOrDefault(); dbpcquote.PickupLocation = string.IsNullOrEmpty(pcquote.PickupLocation) ? "" : pcquote.PickupLocation; dbpcquote.DropoffLocation = string.IsNullOrEmpty(pcquote.DropoffLocation) ? "" : pcquote.DropoffLocation; dbpcquote.PreferredVehicle = string.IsNullOrEmpty(pcquote.PreferredVehicle) ? "" : pcquote.PreferredVehicle; dbpcquote.TravelSector = string.IsNullOrEmpty(pcquote.TravelSector) ? "" : pcquote.TravelSector; dbpcquote.PickUpTime = string.IsNullOrEmpty(Convert.ToString(formCollection["PickUpTime"])) ? new TimeSpan() : DateTime.ParseExact(Convert.ToString(formCollection["PickUpTime"]), "hh:mm tt", CultureInfo.InvariantCulture).TimeOfDay; dbpcquote.DropOffTime = string.IsNullOrEmpty(Convert.ToString(formCollection["DropOffTime"])) ? new TimeSpan() : DateTime.ParseExact(Convert.ToString(formCollection["DropOffTime"]), "hh:mm tt", CultureInfo.InvariantCulture).TimeOfDay; dbpcquote.Amount = pcquote.Amount; dbpcquote.PickUpDate = pcquote.PickUpDate; dbpcquote.DropOffDate = pcquote.DropOffDate; dbpcquote.IsDeleted = false; dbpcquote.IsActive = true; dbpcquote.IsLowest = pcquote.IsLowest; db.PCQuotation.Attach(dbpcquote); var entry = db.Entry(dbpcquote); entry.Property(a => a.Amount).IsModified = true; entry.Property(a => a.DropOffDate).IsModified = true; entry.Property(a => a.DropoffLocation).IsModified = true; entry.Property(a => a.DropOffTime).IsModified = true; entry.Property(a => a.PickUpDate).IsModified = true; entry.Property(a => a.PickupLocation).IsModified = true; entry.Property(a => a.PickUpTime).IsModified = true; entry.Property(a => a.IsActive).IsModified = true; entry.Property(a => a.IsDeleted).IsModified = true; entry.Property(a => a.PreferredVehicle).IsModified = true; entry.Property(a => a.TravelSector).IsModified = true; entry.Property(a => a.IsLowest).IsModified = true; db.SaveChanges(); return(RedirectToAction("AddQuotation", new { id = dbpcquote.Quotation.RFQID })); } } else { using (BTCEntities db = new BTCEntities()) { pcquote.Quotation = db.Quotation.Where(a => a.ID == pcquote.QuotationID).FirstOrDefault(); } var errlist = ModelState.Values.Where(e => e.Errors.Count > 0).Select(a => a.Errors); List <string> sberr = new List <string>(); foreach (var item in errlist) { sberr.Add(item[0].ErrorMessage); } TempData["ErrorMessage"] = sberr.ToList(); TempData["PCQuotationVal"] = pcquote; } return(RedirectToAction("AddPCQuotation", new { quoteid = pcquote.QuotationID })); }
public ActionResult AddPCQuotation(int?quoteid, int?pcquoteid) { ModelState.Clear(); using (BTCEntities db = new BTCEntities()) { PCQuotation pcQuote = new PCQuotation(); ViewBag.Cities = db.City.ToList(); quotation = db.Quotation.Include(a => a.TravelRequests).Where(x => x.ID == quoteid).FirstOrDefault(); if (TempData["PCQuotationVal"] != null) { pcQuote = (PCQuotation)TempData["PCQuotationVal"]; ViewBag.fileUploader = db.AttachmentLink.Where(a => a.AttachmentFor == quotation.TravelRequests.ApplicationNumber + ".PC-Q" + pcQuote.ID).Select(x => x.Attachments).Include(a => a.AttachmentLink).Include(a => a.Users)?.ToList(); ViewBag.ATfileUploader = db.AttachmentLink.Where(a => a.AttachmentFor == quotation.TravelRequests.ApplicationNumber + ".PC-Q" + pcQuote.ID).Select(x => x.Attachments).Include(a => a.AttachmentLink).Include(a => a.Users)?.ToList(); } else { var pcquotes = db.PCQuotation.Include(x => x.Quotation).Include(x => x.Quotation.TravelRequests).Where(a => a.QuotationID == quoteid && a.IsDeleted == false)?.ToList(); if (pcquoteid > 0 && pcquotes.Where(a => a.ID == pcquoteid).Count() > 0) { pcQuote = db.PCQuotation.Include(x => x.Quotation).Include(x => x.Quotation.TravelRequests).Where(a => a.QuotationID == quoteid && a.IsDeleted == false).FirstOrDefault(); ViewBag.fileUploader = db.AttachmentLink.Where(a => a.AttachmentFor == quotation.TravelRequests.ApplicationNumber + ".PC-Q" + pcQuote.ID).Select(x => x.Attachments).Include(a => a.AttachmentLink).Include(a => a.Users)?.ToList(); ViewBag.ATfileUploader = db.AttachmentLink.Where(a => a.AttachmentFor == quotation.TravelRequests.ApplicationNumber + ".PC-Q" + pcQuote.ID).Select(x => x.Attachments).Include(a => a.AttachmentLink).Include(a => a.Users)?.ToList(); } else { if (pcquotes.Where(a => a.IsActive == false).Count() <= 0) { var tempatQuote = db.PCQuotation.Include(x => x.Quotation).Include(x => x.Quotation.TravelRequests).Where(a => a.QuotationID == quoteid).FirstOrDefault(); pcQuote.IsActive = false; pcQuote.IsDeleted = false; pcQuote.IsLowest = false; pcQuote.DropOffDate = tempatQuote.DropOffDate; pcQuote.DropoffLocation = tempatQuote.DropoffLocation; pcQuote.DropOffTime = tempatQuote.DropOffTime; pcQuote.PickUpDate = tempatQuote.PickUpDate; pcQuote.PickupLocation = tempatQuote.PickupLocation; pcQuote.PickUpTime = tempatQuote.PickUpTime; pcQuote.PreferredVehicle = tempatQuote.PreferredVehicle; pcQuote.QuotationID = tempatQuote.QuotationID; pcQuote.QuotationName = tempatQuote.QuotationName; pcQuote.TravelSector = tempatQuote.TravelSector; pcQuote.Quotation = tempatQuote.Quotation; db.PCQuotation.Add(pcQuote); db.Configuration.ValidateOnSaveEnabled = false; db.SaveChanges(); ViewBag.fileUploader = db.AttachmentLink.Where(a => a.AttachmentFor == quotation.TravelRequests.ApplicationNumber + ".PC-Q" + pcQuote.ID).Select(x => x.Attachments).Include(a => a.AttachmentLink).Include(a => a.Users)?.ToList(); ViewBag.ATfileUploader = db.AttachmentLink.Where(a => a.AttachmentFor == quotation.TravelRequests.ApplicationNumber + ".PC-Q" + pcQuote.ID).Select(x => x.Attachments).Include(a => a.AttachmentLink).Include(a => a.Users)?.ToList(); } else { pcQuote = db.PCQuotation.Include(x => x.Quotation).Include(x => x.Quotation.TravelRequests).Where(a => a.QuotationID == quoteid && a.IsActive == false).FirstOrDefault(); ViewBag.fileUploader = db.AttachmentLink.Where(a => a.AttachmentFor == quotation.TravelRequests.ApplicationNumber + ".PC-Q" + pcQuote.ID).Select(x => x.Attachments).Include(a => a.AttachmentLink).Include(a => a.Users)?.ToList(); ViewBag.ATfileUploader = db.AttachmentLink.Where(a => a.AttachmentFor == quotation.TravelRequests.ApplicationNumber + ".PC-Q" + pcQuote.ID).Select(x => x.Attachments).Include(a => a.AttachmentLink).Include(a => a.Users)?.ToList(); } } } pageNo = 3; quotation.PCQuotation.Add(pcQuote); quotation.HSQuotation.Clear(); quotation.ATQuotation.Clear(); CheckErrorMessages(); return(View(pcQuote)); } }
public ActionResult AddHSQuotation(HSQuotation hsquote, FormCollection formCollection) { ModelState.Remove("CheckInTime"); ModelState.Remove("CheckOutTime"); if (ModelState.IsValid) { using (BTCEntities db = new BTCEntities()) { hsquote.ID = string.IsNullOrEmpty(Convert.ToString(formCollection["HSId"])) ? 0 : Convert.ToInt32(formCollection["HSId"]); if ((bool)hsquote.IsLowest && db.HSQuotation.Include(a => a.Quotation).Where(a => a.QuotationID == hsquote.QuotationID && a.ID != hsquote.ID && (bool)a.IsLowest).Count() > 0) { hsquote.Quotation = db.Quotation.Where(a => a.ID == hsquote.QuotationID).FirstOrDefault(); TempData["ErrorMessage"] = new List <string>() { "Only One quotaiton can be the lowest" }; TempData["HSQuotationVal"] = hsquote; return(RedirectToAction("AddHSQuotation", new { quoteid = hsquote.QuotationID })); } var dbhsquote = db.HSQuotation.Include(a => a.Quotation).Where(a => a.QuotationID == hsquote.QuotationID && a.ID == hsquote.ID).FirstOrDefault(); dbhsquote.HotelName = string.IsNullOrEmpty(hsquote.HotelName) ? "" : hsquote.HotelName; dbhsquote.HotelCategory = string.IsNullOrEmpty(hsquote.HotelCategory) ? "" : hsquote.HotelCategory; dbhsquote.RoomCategory = string.IsNullOrEmpty(hsquote.RoomCategory) ? "" : hsquote.RoomCategory; dbhsquote.RoomType = string.IsNullOrEmpty(hsquote.RoomType) ? "" : hsquote.RoomType; dbhsquote.TravelSector = string.IsNullOrEmpty(hsquote.TravelSector) ? "" : hsquote.TravelSector; dbhsquote.CheckInTime = string.IsNullOrEmpty(Convert.ToString(formCollection["CheckInTime"])) ? new TimeSpan() : DateTime.ParseExact(Convert.ToString(formCollection["CheckInTime"]), "hh:mm tt", CultureInfo.InvariantCulture).TimeOfDay; dbhsquote.CheckOutTime = string.IsNullOrEmpty(Convert.ToString(formCollection["CheckOutTime"])) ? new TimeSpan() : DateTime.ParseExact(Convert.ToString(formCollection["CheckOutTime"]), "hh:mm tt", CultureInfo.InvariantCulture).TimeOfDay; dbhsquote.Amount = hsquote.Amount; dbhsquote.CheckInDate = hsquote.CheckInDate; dbhsquote.CheckOutDate = hsquote.CheckOutDate; dbhsquote.IsDeleted = false; dbhsquote.IsActive = true; dbhsquote.IsLowest = hsquote.IsLowest; db.HSQuotation.Attach(dbhsquote); var entry = db.Entry(dbhsquote); entry.Property(a => a.Amount).IsModified = true; entry.Property(a => a.CheckInDate).IsModified = true; entry.Property(a => a.CheckInTime).IsModified = true; entry.Property(a => a.CheckOutDate).IsModified = true; entry.Property(a => a.CheckOutTime).IsModified = true; entry.Property(a => a.HotelCategory).IsModified = true; entry.Property(a => a.HotelName).IsModified = true; entry.Property(a => a.IsActive).IsModified = true; entry.Property(a => a.IsDeleted).IsModified = true; entry.Property(a => a.RoomCategory).IsModified = true; entry.Property(a => a.RoomType).IsModified = true; entry.Property(a => a.TravelSector).IsModified = true; entry.Property(a => a.IsLowest).IsModified = true; db.SaveChanges(); return(RedirectToAction("AddQuotation", new { id = dbhsquote.Quotation.RFQID })); } } else { using (BTCEntities db = new BTCEntities()) { hsquote.Quotation = db.Quotation.Where(a => a.ID == hsquote.QuotationID).FirstOrDefault(); } var errlist = ModelState.Values.Where(e => e.Errors.Count > 0).Select(a => a.Errors); List <string> sberr = new List <string>(); foreach (var item in errlist) { sberr.Add(item[0].ErrorMessage); } TempData["ErrorMessage"] = sberr.ToList(); TempData["HSQuotationVal"] = hsquote; } return(RedirectToAction("AddHSQuotation", new { quoteid = hsquote.QuotationID })); }
public ActionResult AddHSQuotation(int?quoteid, int?hsquoteid) { ModelState.Clear(); using (BTCEntities db = new BTCEntities()) { HSQuotation hsQuote = new HSQuotation(); ViewBag.Cities = db.City.ToList(); quotation = db.Quotation.Include(a => a.TravelRequests).Where(x => x.ID == quoteid).FirstOrDefault(); if (TempData["HSQuotationVal"] != null) { hsQuote = (HSQuotation)TempData["HSQuotationVal"]; ViewBag.fileUploader = db.AttachmentLink.Where(a => a.AttachmentFor == quotation.TravelRequests.ApplicationNumber + ".HS-Q" + hsQuote.ID).Select(x => x.Attachments).Include(a => a.AttachmentLink).Include(a => a.Users)?.ToList(); ViewBag.ATfileUploader = db.AttachmentLink.Where(a => a.AttachmentFor == quotation.TravelRequests.ApplicationNumber + ".HS-Q" + hsQuote.ID).Select(x => x.Attachments).Include(a => a.AttachmentLink).Include(a => a.Users)?.ToList(); } else { var hsquotes = db.HSQuotation.Include(x => x.Quotation).Include(x => x.Quotation.TravelRequests).Where(a => a.QuotationID == quoteid && a.IsDeleted == false)?.ToList(); if (hsquoteid > 0 && hsquotes.Where(a => a.ID == hsquoteid).Count() > 0) { hsQuote = db.HSQuotation.Include(x => x.Quotation).Include(x => x.Quotation.TravelRequests).Where(a => a.QuotationID == quoteid && a.ID == hsquoteid && a.IsDeleted == false).FirstOrDefault(); ViewBag.fileUploader = db.AttachmentLink.Where(a => a.AttachmentFor == quotation.TravelRequests.ApplicationNumber + ".HS-Q" + hsQuote.ID).Select(x => x.Attachments).Include(a => a.AttachmentLink).Include(a => a.Users)?.ToList(); ViewBag.HSfileUploader = db.AttachmentLink.Where(a => a.AttachmentFor == quotation.TravelRequests.ApplicationNumber + ".HS-Q" + hsQuote.ID).Select(x => x.Attachments).Include(a => a.AttachmentLink).Include(a => a.Users)?.ToList(); } else { if (hsquotes.Where(a => a.IsActive == false).Count() <= 0) { var tempatQuote = db.HSQuotation.Include(x => x.Quotation).Include(x => x.Quotation.TravelRequests).Where(a => a.QuotationID == quoteid).FirstOrDefault(); hsQuote.IsActive = false; hsQuote.IsDeleted = false; hsQuote.IsLowest = false; hsQuote.CheckInDate = tempatQuote.CheckInDate; hsQuote.CheckInTime = tempatQuote.CheckInTime; hsQuote.CheckOutDate = tempatQuote.CheckOutDate; hsQuote.CheckOutTime = tempatQuote.CheckOutTime; hsQuote.HotelCategory = tempatQuote.HotelCategory; hsQuote.QuotationID = tempatQuote.QuotationID; hsQuote.QuotationName = tempatQuote.QuotationName; hsQuote.RoomCategory = tempatQuote.RoomCategory; hsQuote.RoomType = tempatQuote.RoomType; hsQuote.TravelSector = tempatQuote.TravelSector; hsQuote.Quotation = tempatQuote.Quotation; db.HSQuotation.Add(hsQuote); db.Configuration.ValidateOnSaveEnabled = false; db.SaveChanges(); ViewBag.fileUploader = db.AttachmentLink.Where(a => a.AttachmentFor == quotation.TravelRequests.ApplicationNumber + ".HS-Q" + hsQuote.ID).Select(x => x.Attachments).Include(a => a.AttachmentLink).Include(a => a.Users)?.ToList(); ViewBag.HSfileUploader = db.AttachmentLink.Where(a => a.AttachmentFor == quotation.TravelRequests.ApplicationNumber + ".HS-Q" + hsQuote.ID).Select(x => x.Attachments).Include(a => a.AttachmentLink).Include(a => a.Users)?.ToList(); } else { hsQuote = db.HSQuotation.Include(x => x.Quotation).Include(x => x.Quotation.TravelRequests).Where(a => a.QuotationID == quoteid && a.IsActive == false).FirstOrDefault(); ViewBag.fileUploader = db.AttachmentLink.Where(a => a.AttachmentFor == quotation.TravelRequests.ApplicationNumber + ".HS-Q" + hsQuote.ID).Select(x => x.Attachments).Include(a => a.AttachmentLink).Include(a => a.Users)?.ToList(); ViewBag.HSfileUploader = db.AttachmentLink.Where(a => a.AttachmentFor == quotation.TravelRequests.ApplicationNumber + ".HS-Q" + hsQuote.ID).Select(x => x.Attachments).Include(a => a.AttachmentLink).Include(a => a.Users)?.ToList(); } } } pageNo = 2; quotation.HSQuotation.Add(hsQuote); quotation.ATQuotation.Clear(); quotation.PCQuotation.Clear(); CheckErrorMessages(); return(View(hsQuote)); } }
public ActionResult CreateTravelGrid(Dictionary <string, string> collection) { try { List <LPO> lpoList = new List <LPO>(); List <string> RfqList = new List <string>(); foreach (var item in collection) { if (item.Value.ToLower() == "true") { RfqList.Add(item.Key.Split('-')[0]); } } foreach (var rfq in RfqList.Distinct()) { LPO lpoObject = new LPO(); foreach (var item in collection) { if (item.Value.ToLower() == "true" && item.Key.Contains(rfq)) { lpoObject.RFQID = Convert.ToInt32(item.Key.Split('-')[0].Substring(item.Key.Split('-')[0].IndexOf('Q') + 1)); lpoObject.QuotationID = Convert.ToInt32(item.Key.Split('-')[1].Substring(item.Key.Split('-')[1].IndexOf('t') + 1)); if (item.Key.Split('-')[2].Contains("ATCheck")) { lpoObject.IsAT = true; } if (item.Key.Split('-')[2].Contains("HSCheck")) { lpoObject.IsHS = true; } if (item.Key.Split('-')[2].Contains("PCCheck")) { lpoObject.IsPC = true; } lpoObject.IsDeleted = true; } } lpoList.Add(lpoObject); } if (lpoList.Count > 0) { using (BTCEntities db = new BTCEntities()) { foreach (var item in lpoList) { if (db.LPO.Where(a => a.RFQID == item.RFQID && a.QuotationID == item.QuotationID).Count() > 0) { var lpodata = db.LPO.Where(a => a.RFQID == item.RFQID && a.QuotationID == item.QuotationID).FirstOrDefault(); lpodata.IsAT = item.IsAT; lpodata.IsDeleted = item.IsDeleted; lpodata.IsHS = item.IsHS; lpodata.IsPC = item.IsPC; lpodata.LPONo = "LPO - " + lpodata.ID; db.Entry(lpodata).State = EntityState.Modified; db.LPO.Attach(lpodata); db.Entry(lpodata).Property(x => x.IsAT).IsModified = true; db.Entry(lpodata).Property(x => x.IsDeleted).IsModified = true; db.Entry(lpodata).Property(x => x.IsHS).IsModified = true; db.Entry(lpodata).Property(x => x.IsPC).IsModified = true; } else { db.LPO.Add(item); } } db.SaveChanges(); return(Json("Created Travel Grid", JsonRequestBehavior.AllowGet)); } } return(Json("Error While Creating Travel Grid", JsonRequestBehavior.AllowGet)); } catch (Exception) { return(Json("Error While Creating Travel Grid", JsonRequestBehavior.AllowGet)); } }
public ActionResult AddATQuotation(ATQuotation atquote, FormCollection formCollection) { ModelState.Remove("DepartureTime"); ModelState.Remove("ReturnTime"); if (ModelState.IsValid) { using (BTCEntities db = new BTCEntities()) { atquote.ID = string.IsNullOrEmpty(Convert.ToString(formCollection["ATId"])) ? 0 : Convert.ToInt32(formCollection["ATId"]); if ((bool)atquote.IsLowest && db.ATQuotation.Include(a => a.Quotation).Where(a => a.QuotationID == atquote.QuotationID && a.ID != atquote.ID && (bool)a.IsLowest).Count() > 0) { atquote.Quotation = db.Quotation.Where(a => a.ID == atquote.QuotationID).FirstOrDefault(); TempData["ErrorMessage"] = new List <string>() { "Only One quotaiton can be the lowest" }; TempData["ATQuotationVal"] = atquote; return(RedirectToAction("AddATQuotation", new { quoteid = atquote.QuotationID })); } var dbatquote = db.ATQuotation.Include(a => a.Quotation).Where(a => a.QuotationID == atquote.QuotationID && a.ID == atquote.ID).FirstOrDefault(); dbatquote.Airlines = string.IsNullOrEmpty(atquote.Airlines) ? "" : atquote.Airlines; dbatquote.TicketClass = string.IsNullOrEmpty(atquote.TicketClass) ? "" : atquote.TicketClass; dbatquote.TicketNo = string.IsNullOrEmpty(atquote.TicketNo) ? "" : atquote.TicketNo; dbatquote.DepartureTime = string.IsNullOrEmpty(Convert.ToString(formCollection["DepartureTime"])) ? new TimeSpan() : DateTime.ParseExact(Convert.ToString(formCollection["DepartureTime"]), "hh:mm tt", CultureInfo.InvariantCulture).TimeOfDay; dbatquote.ReturnTime = string.IsNullOrEmpty(Convert.ToString(formCollection["ReturnTime"])) ? new TimeSpan() : DateTime.ParseExact(Convert.ToString(formCollection["ReturnTime"]), "hh:mm tt", CultureInfo.InvariantCulture).TimeOfDay; dbatquote.Amount = atquote.Amount; dbatquote.DepartureDate = atquote.DepartureDate; dbatquote.ReturnDate = atquote.ReturnDate; dbatquote.DestinationID = atquote.DestinationID; dbatquote.OriginID = atquote.OriginID; dbatquote.TicketClass = atquote.TicketClass; dbatquote.TicketNo = atquote.TicketNo; dbatquote.IsDeleted = false; dbatquote.IsActive = true; dbatquote.IsLowest = atquote.IsLowest; db.ATQuotation.Attach(dbatquote); var entry = db.Entry(dbatquote); entry.Property(a => a.Airlines).IsModified = true; entry.Property(a => a.Amount).IsModified = true; entry.Property(a => a.DepartureDate).IsModified = true; entry.Property(a => a.DepartureTime).IsModified = true; entry.Property(a => a.DestinationID).IsModified = true; entry.Property(a => a.ReturnDate).IsModified = true; entry.Property(a => a.ReturnTime).IsModified = true; entry.Property(a => a.OriginID).IsModified = true; entry.Property(a => a.QuotationID).IsModified = true; entry.Property(a => a.TicketClass).IsModified = true; entry.Property(a => a.TicketNo).IsModified = true; entry.Property(a => a.IsDeleted).IsModified = true; entry.Property(a => a.IsActive).IsModified = true; entry.Property(a => a.IsLowest).IsModified = true; db.SaveChanges(); return(RedirectToAction("AddQuotation", new { id = dbatquote.Quotation.RFQID })); } } else { using (BTCEntities db = new BTCEntities()) { atquote.Quotation = db.Quotation.Where(a => a.ID == atquote.QuotationID).FirstOrDefault(); } var errlist = ModelState.Values.Where(e => e.Errors.Count > 0).Select(a => a.Errors); List <string> sberr = new List <string>(); foreach (var item in errlist) { sberr.Add(item[0].ErrorMessage); } TempData["ErrorMessage"] = sberr.ToList(); TempData["ATQuotationVal"] = atquote; } return(RedirectToAction("AddATQuotation", new { quoteid = atquote.QuotationID })); }