public ActionResult Index(TheftClaimModel model) { if (!this.ModelState.IsValid) { return((ActionResult)this.View()); } this.theftClaim = (ITheftClaimServices) new TheftClaimServices(); return((ActionResult)this.RedirectToAction(nameof(Index), (object)new { message = this.theftClaim.SaveTheftClaim(model) })); }
public string SaveTheftClaim(TheftClaimModel model) { return(this._theftRepo.SaveTheftClaim(model)); }
public string SaveTheftClaim(TheftClaimModel model) { string path = Path.Combine(HttpContext.Current.Server.MapPath("~/PdfTemplates"), "TheftClaimPDF.html"); model.FullName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(model.FullName.ToLower()); int bookingid; try { bookingid = Convert.ToInt32(model.BookingId); } catch (Exception ex) { bookingid = 0; } tblBooking tblBooking = ((IQueryable <tblBooking>) this._dbEntity.tblBookings).FirstOrDefault <tblBooking>((Expression <Func <tblBooking, bool> >)(x => x.BookingId == (long)bookingid)); if (tblBooking != null) { tblBooking.IsTheftClaimRaised = new bool?(true); tblBooking.IsRenterRaisedDispute = new bool?(true); this._dbEntity.SaveChanges(); } string str1 = System.IO.File.ReadAllText(path).Replace("{fullname}", model.FullName).Replace("{email}", model.Email); string oldValue1 = "{dob}"; DateTime dateTime = model.DOB.Date; string newValue1 = dateTime.ToString("MM-dd-yyyy"); string str2 = str1.Replace(oldValue1, newValue1).Replace("{booking}", model.BookingId).Replace("{address}", model.Address).Replace("{postcode}", model.PostCode).Replace("{mobilenumber}", model.MobileNumber).Replace("{circumstances}", model.Circumstances).Replace("{stolenlist}", model.ListOfStolenItems).Replace("{approxvalue}", "£ " + model.ApproxValue).Replace("{responsible}", model.WhoWasResponsible).Replace("{unattended}", model.HowLongUnattended); string oldValue2 = "{lastseen}"; dateTime = model.TimeAndDateLastSeen; string newValue2 = dateTime.ToString(); string str3 = str2.Replace(oldValue2, newValue2); string oldValue3 = "{discovered}"; dateTime = model.TimeAndDateTheftDiscovered; string newValue3 = dateTime.ToString(); string str4 = str3.Replace(oldValue3, newValue3); bool? nullable = model.IsAnyWitness; bool flag1 = true; string str5 = ((nullable.GetValueOrDefault() == flag1 ? (nullable.HasValue ? 1 : 0) : 0) == 0 ? str4.Replace("{anywitness}", "No").Replace("{witnessdetails}", string.Empty) : str4.Replace("{anywitness}", "Yes").Replace("{witnessdetails}", model.WitnessDetails)).Replace("{policecontact}", model.PoliceContactNumber).Replace("{crimeincident}", model.CrimeIncidentNumber); string str6 = !model.IsPoliceAttend ? str5.Replace("{policeattend}", "No") : str5.Replace("{policeattend}", "Yes"); string str7 = (!model.IsReportedToPoliceImmediately ? str6.Replace("{policeimmediately}", "No").Replace("{reasonforpolice}", model.ReasonForNotReportedImmediately) : str6.Replace("{policeimmediately}", "Yes").Replace("{reasonforpolice}", string.Empty)).Replace("{howsecured}", model.HowBicycleWasSecured).Replace("{locksecured}", model.DetailOfSecuredLock).Replace("{howaccess}", model.HowAccessGained).Replace("{alternatesecurity}", model.AlternativeSecurityMethod); nullable = model.IsAnotherInsurer; bool flag2 = true; string str8 = ((nullable.GetValueOrDefault() == flag2 ? (nullable.HasValue ? 1 : 0) : 0) == 0 ? str7.Replace("{isanotherinsurer}", "No") : str7.Replace("{isanotherinsurer}", "Yes")).Replace("{previousinsurer}", model.PreviousInsurerName).Replace("{expirydate}", model.ExpiryDate).Replace("{anybicycleclaim}", model.PastClaimDetails); nullable = model.IsAnyCriminalConviction; bool flag3 = true; string str9 = (nullable.GetValueOrDefault() == flag3 ? (nullable.HasValue ? 1 : 0) : 0) == 0 ? str8.Replace("{iscriminal}", "No") : str8.Replace("{iscriminal}", "Yes"); nullable = model.IsPolicyCancelled; bool flag4 = true; string str10 = (nullable.GetValueOrDefault() == flag4 ? (nullable.HasValue ? 1 : 0) : 0) == 0 ? str9.Replace("{ispolicycancelled}", "No") : str9.Replace("{ispolicycancelled}", "Yes"); nullable = model.IsRefusedRenewal; bool flag5 = true; string str11 = ((nullable.GetValueOrDefault() == flag5 ? (nullable.HasValue ? 1 : 0) : 0) == 0 ? str10.Replace("{isrefusedrenewal}", "No") : str10.Replace("{isrefusedrenewal}", "Yes")).Replace("{provideddetails}", model.ProvidedDetails); StreamWriter streamWriter = new StreamWriter(HostingEnvironment.MapPath("~/Templates/dfTemplate.htm")); streamWriter.Write(str11); streamWriter.Close(); streamWriter.Dispose(); PdfConverter pdfConverter = new PdfConverter(); pdfConverter.LicenseKey = "elFLWktaTE9IWk9USlpJS1RLSFRDQ0ND"; pdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.Letter; pdfConverter.PdfDocumentOptions.PdfCompressionLevel = PdfCompressionLevel.NoCompression; pdfConverter.PdfDocumentOptions.PdfPageOrientation = PDFPageOrientation.Landscape; pdfConverter.PdfDocumentOptions.BottomMargin = 20; pdfConverter.PdfDocumentOptions.TopMargin = 20; pdfConverter.PdfDocumentOptions.LeftMargin = 20; pdfConverter.PdfDocumentOptions.RightMargin = 20; pdfConverter.PdfDocumentOptions.ShowHeader = false; pdfConverter.PdfDocumentOptions.ShowFooter = false; pdfConverter.PdfDocumentOptions.AutoSizePdfPage = false; pdfConverter.PdfDocumentOptions.GenerateSelectablePdf = true; pdfConverter.PdfDocumentOptions.SinglePage = true; string str12 = RandomString(7) + ".pdf"; byte[] pdfBytesFromUrl = pdfConverter.GetPdfBytesFromUrl(HostingEnvironment.MapPath("~/Templates/dfTemplate.htm")); System.IO.File.WriteAllBytes(HostingEnvironment.MapPath("~/PdfTemplates/TheftClaimForms/" + str12 ?? ""), pdfBytesFromUrl); model.PDFName = str12; Mapper.Initialize(new MapperConfigurationExpression() { AllowNullCollections = true, AllowNullDestinationValues = true, CreateMissingTypeMaps = true }); tblTheftClaim tblTheftClaim = Mapper.Instance.Map <tblTheftClaim>(model); tblTheftClaim.IsApproved = new bool?(false); tblTheftClaim.CreatedDate = new DateTime?(DateTime.Now); this._dbEntity.tblTheftClaims.Add(tblTheftClaim); this._dbEntity.SaveChanges(); return("Success"); }