public Corner(CornerViewModel corner) { _corner = corner; _trsparts = CommandExecutor.ExecuteCommand( new ChooseBestTrsValueCommand(_corner.BlmPointId, _corner.Township)); Township = string.Format("T{0}{1} R{2}{3} Sec{4}", _trsparts.Township, _trsparts.TownshipDirection, _trsparts.Range, _trsparts.RangeDirection, _trsparts.Section); }
public Photo(CornerViewModel model) { _imageService = new ImageService(); _pdfService = new BasicPdfService(); PhotoId = Guid.NewGuid(); Sketch = ReadFully(model.Sketch); Thumb = ReadFully(model.Thumb); Thumb2 = ReadFully(model.Thumb2); ExtraPages = ProcessExtraPages(model.Files); }
public TieSheetPdfModel(CornerViewModel model, Corner corner, Photo photo) { var imageService = new ImageService(); const int factor = 2; OverrideTitle = model.UseCountyTitle; County = corner.County; BlmPointId = corner.BlmPointId; CollectionDate = corner.CollectionDate.ToShortDateString(); SectionCorner = corner.SectionCorner; Township = corner.Township; BaseMeridian = corner.BaseMeridian; Accuracy = corner.Accuracy; Description = corner.Description; MonumentStatus = corner.MonumentStatus; SurveryorLicenseNumber = model.User.SurveryorLicenseNumber; SurveyorName = model.User.Name; Zone = model.Grid.Zone; Northing = model.Grid.Northing.ToString("0.000"); Easting = model.Grid.Easting.ToString("0.000"); Elevation = model.Grid.Elevation.ToString("0.000"); CoordinateAdjustment = model.Grid.Adjustment; CoordinateSystem = model.Grid.CoordinateSystem; Datum = model.Grid.Datum; Latitude = string.Format("{0}°{1}'{2}\" {3}", model.Coordinate.NorthingDegrees, model.Coordinate.NorthingMinutes, model.Coordinate.NorthingSeconds, model.Coordinate.Northing); Longitude = string.Format("{0}°{1}'{2}\" {3}", model.Coordinate.EastingDegrees, model.Coordinate.EastingMinutes, model.Coordinate.EastingSeconds, model.Coordinate.Easting); ElipsoidHeight = model.Coordinate.ElipsoidHeight.ToString("0.000"); GridAdjustment = model.Coordinate.Adjustment; var sketch = ConvertToImage(model.Sketch); if (sketch != null) { Sketch = imageService.CreateSizedImage(sketch, new ImageSize(height: 270 * factor, width: 357 * factor)); } var thumb = ConvertToImage(model.Thumb); if (thumb != null) { Thumb = imageService.CreateSizedImage(thumb, new ImageSize(height: 270 * factor, width: 357 * factor)); } var thumb2 = ConvertToImage(model.Thumb2); if (thumb2 != null) { Thumb2 = imageService.CreateSizedImage(thumb2, new ImageSize(height: 270 * factor, width: 357 * factor)); } var extras = photo.ExtraPages; if (extras != null) { ExtraPages = extras; } if (model.User.SurveyorSeal != null && model.User.SurveyorSeal.Length > 0) { SurveyorSeal = model.User.SurveyorSeal; } }
public async Task <ActionResult> Preview(CornerViewModel cornerViewModel) { #region validate input if (!ModelState.IsValid) { TempData["error"] = "There was a problem with your input. Please try again."; return(RedirectToAction("Index")); } #endregion var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["PLSS"].ConnectionString); PDFDocument pdf = null; try { await connection.OpenAsync(); var user = CommandExecutor.ExecuteCommand(new GetUserCommand(connection, User.Identity.Name)); if (user == null) { TempData["error"] = "You must log in to submit a corner"; return(RedirectToRoute("", new { Controller = "Home", Action = "Index" })); } cornerViewModel.User = user; var corner = new Corner(cornerViewModel); var photos = new Photo(cornerViewModel); var model = new TieSheetPdfModel(cornerViewModel, corner, photos); var pdfService = new PlssPdfService("Assets\\pdf"); pdf = pdfService.HydratePdfForm("MonumentStatusTemplate.pdf", model); #if DEBUG pdf.FlattenFormFields(); #endif return(File(pdf.GetPDFAsByteArray(), MediaTypeNames.Application.Pdf, $"{model.BlmPointId}-preview.pdf")); } catch (Exception ex) { Log.LogException(LogLevel.Fatal, $"problem previewing pdf for {cornerViewModel}", ex); TempData["error"] = $"There was a problem generating your preview. {ex.Message}"; return(RedirectToRoute("", new { Controller = "Home", Action = "Index" })); } finally { pdf?.Dispose(); connection.Close(); connection.Dispose(); } }
public async Task <ActionResult> New(CornerViewModel cornerViewModel) { #region validate input if (!ModelState.IsValid) { TempData["error"] = ModelState.ToErrors(); return(RedirectToRoute("", new { Controller = "Home", Action = "Index" })); } #endregion if (Request.Form["submitType"] == "preview") { Log.Info("Showing preview for {0}", cornerViewModel.BlmPointId); return(await Preview(cornerViewModel)); } var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["PLSS"].ConnectionString); try { await connection.OpenAsync(); var user = CommandExecutor.ExecuteCommand(new GetUserCommand(connection, User.Identity.Name)); if (user == null) { Log.Info("Could not find user {0} redirecting to home.", User.Identity.Name); TempData["error"] = "You must log in to submit a corner"; return(RedirectToRoute("", new { Controller = "Home", Action = "Index" })); } Log.Info("Submitting tiesheet for {0}", user.Name); cornerViewModel.User = user; var corner = new Corner(cornerViewModel); var grid = new Grid(cornerViewModel.Grid); var coordinate = new Coordinate(cornerViewModel.Coordinate); var formInfo = new FormInfo(user.Name, corner.BlmPointId); var photos = new Photo(cornerViewModel); corner.CoordinateId = coordinate.CoordinateId; corner.GridId = grid.GridId; corner.FormInfoId = formInfo.FormInfoId; corner.PhotoId = photos.PhotoId; var gInserts = connection.Execute(Grid.InsertString, grid); Debug.Assert(gInserts == 1, "inserted into grid successfully"); var cInserts = connection.Execute(Coordinate.InsertString, coordinate); Debug.Assert(cInserts == 1, "inserted into coords successfully"); var fInserts = connection.Execute(FormInfo.InsertString, formInfo); Debug.Assert(fInserts == 1, "inserted into form successfully"); var pInserts = connection.Execute(Photo.InsertString, photos); Debug.Assert(pInserts == 1, "inserted into photo successfully"); var cornInserts = connection.Execute(Corner.InsertString, corner); Debug.Assert(cornInserts == 1, "inserted into corners successfully"); var model = new TieSheetPdfModel(cornerViewModel, corner, photos); var pdfService = new PlssPdfService("Assets\\pdf"); var pdf = pdfService.HydratePdfForm("MonumentStatusTemplate.pdf", model); #if DEBUG pdf.FlattenFormFields(); #endif Log.Info("finished created database models"); var actualPath = Path.Combine(Config.Global.Get <string>("SharePath"), formInfo.Path); Log.Info($"Writing PDF to: {actualPath}"); var success = FileSaver.SaveFile(actualPath, pdf.GetPDFAsByteArray()); if (!success) { Log.Fatal($"problem saving pdf for {cornerViewModel}"); //do nothing, email will get sent about issue and we'll rebuild pdf form later. Log.Info("Sending failed notification email to {0}", string.Join(", ", App.AdminEmails)); CommandExecutor.ExecuteCommand(new UserSubmitionFailedEmailCommand( new UserSubmitionFailedEmailCommand.MailTemplate(App.AdminEmails, new[] { user. UserName }, user.Name, model.BlmPointId, model. CollectionDate))); } else { CommandExecutor.ExecuteCommand(new UserSubmittedEmailCommand( new UserSubmittedEmailCommand.MailTemplate(App.AdminEmails, new[] { user.UserName }, user.Name, model.BlmPointId, model.CollectionDate, actualPath))); } Log.Info("updating forminfoes table path: {0}", actualPath, success); var cUpdate = connection.Execute( "update FormInfoes set " + "path = @actualpath, " + "uploadedSuccessfully = @success " + "where forminfoid = @FormInfoId", new { actualPath, formInfo.FormInfoId, success }); Debug.Assert(cUpdate == 1, "updated form infos correctly"); } catch (Exception ex) { Log.LogException(LogLevel.Fatal, $"problem saving new corner for {cornerViewModel}", ex); TempData["error"] = ex.Message; return(RedirectToRoute("", new { Controller = "Home", Action = "Index" })); } finally { connection.Close(); connection.Dispose(); } return(RedirectToRoute("", new { Controller = "Home", Action = "Index" })); }