public async Task <ActionResult> New(string id, string source) { if (source == "order") { var rentalsDAL = new ROLWeb.Models.Rentals.RentalsDAL(); var orderDetails = rentalsDAL.GetRentalOrderDetails(this.ActiveCustomer, id); if (orderDetails == null) { return(HttpNotFound()); } var model = new NewImprovementViewModel(); model.CustomerId = this.ActiveCustomer.CustomerId; model.CustomerName = orderDetails.AccountName; model.ComplaintSource = "order"; model.ReferenceId = id; model.ReferenceText = String.Format("{0}: {1}. {2}: {3}.", Resources.RentalOrder, orderDetails.SalesId, Resources.MachineSerialNumber, orderDetails.ObjectId); return(View(model)); } else if (source == "invoice") { var invoice = await db.GetInvoiceDetails(this.ActiveCustomer, id); if (invoice == null) { return(HttpNotFound()); } var model = new NewImprovementViewModel(); model.CustomerId = invoice.InvoiceAccount; model.CustomerName = invoice.AccountName; model.ComplaintSource = "invoice"; model.ReferenceId = id; model.ReferenceText = String.Format("{0}: {1}.", Resources.InvoiceNumber, id); return(View(model)); } else if (source == "direct") { var model = new NewImprovementViewModel(); model.CustomerId = this.ActiveCustomer.CustomerId; model.CustomerName = this.ActiveCustomer.Name; model.ComplaintSource = "direct"; model.ReferenceId = id; model.ReferenceText = Resources.NoReference; return(View(model)); } return(HttpNotFound()); }
public async Task <ActionResult> New(NewImprovementViewModel model) { if (ModelState.IsValid && (model.ComplaintSource == "order" || model.ComplaintSource == "direct" || model.ComplaintSource == "invoice")) { var complaintsDAL = new ROLWeb.Models.Improvements.ImproventsDAL(); var rentalsDAL = new ROLWeb.Models.Rentals.RentalsDAL(); Customer custId = new Customer(); StringBuilder sb = new StringBuilder(); List <Attachment> attachments = new List <Attachment>(); byte[] file = null; if (model.file != null) { var inputFile = new MemoryStream(); await model.file.InputStream.CopyToAsync(inputFile); inputFile.Seek(0, 0); attachments.Add(new Attachment(inputFile, model.file.FileName)); inputFile.Seek(0, 0); file = inputFile.ToArray(); } if (model.ComplaintSource == "order") { var orderDetails = rentalsDAL.GetRentalOrderDetails(this.ActiveCustomer, model.ReferenceId); if (orderDetails == null) { return(View("FormSubmitted", new FormSubmittedViewModel { Title = Resources.Error, Message = Resources.DataProvidedNotValid })); } custId.DatabaseName = this.ActiveCustomer.DatabaseName; custId.CompanyId = this.ActiveCustomer.CompanyId; custId.CustomerId = this.ActiveCustomer.CustomerId; custId.Name = orderDetails.AccountName; //Register complaint var complaint = new Complaint { UserId = User.Identity.GetUserId(), DatabaseName = custId.DatabaseName, CompanyId = custId.CompanyId, CustomerId = custId.CustomerId, Description = model.Description ?? "", SuggestedSolution = model.SuggestedSolution ?? "", ComplaintSource = "order", ReferenceId = orderDetails.InventTransId, StatusId = "10", Answer = "", Attachment = file }; complaint.ComplaintId = await complaintsDAL.InsertComplaint(complaint); sb.AppendFormat("<h2>MyRiwal {0}</h2>", Resources.NewImprovementForm); sb.AppendLine("<table>"); sb.AppendFormat("<tr><td>{0}:</td><td>{1:dd-MM-yyyy HH:mm}</td></tr>\n", Resources.DateTime, DateTime.Now); sb.AppendFormat("<tr><td>MyRiwal {0}:</td><td>{1}</td></tr>\n", Resources.UserName, ((System.Security.Claims.ClaimsIdentity)User.Identity).FindFirst("FullName").Value); sb.AppendFormat("<tr><td></td><td></td></tr>\n"); sb.AppendFormat("<tr><td>{0}:</td><td></td></tr>\n", Resources.FormDetails); sb.AppendFormat("<tr><td>{0}:</td><td>{1}</td></tr>\n", Resources.CompanyNumber, this.ActiveCustomer.CompanyId); sb.AppendFormat("<tr><td>{0}:</td><td>{1}</td></tr>\n", Resources.CustomerNumber, orderDetails.CustAccount); sb.AppendFormat("<tr><td>{0}:</td><td>{1}</td></tr>\n", Resources.CustomerName, orderDetails.AccountName); sb.AppendFormat("<tr><td>{0}:</td><td>{1}</td></tr>\n", Resources.ImprovementNumber, complaint.ComplaintKey); sb.AppendFormat("<tr><td>{0}:</td><td>{1}</td></tr>\n", Resources.RentalOrder, orderDetails.SalesId); sb.AppendFormat("<tr><td>{0}:</td><td>{1}</td></tr>\n", Resources.MachineSerialNumber, orderDetails.ObjectId); sb.AppendFormat("<tr><td>{0}:</td><td>{1}</td></tr>\n", Resources.FleetNumber, orderDetails.AssetId); sb.AppendLine("</table>"); sb.AppendLine("<br /><br />"); sb.AppendFormat("{0}: <br />", Resources.ImprovementDescription); sb.AppendLine(model.Description); sb.AppendLine("<br /><br />"); sb.AppendFormat("{0}: <br />", Resources.SuggestedSolution); sb.AppendLine(model.SuggestedSolution); } // end source="order" else if (model.ComplaintSource == "invoice") { var invoice = (await db.GetInvoiceDetails(this.ActiveCustomer, model.ReferenceId)); if (invoice == null) { return(View("FormSubmitted", new FormSubmittedViewModel { Title = Resources.Error, Message = Resources.DataProvidedNotValid })); } custId.DatabaseName = this.ActiveCustomer.DatabaseName; custId.CompanyId = this.ActiveCustomer.CompanyId; custId.CustomerId = invoice.InvoiceAccount; custId.Name = invoice.AccountName; //Register complaint var complaint = new Complaint { UserId = User.Identity.GetUserId(), DatabaseName = custId.DatabaseName, CompanyId = custId.CompanyId, CustomerId = custId.CustomerId, Description = model.Description ?? "", SuggestedSolution = model.SuggestedSolution ?? "", ComplaintSource = "invoice", ReferenceId = invoice.InvoiceId, StatusId = "10", Answer = "", Attachment = file }; complaint.ComplaintId = await complaintsDAL.InsertComplaint(complaint); sb.AppendFormat("<h2>MyRiwal {0}</h2>", Resources.NewImprovementForm); sb.AppendLine("<table>"); sb.AppendFormat("<tr><td>{0}:</td><td>{1:dd-MM-yyyy HH:mm}</td></tr>\n", Resources.DateTime, DateTime.Now); sb.AppendFormat("<tr><td>MyRiwal {0}:</td><td>{1}</td></tr>\n", Resources.UserName, ((System.Security.Claims.ClaimsIdentity)User.Identity).FindFirst("FullName").Value); sb.AppendFormat("<tr><td></td><td></td></tr>\n"); sb.AppendFormat("<tr><td>{0}:</td><td></td></tr>\n", Resources.FormDetails); sb.AppendFormat("<tr><td>{0}:</td><td>{1}</td></tr>\n", Resources.CompanyNumber, this.ActiveCustomer.CompanyId); sb.AppendFormat("<tr><td>{0}:</td><td>{1}</td></tr>\n", Resources.CustomerNumber, invoice.InvoiceAccount); sb.AppendFormat("<tr><td>{0}:</td><td>{1}</td></tr>\n", Resources.CustomerName, invoice.AccountName); sb.AppendFormat("<tr><td>{0}:</td><td>{1}</td></tr>\n", Resources.ImprovementNumber, complaint.ComplaintKey); sb.AppendFormat("<tr><td>{0}:</td><td>{1}</td></tr>\n", Resources.InvoiceNumber, invoice.InvoiceId); sb.AppendLine("</table>"); sb.AppendLine("<br /><br />"); sb.AppendFormat("{0}: <br />", Resources.ImprovementDescription); sb.AppendLine(model.Description); sb.AppendLine("<br /><br />"); sb.AppendFormat("{0}: <br />", Resources.SuggestedSolution); sb.AppendLine(model.SuggestedSolution); } // end source="invoice" else if (model.ComplaintSource == "direct") { custId.DatabaseName = this.ActiveCustomer.DatabaseName; custId.CompanyId = this.ActiveCustomer.CompanyId; custId.CustomerId = this.ActiveCustomer.CustomerId; custId.Name = this.ActiveCustomer.Name; //Register complaint var complaint = new Complaint { UserId = User.Identity.GetUserId(), DatabaseName = custId.DatabaseName, CompanyId = custId.CompanyId, CustomerId = custId.CustomerId, Description = model.Description ?? "", SuggestedSolution = model.SuggestedSolution ?? "", ComplaintSource = "direct", ReferenceId = "", StatusId = "10", Answer = "", Attachment = file }; complaint.ComplaintId = await complaintsDAL.InsertComplaint(complaint); sb.AppendFormat("<h2>MyRiwal {0}</h2>", Resources.NewImprovementForm); sb.AppendLine("<table>"); sb.AppendFormat("<tr><td>{0}:</td><td>{1:dd-MM-yyyy HH:mm}</td></tr>\n", Resources.DateTime, DateTime.Now); sb.AppendFormat("<tr><td>MyRiwal {0}:</td><td>{1}</td></tr>\n", Resources.UserName, ((System.Security.Claims.ClaimsIdentity)User.Identity).FindFirst("FullName").Value); sb.AppendFormat("<tr><td></td><td></td></tr>\n"); sb.AppendFormat("<tr><td>{0}:</td><td></td></tr>\n", Resources.FormDetails); sb.AppendFormat("<tr><td>{0}:</td><td>{1}</td></tr>\n", Resources.CompanyNumber, this.ActiveCustomer.CompanyId); sb.AppendFormat("<tr><td>{0}:</td><td>{1}</td></tr>\n", Resources.CustomerNumber, custId.CustomerId); sb.AppendFormat("<tr><td>{0}:</td><td>{1}</td></tr>\n", Resources.CustomerName, custId.Name); sb.AppendFormat("<tr><td>{0}:</td><td>{1}</td></tr>\n", Resources.ImprovementNumber, complaint.ComplaintKey); sb.AppendLine("</table>"); sb.AppendLine("<br /><br />"); sb.AppendFormat("{0}: <br />", Resources.ImprovementDescription); sb.AppendLine(model.Description); sb.AppendLine("<br /><br />"); sb.AppendFormat("{0}: <br />", Resources.SuggestedSolution); sb.AppendLine(model.SuggestedSolution); } // end source="direct" string userEmail = ((System.Security.Claims.ClaimsIdentity)User.Identity).FindFirst("Email").Value; string onRentEmail = await rentalsDAL.GetOnRentEmailAddress(custId); if (MailClient.SendEmail(custId, Resources.NewImprovementForm, sb.ToString(), null, userEmail, onRentEmail, null, attachments)) { return(View("FormSubmitted", new FormSubmittedViewModel { Title = Resources.FormSubmitted, Message = Resources.RequestSubmitted })); } return(View("FormSubmitted", new FormSubmittedViewModel { Title = Resources.Error, Message = Resources.RequestNotSent })); } // modelstate.isvalid return(View("FormSubmitted", new FormSubmittedViewModel { Title = Resources.Error, Message = Resources.DataProvidedNotValid })); }