public ShiftManagement ToEntity() { var shiftManagement = new ShiftManagement(); shiftManagement.ID = Id; shiftManagement.Department.LookupId = Department.Id; shiftManagement.Requester.LookupId = Requester.LookupId; shiftManagement.Month = Month; shiftManagement.Year = Year; shiftManagement.Location.LookupId = Location.LookupId; if (ApprovedBy != null) { shiftManagement.ApprovedBy = new User { FirstName = ApprovedBy.FirstName, FullName = ApprovedBy.FullName, ID = ApprovedBy.ID, IsGroup = ApprovedBy.IsGroup, LastName = ApprovedBy.LastName, UserName = ApprovedBy.UserName }; } if (AdditionalUser != null) { var userList = new List <User>(); userList.AddRange(AdditionalUser.Select(item => new User { FirstName = item.FirstName, FullName = item.FullName, ID = item.ID, IsGroup = item.IsGroup, LastName = item.LastName, UserName = item.UserName })); shiftManagement.CommonAddApprover1 = userList; } if (ModifiedBy != null) { shiftManagement.ModifiedBy = new User { FirstName = ModifiedBy.FirstName, FullName = ModifiedBy.FullName, ID = ModifiedBy.ID, IsGroup = ModifiedBy.IsGroup, LastName = ModifiedBy.LastName, UserName = ModifiedBy.UserName }; } return(shiftManagement); }
public ActionResult ConfirmClaimPost(IEnumerable <HttpPostedFileBase> UserFiles) { using (AirHelpDBContext dc = new AirHelpDBContext()) { var BookCode = Request.Form["BookCode"]; var TikedNumber = Request.Form["TikedNumber"]; var AdditionalInfo = Request.Form["AdditionalInfo"]; var claimId = Request.Form["claimId"]; var SignitureImage = Request.Form["SignitureImage"]; var Name = Request.Form["Name"]; var Family = Request.Form["Family"]; bool signOnEmail = Request.Form["SignViaEmail"] == "yes" ? true : false; var ClaimId = Guid.Parse(claimId); var claim = dc.Claims .Include("User") .Include("Documents") .Include("AdditionalUsers") .Include("AirPorts") .Where(c => c.ClaimId == ClaimId).SingleOrDefault(); if (claim.State > ClaimStatus.Pending) { var url = $"/иск/{claim.ClaimId}"; Response.Redirect(url); } if (!string.IsNullOrEmpty(Name)) { var arrN = Name.Split(','); var arrF = Family.Split(','); for (var i = 0; i < arrN.Length; i++) { AdditionalUser user = new AdditionalUser { AdditionalUserId = Guid.NewGuid(), FirstName = arrN[i], LastName = arrF[i] }; claim.AdditionalUsers.Add(user); } } claim.SignitureImage = SignitureImage; claim.AdditionalInfo = AdditionalInfo; claim.TikedNumber = TikedNumber; claim.BookingCode = BookCode; if (UserFiles != null) { foreach (var file in UserFiles) { if (file != null && file.ContentLength > 0) { var name = Guid.NewGuid().ToString().Replace("-", "") + "." + file.FileName.Split('.')[1]; file.SaveAs(Server.MapPath("~/UserDocuments/" + name)); claim.Documents.Add(new Document { Id = Guid.NewGuid(), DocumentName = name, Url = "/документи/" + name.Split('.')[0] + "/" + name.Split('.')[1] }); } } } claim.State = signOnEmail ? ClaimStatus.WaitForAttorny : (claim.Documents.Count > 0 ? ClaimStatus.InProgress : ClaimStatus.WaitForDocument); Guid newGuid = Guid.NewGuid(); var attorneyName = string.Format("attorney{0}", claim.referalNumber.ToString("0000")); var contractName = string.Format("contract{0}", claim.referalNumber.ToString("0000")); claim.AttorneyUrl = $"/документи/{attorneyName}/pdf"; claim.contractUrl = $"/документи/{contractName}/pdf"; dc.SaveChanges(); string port = Request.Url.Port == 80 ? string.Empty : $":{Request.Url.Port.ToString()}"; String aUrl = $"{Request.Url.Scheme}://{Request.Url.Host}{port}/attorneyPdf-09-234-5644-34e5345-2343246/{claim.ClaimId}"; String cUrl = $"{Request.Url.Scheme}://{Request.Url.Host}{port}/contractPdf-09-4565-3453-2345435-2355/{claim.ClaimId}"; SelectPdf.HtmlToPdf converter = new SelectPdf.HtmlToPdf(); converter.Options.MarginTop = 30; converter.Options.MarginBottom = 10; converter.Options.MarginLeft = 20; converter.Options.MarginRight = 20; converter.Options.PdfPageSize = SelectPdf.PdfPageSize.A4; SelectPdf.PdfDocument doc = converter.ConvertUrl(aUrl); doc.Save(Server.MapPath($"~/UserDocuments/{attorneyName}.pdf")); doc.Close(); doc = converter.ConvertUrl(cUrl); doc.Save(Server.MapPath($"~/UserDocuments/{contractName}.pdf")); doc.Close(); Session["claim"] = claim; string bosy = $"<h1>Заявка #{claim.referalNumber.ToString("0000")}</h1><p>От: {claim.User.FirstName} {claim.User.LastName}</p><p><а href='helpclaim.eu/иск/{claim.ClaimId}'>заявка</а></p>"; MailMessage message = new MailMessage(); message.To.Add(new MailAddress("*****@*****.**")); message.To.Add(new MailAddress("*****@*****.**")); message.To.Add(new MailAddress("*****@*****.**")); message.To.Add(new MailAddress("*****@*****.**")); message.Subject = "message"; message.Body = bosy; message.IsBodyHtml = true; try { using (var smtp = new SmtpClient()) { smtp.Port = 25; smtp.EnableSsl = false; smtp.Credentials = new System.Net.NetworkCredential("*****@*****.**", "P@ssw0rd6712"); smtp.Host = "mail.helpclaim.eu"; smtp.Send(message); } } catch (Exception ex) { return(View("ViewClaim", claim)); } return(View("ViewClaim", claim)); } }