private CustomerCaseServiceResponse SaveCaseStatus(int supplierId, int customerId, int departmentId, Guid userId, bool supplierEmployeeLimitForOrder, Guid orderId) { CustomerCase @case = new CustomerCase { ForSupplierId = supplierId, FromCustomerId = customerId, FromDepartmentId = departmentId, FromUserId = userId, OrderId = orderId, Tracking = EntityTracker.StartTracking(ServiceId) // not directly by user, disputable }; CustomerCaseStatusEntry caseEntry = new CustomerCaseStatusEntry { Status = (supplierEmployeeLimitForOrder) ? CaseStatus.PendingSupplier : CaseStatus.PendingInternal, UserComments = (supplierEmployeeLimitForOrder) ? @"Waiting for Supplier response." : @"Waiting for Support response. Customer-Case has been sent to Support.", Tracking = EntityTracker.StartTracking(ServiceId) // not directly by user, disputable }; @case.CaseHistory.Add(caseEntry); //return CustomerCaseServiceLogic.SaveCustomerCase(work, @case); return(_customerCaseService.SaveCustomerCase(@case)); }
private void SendOrderToPrimaryEmail(AspNetUser user, string subject, string body, int caseId, string supplier, List <email_attachment> attachmentList, string channelId, int customerId, int deptId, ICollection <CustomerOrderAttachment> customer_Order_Attachment) { try { Logger.Info(String.Format("Email Sending to {0} with PrimaryEmail {1}", user.FirstName, user.Email)); EmailProvider client = new EmailProvider(channelId); var cwaUrl = ConfigurationManager.AppSettings["ChannelOneLoginUrl"] + channelId; if (channelId == "12") { cwaUrl = ConfigurationManager.AppSettings["ChannelTwoLoginUrl"] + channelId; } var emailContents = new Dictionary <string, string>(); emailContents.Add("SUPPLIER", supplier); emailContents.Add("NAME", user.FirstName + " " + user.LastName); emailContents.Add("URL", cwaUrl); emailContents.Add("TABLEBODY", body); var type = client.GetTemplateType("OfferRequestOrder", user.LanguageCode, Convert.ToInt32(channelId)); var slug = client.GetTemplateName(type); bool sent = false; if (attachmentList != null && attachmentList.ToList().Count > 0) { sent = client.Send(user.Email, emailContents, type, attachmentList); } else { sent = client.Send(user.Email, emailContents, type); } var mail = new MailMessage() { CustomerId = customerId, DepartmentId = deptId, CauseTrackingId = caseId, Kind = MessageKind.Received, ToAddress = user.Email, UserId = user.Id, HideFromUser = true, Tracking = EntityTracker.StartTracking(ServiceId) // not directly by user, disputable }; _mailMessageService.SaveMailMessage(mail, slug, channelId, emailContents); if (attachmentList != null && attachmentList.ToList().Count > 0) { SaveCustomerAttachmentsInMailMessage(customer_Order_Attachment, mail.MessageId); } Logger.Info($"Email Sent to {user.FirstName} with PrimaryEmail {user.Email}"); } catch (Exception ex) { Logger.Error(ex); } }
private static void CreateSystemUser(MeetUpDbContext context, Guid serviceId, string serviceName) { context.AspNetUsers.AddOrUpdate( m => m.Id, new AspNetUser { Id = serviceId, FirstName = serviceName, LastName = nameof(SystemUsers), Email = $"{serviceName.ToLower()}@sysusers.internal", // must be unique, and better conform to email format InternalEmail = $"#ERR_{serviceName}#", // not possible to email sys-users, yet must be unique, conform or not? IsSystemUser = true, LanguageCode = LanguageCode.English, Tracking = EntityTracker.StartTracking(SystemUsers.Migrator) }); }
private bool SaveCustomerAttachmentsInMailMessage(ICollection <CustomerOrderAttachment> customerOrderAttachment, Guid messgeId) { foreach (var item in customerOrderAttachment) { MailAttachment attachment = new MailAttachment { MessageId = messgeId, FileName = item.FileName, FileUrl = item.FileURL, FilePath = item.FilePath, MimeType = item.MimeType, Tracking = EntityTracker.StartTracking(ServiceId) // not directly by user, disputable }; _mailAttachmentService.SaveAttachemnts(attachment); } return(true); }
private MailMessageResponse SaveMailMessage(Guid userId, string name, string subject, string message, string senderEmail, string destinationEmail, int caseId, int companyId, int deptId) { MailMessage mailMessage = new MailMessage { UserId = userId, DisplayName = name, FromAddress = senderEmail, ToAddress = destinationEmail, Subject = subject, Body = message, CauseTrackingId = caseId, Status = MessageStatus.Read, CustomerId = companyId, DepartmentId = deptId, Kind = MessageKind.Sent, HideFromUser = true, Type = MessageType.Order, Tracking = EntityTracker.StartTracking(ServiceId) // not directly by user, disputable }; return(_mailMessageService.SaveMailMessage(mailMessage)); }
public static CustomerCaseServiceResponse SaveCustomerCase(IUnitOfWork work, CustomerCase customerCase) { Logger.Debug("SaveCustomerCase : customerId : " + customerCase?.FromCustomerId ?? "#NULL#"); if (customerCase != null) // TODO: throw ArgumentNulLException instead { CustomerCase customerCaseModel = null; if (customerCase.CaseId > 0) { customerCaseModel = work.Context.CustomerCases.FirstOrDefault(i => i.CaseId == customerCase.CaseId); } if (customerCaseModel != null) { customerCaseModel.Tracking.UpdateTracking(SystemUsers.CustomerCaseService); if (customerCase.FromUserId != Guid.Empty) { customerCaseModel.FromUserId = customerCase.FromUserId; } if (customerCase.ForSupplierId > 0) { customerCaseModel.ForSupplierId = customerCase.ForSupplierId; } if (customerCase.FromCustomerId > 0) { customerCaseModel.FromCustomerId = customerCase.FromCustomerId; } if (customerCase.FromDepartmentId > 0) { customerCaseModel.FromDepartmentId = customerCase.FromDepartmentId; } work.Context.CustomerCases.Update(customerCaseModel); // no SaveChanges! service do not own UOF object! return(new CustomerCaseServiceResponse { IsSuccess = true, CaseId = customerCase.CaseId, Message = ResponseMessage.RecordUpdated }); } else { customerCase.Tracking = EntityTracker.StartTracking(SystemUsers.CustomerCaseService); if (customerCase.CaseHistory != null && customerCase.CaseHistory.Count > 0) { foreach (var caseStatusEntry in customerCase.CaseHistory) { if (caseStatusEntry.EntryId == 0) { caseStatusEntry.Tracking.CreatedDateTimeUtc = DateTime.UtcNow; // ??? this one is bad caseStatusEntry.Tracking.ModifiedDateTimeUtc = DateTime.UtcNow; // TODO: TASK: update tracking object with user id } } } // TODO: this code is again quite bad and doing some magic with entities var newCase = work.Context.CustomerCases.FirstOrDefault(d => d.OrderId == customerCase.OrderId && customerCase.OrderId != null); if (newCase == null) { work.Context.CustomerCases.Add(customerCase); // Insert()? // no SaveChanges! service do not own UOF object! } else { return(new CustomerCaseServiceResponse { CaseId = newCase.CaseId, IsSuccess = true, Message = "Case Exists" }); } } return(new CustomerCaseServiceResponse { IsSuccess = true, CaseId = customerCase.CaseId, Message = ResponseMessage.RecordSaved }); } // WARN: this will throw null-ref... // TODO: throw ArgumentNulLException instead on top of the function, this is not recoverable bug // if parameters are null then sending error response return(new CustomerCaseServiceResponse { IsSuccess = false, CaseId = customerCase.CaseId, Message = ResponseMessage.InvalidParam }); }