/// <summary> /// Prepare HTML Msg Body /// </summary> /// <returns></returns> private string PrepareHtmlBody(BomRequestViewModel requestViewModel) { if (requestViewModel.BomRequestNodes != null && requestViewModel.BomRequestNodes.Any()) { StringBuilder sb = new StringBuilder(); var materialItems = requestViewModel.BomRequestNodes.Where(x => x.Type == BomItemType.Material).ToList(); if (materialItems.Any()) { var materialItemNumbers = string.Join(", ", materialItems.Select(x => x.ItemNumber)); sb.Append("<div class='description'>"); sb.Append("<div><span> I would like to order subsea " + BomItemType.Material.ToString() + "</span></div>"); sb.Append("<div><span class='form-header'>Part Name/Number: </span><span class='form-data'>" + materialItemNumbers + "</span></div>"); sb.Append("</div>"); } var equipmentItems = requestViewModel.BomRequestNodes.Where(x => x.Type == BomItemType.Equipment).ToList(); if (equipmentItems.Any()) { var equipmentItemNumbers = string.Join(", ", equipmentItems.Select(x => x.ItemNumber)); sb.Append("<div class='description'>"); sb.Append("<div><span> I would like to order subsea " + BomItemType.Equipment.ToString() + "</span></div>"); sb.Append("<div><span class='form-header'>Equipment Name/Number: </span><span class='form-data'>" + equipmentItemNumbers + "</span></div>"); sb.Append("</div>"); } return(sb.ToString()); } return(null); }
/// <summary> /// Prepare Email options for various system requests /// </summary> /// <param name="requestViewModel"></param> /// <returns></returns> private EmailOptions PrepareEmailOptions(BomRequestViewModel requestViewModel) { var emailOptions = new EmailOptions { Template = MailTemplate.BillOfMaterial, PlainBody = string.Empty, Attachments = new List <Attachment>() }; var msgBody = SendGridMailHelper.MailBody(_hostingEnvironment, emailOptions.Template); if (!string.IsNullOrEmpty(msgBody)) { emailOptions.Subject = "Request for Bill Of Material Received - SubQuip"; emailOptions.CcMail = new MailUser { Name = "SubQuip", Email = _configuration["requestEmail"] }; emailOptions.ToMailsList = requestViewModel.MailUsers; emailOptions.HtmlBody = msgBody.Replace("{BomDescription}", requestViewModel.Description).Replace("{Description}", PrepareHtmlBody(requestViewModel)).Replace("{FromDate}", requestViewModel.FromDate.ToString("dd-MM-yyyy")).Replace("{ToDate}", requestViewModel.ToDate.ToString("dd-MM-yyyy")); } return(emailOptions); }
/// <summary> /// Insert BOM Request /// </summary> /// <param name="requestViewModel"></param> /// <returns></returns> public IResult InsertBOMRequest(List <FileDetails> fileList, BomRequestViewModel bomRequestViewModel) { bomRequestViewModel.RequestId = null; var result = new Result { Operation = Operation.Create, Status = Status.Success }; try { var bomRequest = new Request(); bomRequest.MapFromViewModel(bomRequestViewModel, (ClaimsIdentity)_principal.Identity); bomRequest.MailUsers = new List <MailUserDetails>(); if (bomRequestViewModel.MailUsers != null && bomRequestViewModel.MailUsers.Any()) { bomRequest.MailUsers = bomRequestViewModel.MailUsers.Select(user => { var mailUser = new MailUserDetails(); mailUser.MapFromViewModel(user); return(mailUser); }).ToList(); } if (bomRequestViewModel.BomRequestNodes != null && bomRequestViewModel.BomRequestNodes.Any()) { bomRequest.BomRequestNodes = bomRequestViewModel.BomRequestNodes.Select(t => { var bomNode = new BomRequestNode(); bomNode.MapFromViewModel(t); return(bomNode); }).ToList(); } if (!string.IsNullOrEmpty(bomRequestViewModel.RegardingId)) { bomRequest.RegardingId = ObjectId.Parse(bomRequestViewModel.RegardingId); } _requestRepository.InsertOne(bomRequest); if (fileList != null && fileList.Any()) { bomRequest.Files = fileList.Select(fileViewModel => { var file = new File(); file.MapFromViewModel(fileViewModel, (ClaimsIdentity)_principal.Identity); _fileRepository.InsertOne(file); return(file.FileId); }).ToList(); } var updateDefinition = Builders <Request> .Update.Set(t => t.Files, bomRequest.Files); _requestRepository.UpdateOne(t => t.RequestId.Equals(bomRequest.RequestId), updateDefinition); if (bomRequest.Files != null && bomRequest.Files.Any()) { bomRequestViewModel.Files = new List <string>(); bomRequest.Files.ForEach(x => bomRequestViewModel.Files.Add(x.ToString())); } result.Body = bomRequestViewModel.MapFromModel(bomRequest); result.Message = RequestNotification.Created; } catch (Exception e) { result.Message = e.Message; result.Status = Status.Fail; } return(result); }