public void MapInspectionDTOToInspectionTest() { UserDTO user = this.CreateUser(); VehicleDTO vehicle = this.CreateVehicle(); InspectionMapper mapper = new InspectionMapper(); InspectionDTO inspectionDTO = new InspectionDTO(); inspectionDTO.Damages = new List <DamageDTO>(); inspectionDTO.CreatorUserName = user.UserName; inspectionDTO.Date = DateTime.Now; inspectionDTO.Location = "Puerto 1"; inspectionDTO.IdVehicle = vehicle.Vin; Inspection inspectionEntity = mapper.ToEntity(inspectionDTO); Assert.AreEqual(inspectionDTO.Location, inspectionEntity.IdLocation.Name); Assert.AreEqual(inspectionDTO.Id, inspectionEntity.Id); Assert.AreEqual(inspectionDTO.Date, inspectionEntity.Date); Assert.AreEqual(inspectionDTO.CreatorUserName, inspectionEntity.IdUser.UserName); Assert.AreEqual(inspectionDTO.IdVehicle, inspectionEntity.IdVehicle.Vin); foreach (DamageDTO damageDTO in inspectionDTO.Damages) { Assert.IsNotNull(inspectionEntity.Damages.Find(d => d.Description == damageDTO.Description)); } }
public void MapInspectionToInspectionDTOTest() { UserDTO userDTO = this.CreateUser(); UserMapper userMapper = new UserMapper(new RoleDAOImp()); User user = userMapper.ToEntity(userDTO); VehicleDTO vehicleDTO = new VehicleDTO(); VehicleMapper vehicleMapper = new VehicleMapper(); Vehicle vehicle = vehicleMapper.ToEntity(vehicleDTO); InspectionMapper mapper = new InspectionMapper(); Inspection inspection = new Inspection(); inspection.Date = DateTime.Now; inspection.IdLocation = new Location(Ports.FIRST_PORT); inspection.IdUser = user; inspection.Damages = new List <Damage>(); inspection.IdVehicle = vehicle; InspectionDTO inspectionDTO = mapper.ToDTO(inspection); Assert.AreEqual(inspectionDTO.Location, inspection.IdLocation.Name); Assert.AreEqual(inspectionDTO.Id, inspection.Id); Assert.AreEqual(inspectionDTO.Date, inspection.Date); Assert.AreEqual(inspectionDTO.CreatorUserName, inspection.IdUser.UserName); Assert.AreEqual(inspectionDTO.IdVehicle, inspection.IdVehicle.Vin); foreach (DamageDTO damageDTO in inspectionDTO.Damages) { Assert.IsNotNull(inspection.Damages.Find(d => d.Description == damageDTO.Description)); } }
public async Task <ActionResult> Detail(int?id, bool partial = false) { UserModel user = JwtTokenProvider.GetUserModel(Request.Cookies["token"].Value); var audits = await _prepareService.GetAudits(id); if (!audits.Any()) { return(HttpNotFound()); } var audit = audits.First(); if (!user.Roles.Any(r => (new[] { KnownRoles.Administrator, KnownRoles.Supervisor, KnownRoles.Documentalist }.Contains(r))) && audit.AuditorId != user.UserId && !audit.Inspection.InspectionSteps.Any(s => s.InspectorId == user.UserId)) { return(RedirectToAction("Index", new { userId = user.UserId, partial = partial })); } var inspection = await _prepareService.GetInspection(audit.InspectionId); var inspectionSteps = InspectionController.GetInspectionStepAndChilds(inspection, inspection.Publication.PublishedActions.Distinct() .OrderBy(a => a.WBSParts, new WBSPartsComparer()).ToList()); var anomalies = await _prepareService.GetAnomalies(audit.InspectionId); var model = AuditMapper.ToAuditViewModel(audits.FirstOrDefault()); model.Inspection = InspectionMapper.ToInspectionViewModel(inspection, inspectionSteps, anomalies.ToList()); if (partial) { return(PartialView(model)); } return(View(model)); }
public async Task <ActionResult> Index(string team, string userId, string publicationId, int?opeId, bool partial = false) { //check if user can create audit for inspection var currentUserId = Convert.ToInt32(System.Web.HttpContext.Current.User.Identity.GetUserId()); var currentAudit = await _prepareService.GetActiveAudit(currentUserId); var inspections = (await _prepareService.GetLastPublications((int)PublishModeEnum.Inspection)) .SelectMany(p => p.Inspections) .OrderByDescending(i => i.StartDate) .ToList(); ViewBag.AllowCreateAudit = currentAudit == null; if (team == null && userId == null && publicationId == null) { var model = await InspectionMapper.ToInspectionManageViewModel(inspections); model.CurrentAuditInspectionId = currentAudit != null ? currentAudit.InspectionId : 0; model.IsCurrentAuditStarted = currentAudit != null && currentAudit.AuditItems != null?currentAudit.AuditItems.Any() : false; model.Question = currentAudit != null ? currentAudit.Survey.Name : ""; if (partial) { return(PartialView(model)); } return(View(model)); } else { var(Users, Teams) = await _applicationUsersService.GetUsersTeams("0", "All", KnownRoles.Operator); var model = await InspectionMapper.ToInspectionManageViewModel(inspections, team, userId, publicationId); model.CurrentAuditInspectionId = currentAudit != null ? currentAudit.Id : 0; model.IsCurrentAuditStarted = currentAudit != null && currentAudit.AuditItems != null?currentAudit.AuditItems.Any() : false; model.Question = currentAudit != null ? currentAudit.Survey.Name : ""; var inspectionPublications = await _prepareService.GetLastPublicationsForFilter((int)PublishModeEnum.Inspection); var teams = Teams.Select(t => t.Id).ToList(); var operators = Users.Select(u => u.UserId).ToList(); var publications = inspectionPublications.Select(p => p.PublicationId.ToString()).ToList(); model.selectedIndexTeam = (team == "0") ? 0 : teams.IndexOf(Convert.ToInt16(team)) + 1; model.selectedIndexOperator = (userId == "0") ? 0 : operators.IndexOf(Convert.ToInt16(userId)) + 1; model.selectedIndexPublication = (publicationId == "0") ? 0 : publications.IndexOf(publicationId) + 1; if (partial) { return(PartialView(model)); } return(View(model)); } }
public async Task ExportToExcel(string GridModel, string gridId, int id, string process) { ExcelExport exp = new ExcelExport(); GridProperties obj = (GridProperties)Syncfusion.JavaScript.Utils.DeserializeToModel(typeof(GridProperties), GridModel); //Clear if there are any filter columns //syncfusion bug in exporting while in filter mode obj.FilterSettings.FilteredColumns.Clear(); grid = gridId; count = 0; if (gridId == "InspectionDetail") { var inspection = await _prepareService.GetInspection(id); // Retrieve all the action of the publication var actionSorted = inspection.Publication.PublishedActions.Distinct() .OrderBy(a => a.WBSParts, new WBSPartsComparer()) .ToList(); var inspectionSteps = GetInspectionStepAndChilds(inspection, actionSorted); var model = InspectionMapper.ToInspectionViewModel(inspection, inspectionSteps, new List <Anomaly>()); var dataSource = model.Steps.ToList(); inspectionStepViewModelData = dataSource; var currentDate = DateTime.Today.ToShortDateString().Replace("/", "-"); obj.ServerExcelQueryCellInfo = QueryCellInfo; exp.Export(obj, dataSource, LocalizedStrings.GetString("Inspection") + " " + process + " " + currentDate + ".xlsx", ExcelVersion.Excel2013, false, false, "flat-saffron"); } if (gridId == "InspectionManage") { var inspections = await _prepareService.GetInspections(); var model = await InspectionMapper.ToInspectionManageViewModel(inspections); var dataSource = model.Inspections.ToList(); inspectionViewModelData = dataSource; var currentDate = DateTime.Today.ToShortDateString().Replace("/", "-"); obj.ServerExcelQueryCellInfo = QueryCellInfo; exp.Export(obj, dataSource, LocalizedStrings.GetString("Inspection") + " " + currentDate + ".xlsx", ExcelVersion.Excel2013, false, false, "flat-saffron"); } if (gridId == "Anomaly") { var inspection = await _prepareService.GetInspection(id); var anomalies = await _prepareService.GetAnomalies(id); var model = InspectionMapper.ToInspectionViewModel(inspection, new List <InspectionStep>(), anomalies); var dataSource = model.Anomalies.ToList(); var currentDate = DateTime.Today.ToShortDateString().Replace("/", "-"); exp.Export(obj, dataSource, LocalizedStrings.GetString("Anomaly") + " " + process + " " + currentDate + ".xlsx", ExcelVersion.Excel2013, false, false, "flat-saffron"); } }
public async Task <bool> CollectAndSendInspection() { try { var inspectionTypes = await _notificationService.GetNotificationTypes(NotificationCategory.Inspection); var inspectionType = inspectionTypes.FirstOrDefault(_ => _.NotificationCategory == NotificationCategory.Inspection); if (inspectionType == null) { return(false); } var inspections = await _notificationService.GetInspectionReport(); var anomalies = inspections.SelectMany(i => i.Anomalies).Distinct(); if (!inspections.Any()) { return(false); } var inspectionsModel = InspectionMapper.ToInspectionViewModels(inspections); var anomaliesModel = InspectionMapper.ToAnomalyViewModels(anomalies); var model = (inspectionsViewModel : inspectionsModel, anomaliesViewModel : anomaliesModel); List <byte[]> attachments = new List <byte[]>(); string pdfString = _notificationService.RenderViewToString(model, pdfTemplatePath, inspectionType.NotificationTypeSetting.PdfTemplate); var pdfAttachment = _notificationService.RenderViewToPdf(pdfString, pdfBase, baseUrl); attachments.Add(pdfAttachment); string bodyString = _notificationService.RenderViewToString(model, bodyTemplatePath, inspectionType.NotificationTypeSetting.BodyTemplate); await _notificationService.PushNotification(bodyString, inspectionType.Id, attachments, new List <string> { $"I - {DateTime.Today.AddDays(-1).ToString("yyMMdd")}" }); return(true); } catch (Exception ex) { Console.WriteLine(ex.Message); return(false); } }
public async Task <ActionResult> Detail(int id, bool partial = false) { ////check if user can create audit for inspection //var auditController = DependencyResolver.Current.GetService<AuditController>(); //var allowCreateAudit = await auditController.allowUserCreateAudit(); //ViewBag.AllowCreateAudit = allowCreateAudit; var inspection = await _prepareService.GetInspection(id); // Retrieve all the action of the publication var actionSorted = inspection.Publication.PublishedActions.Distinct() .OrderBy(a => a.WBSParts, new WBSPartsComparer()) .ToList(); var inspectionSteps = GetInspectionStepAndChilds(inspection, actionSorted); var anomalies = await _prepareService.GetAnomalies(id); var model = InspectionMapper.ToInspectionViewModel(inspection, inspectionSteps, anomalies.ToList()); if (partial) { return(PartialView(model)); } return(View(model)); }
public InspectionDAOImp(VehicleDAO vehicleDAO) { inspectionMapper = new InspectionMapper(); this.vehicleDAO = vehicleDAO; }
public VehicleHistoryDTO GetHistory(string vin) { VehicleHistoryDTO historyDTO = null; List <HistoricVehicle> historicVehicles = null; List <Inspection> historicInspections = null; using (VehicleTrackingDbContext context = new VehicleTrackingDbContext()) { historicVehicles = context.HistoricVehicles .Where(hv => hv.Vin == vin) .ToList(); historicInspections = context.Inspections .Include("IdUser") .Include("IdLocation") .Include("Damages") .Include("IdVehicle") .Where(i => i.IdVehicle.Vin == vin) .ToList(); if ((historicVehicles != null && historicVehicles.Count > 0) || (historicInspections != null && historicInspections.Count > 0)) { historyDTO = new VehicleHistoryDTO(); if (historicVehicles != null && historicVehicles.Count > 0) { List <HistoricVehicleDTO> historicVehiclesDTO = new List <HistoricVehicleDTO>(); foreach (HistoricVehicle historicVehicle in historicVehicles) { HistoricVehicleDTO historicVehicleDTO = new HistoricVehicleDTO(); historicVehicleDTO.Brand = historicVehicle.Brand; historicVehicleDTO.Color = historicVehicle.Color; historicVehicleDTO.CurrentLocation = historicVehicle.CurrentLocation; historicVehicleDTO.Date = historicVehicle.Date; historicVehicleDTO.Model = historicVehicle.Model; historicVehicleDTO.Status = historicVehicle.Status; historicVehicleDTO.Type = historicVehicle.Type; historicVehicleDTO.Vin = historicVehicle.Vin; historicVehicleDTO.Year = historicVehicle.Year; historicVehiclesDTO.Add(historicVehicleDTO); } historyDTO.VehicleHistory = historicVehiclesDTO; } if (historicInspections != null && historicInspections.Count > 0) { List <InspectionDTO> historicInspectionsDTO = new List <InspectionDTO>(); InspectionMapper inspectionMapper = new InspectionMapper(); foreach (Inspection historicInspection in historicInspections) { InspectionDTO historicInspectionDTO = inspectionMapper.ToDTO(historicInspection); historicInspectionsDTO.Add(historicInspectionDTO); } historyDTO.InspectionHistory = historicInspectionsDTO; } } } return(historyDTO); }
public async Task ExportToExcelAnomaly(string gridColumns, string gridHeaders, int id, string process) { try { List <Column> columnsInfos = (List <Column>)Syncfusion.JavaScript.Utils.DeserializeToModel(typeof(List <Column>), gridColumns); JavaScriptSerializer json_serializer = new JavaScriptSerializer(); var columnHeaders = JsonConvert.DeserializeObject <List <GridHeader> >(gridHeaders); var inspection = await _prepareService.GetInspection(id); var anomalies = await _prepareService.GetAnomalies(id); var model = InspectionMapper.ToInspectionViewModel(inspection, new List <InspectionStep>(), anomalies); var dataSource = model.Anomalies.ToList(); var fileName = LocalizedStrings.GetString("Anomaly") + " " + process + " " + ".xlsx"; using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; //application.DefaultVersion = ExcelVersion.Excel2013; IWorkbook workbook = application.Workbooks.Create(1); IWorksheet worksheet = workbook.Worksheets[0]; int rowCounter = 1; int columnCounter = 1; var headers = columnsInfos.Where(_ => _.Visible); var shapes = new List <IPictureShape>(); var rangeLocations = new List <RangeLocation>(); var shapeCounter = 1; // Adding headers foreach (var header in headers) { worksheet.Range[rowCounter, columnCounter].VerticalAlignment = ExcelVAlign.VAlignCenter; worksheet.Range[rowCounter, columnCounter].HorizontalAlignment = ExcelHAlign.HAlignCenter; worksheet.Range[rowCounter, columnCounter++].Text = columnHeaders.FirstOrDefault(h => h.Field == header.Field).HeaderText; } foreach (var data in dataSource) { rowCounter++; columnCounter = 1; foreach (var header in headers) { if (header.Field != "Photo" && (data.GetType().GetProperty(header.Field) == null || (data.GetType().GetProperty(header.Field).GetValue(data) == null && header.Field != "Description"))) { continue; } var range = worksheet.Range[rowCounter, columnCounter++]; switch (header.Field) { case "Photo": if (data.HasPhoto) { range.VerticalAlignment = ExcelVAlign.VAlignTop; try { range.Value = ""; var memoryStream = new MemoryStream(Convert.FromBase64String(data.RawPhoto)); var imageFile = Image.FromStream(memoryStream); int maxPixelSize = 500; double maxWidthPoints = maxPixelSize.PixelsToWidthPoints(); double maxHeightPoints = maxPixelSize.PixelsToHeightPoints(); var widthScale = Convert.ToInt32(maxWidthPoints / imageFile.Width.PixelsToWidthPoints() * 100.0); var heightScale = Convert.ToInt32(maxHeightPoints / imageFile.Height.PixelsToHeightPoints() * 100.0); var imageScaleInPercent = Math.Min(widthScale, heightScale); range.RowHeight = (imageFile.Height >= imageFile.Width ? maxHeightPoints : (imageFile.Height * imageScaleInPercent / 100.0).PixelsToHeightPoints()); range.ColumnWidth = maxWidthPoints; var shape = range.Worksheet.Pictures.AddPicture(range.Row, range.Column, imageFile, imageScaleInPercent, imageScaleInPercent); shape.Name = "shape" + shapeCounter; shapes.Add(shape); rangeLocations.Add(new RangeLocation { ShapeName = shape.Name, Row = range.Row, Column = range.Column }); shapeCounter++; } catch (Exception ex) { _traceManager.TraceError(ex, $"Error on {nameof(ExportToExcelAnomaly)}"); range.Value = ""; } } break; default: range.Value = data.GetType().GetProperty(header.Field).GetValue(data) == null ? "" : data.GetType().GetProperty(header.Field).GetValue(data).ToString(); break; } } } foreach (var shape in shapes) { //Rearrange cell height var range = worksheet.Range[rangeLocations.FirstOrDefault(r => r.ShapeName == shape.Name).Row, rangeLocations.FirstOrDefault(r => r.ShapeName == shape.Name).Column]; range.RowHeight = shape.Height.PixelsToHeightPoints(); } // Saving the workbook to disk in XLSX format workbook.SaveAs(fileName, ExcelSaveType.SaveAsXLS, System.Web.HttpContext.Current.Response, ExcelDownloadType.Open); } } catch (Exception e) { _traceManager.TraceError(e, $"Error on {nameof(ExportToExcelAnomaly)}"); } }
public async Task ExportToExcelInspectionDetail(string gridColumns, string gridHeaders, int id, string process) { try { List <Column> columnsInfos = (List <Column>)Syncfusion.JavaScript.Utils.DeserializeToModel(typeof(List <Column>), gridColumns); JavaScriptSerializer json_serializer = new JavaScriptSerializer(); var columnHeaders = JsonConvert.DeserializeObject <List <GridHeader> >(gridHeaders); var inspection = await _prepareService.GetInspection(id); // Retrieve all the action of the publication var actionSorted = inspection.Publication.PublishedActions.Distinct() .OrderBy(a => a.WBSParts, new WBSPartsComparer()) .ToList(); var inspectionSteps = GetInspectionStepAndChilds(inspection, actionSorted); var model = InspectionMapper.ToInspectionViewModel(inspection, inspectionSteps, new List <Anomaly>()); var dataSource = model.Steps.ToList(); var fileName = LocalizedStrings.GetString("Inspection") + " " + process + " " + ".xlsx"; using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; //application.DefaultVersion = ExcelVersion.Excel2013; IWorkbook workbook = application.Workbooks.Create(1); IWorksheet worksheet = workbook.Worksheets[0]; int rowCounter = 1; int columnCounter = 1; var headers = columnsInfos.Where(_ => _.Visible); var shapes = new List <IPictureShape>(); var rangeLocations = new List <RangeLocation>(); var shapeCounter = 1; // Adding headers foreach (var header in headers) { worksheet.Range[rowCounter, columnCounter].VerticalAlignment = ExcelVAlign.VAlignCenter; worksheet.Range[rowCounter, columnCounter].HorizontalAlignment = ExcelHAlign.HAlignCenter; worksheet.Range[rowCounter, columnCounter++].Text = columnHeaders.FirstOrDefault(h => h.Field == header.Field).HeaderText; } foreach (var data in dataSource) { rowCounter++; columnCounter = 1; foreach (var header in headers) { if (header.Field != "Photo" && (data.GetType().GetProperty(header.Field) == null || (data.GetType().GetProperty(header.Field).GetValue(data) == null && header.Field != "Description"))) { continue; } var range = worksheet.Range[rowCounter, columnCounter++]; switch (header.Field) { case "ActionLabel": if (data.Level > 0) { range.IndentLevel = 2; } range.Value = data.GetType().GetProperty(header.Field).GetValue(data).ToString(); break; case "IsOK": if (data.IsOK == true) { range.Value = "OK"; range.CellStyle.Color = Color.Green; range.CellStyle.Font.Color = ExcelKnownColors.White; } else { range.Value = "NOK"; range.CellStyle.Color = Color.Red; range.CellStyle.Font.Color = ExcelKnownColors.White; } break; case "Photo": if (data.HasThumbnail) { range.VerticalAlignment = ExcelVAlign.VAlignTop; var fileServer = ConfigurationManager.AppSettings["FileServerUri"]; var filePath = data.ThumbnailHash + data.ThumbnailExt; try { range.Value = ""; var downloadPath = Path.Combine(fileServer, "GetFile", filePath); downloadPath = downloadPath.Replace("\\", "/"); var webClient = new WebClient(); var imageBytes = webClient.DownloadData(downloadPath); var memoryStream = new MemoryStream(imageBytes); var imageFile = Image.FromStream(memoryStream); int maxPixelSize = 500; double maxWidthPoints = maxPixelSize.PixelsToWidthPoints(); double maxHeightPoints = maxPixelSize.PixelsToHeightPoints(); var widthScale = Convert.ToInt32(maxWidthPoints / imageFile.Width.PixelsToWidthPoints() * 100.0); var heightScale = Convert.ToInt32(maxHeightPoints / imageFile.Height.PixelsToHeightPoints() * 100.0); var imageScaleInPercent = Math.Min(widthScale, heightScale); range.RowHeight = (imageFile.Height >= imageFile.Width ? maxHeightPoints : (imageFile.Height * imageScaleInPercent / 100.0).PixelsToHeightPoints()) + 61; range.ColumnWidth = range.ColumnWidth >= maxWidthPoints + 22.86 ? range.ColumnWidth : maxWidthPoints + 22.86; var shape = range.Worksheet.Pictures.AddPicture(range.Row, range.Column, imageFile, imageScaleInPercent, imageScaleInPercent); shape.Name = "shape" + shapeCounter; shapes.Add(shape); rangeLocations.Add(new RangeLocation { ShapeName = shape.Name, Row = range.Row, Column = range.Column }); shapeCounter++; } catch (Exception ex) { _traceManager.TraceError(ex, $"Error on {nameof(ExportToExcelInspectionDetail)}"); range.Value = ""; } } break; default: range.Value = data.GetType().GetProperty(header.Field).GetValue(data) == null ? "" : data.GetType().GetProperty(header.Field).GetValue(data).ToString(); break; } } } foreach (var shape in shapes) { //Rearrange cell height var range = worksheet.Range[rangeLocations.FirstOrDefault(r => r.ShapeName == shape.Name).Row, rangeLocations.FirstOrDefault(r => r.ShapeName == shape.Name).Column]; range.RowHeight = shape.Height.PixelsToHeightPoints(); } // Saving the workbook to disk in XLSX format workbook.SaveAs(fileName, ExcelSaveType.SaveAsXLS, System.Web.HttpContext.Current.Response, ExcelDownloadType.Open); } } catch (Exception e) { _traceManager.TraceError(e, $"Error on {nameof(ExportToExcelInspectionDetail)}"); } }