// GET: Customer_Project/Edit/5 public ActionResult Edit(int?id) { if (Utilities.IsUserLogged()) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Customer_Project customer_Project = db.Customer_Project.Find(id); if (customer_Project == null) { return(HttpNotFound()); } if (customer_Project.deactivation == true && customer_Project.copy_file == true && customer_Project.copy_db == true && customer_Project.change_file == true && customer_Project.restore_project == true && customer_Project.upgrade_project == true && customer_Project.undo_checkouts == true && customer_Project.verify_project == true && customer_Project.verification == true && customer_Project.release == true) { ViewBag.allchecks = true; } else { ViewBag.allchecks = false; } return(View(customer_Project)); } else { return(RedirectToAction("Login", "Home")); } }
public ActionResult Create([Bind(Include = "id,customer_name,customer_url,deactivation,undo_checkouts,copy_file,copy_db,change_file,restore_project,verify_project,upgrade_project,verification,deactivation,release,initialNotification,finalNotification,service_id,upgrade_type,upgrade_version,dry_run")] Customer_Project customer_Project) { if (ModelState.IsValid) { try { if (customer_Project.customer_name.Contains("batch")) { customer_Project.customer_name.Replace("batch", "Batch"); } customer_Project.customerId = Guid.NewGuid(); db.Customer_Project.Add(customer_Project); db.SaveChanges(); return(RedirectToAction("Edit", new { id = customer_Project.id })); } catch (Exception ex) { if (ex.GetBaseException().GetType() == typeof(SqlException)) { //Violation of primary key/Unique constraint can be handled here. Also you may //check if Exception Message contains the constraint Name String m = ex.InnerException.InnerException.Message; if (m.Contains("Violation of UNIQUE KEY constraint")) { Session["message"] = "The customer name is already in use"; return(View(customer_Project)); } } } } return(View(customer_Project)); }
public ActionResult Edit([Bind(Include = "id,customer_name,customer_url,deactivation,undo_checkouts,copy_file,copy_db,change_file,restore_project,verify_project,upgrade_project,verification,release,customerId,initialNotification,finalNotification,service_id,upgrade_type,upgrade_version,dry_run")] Customer_Project customer_Project) { if (ModelState.IsValid) { db.Entry(customer_Project).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Edit", new { id = customer_Project.id }));//return to same view } return(View(customer_Project)); }
public ActionResult NotifyCustomer(int id, int notificationType, string comments) { if (Utilities.IsUserLogged()) { List <HttpPostedFileBase> attachments = new List <HttpPostedFileBase>(); try { HttpFileCollectionBase files = Request.Files; for (int i = 0; i < files.Count; i++) { //save the attachments attachments.Add(files[i]); } } catch (Exception ex) { return(Json("Error uploading file")); } //get the email list for the specific project List <Project_Email> list = db.Project_Email.Where(x => x.project_id == id).ToList(); Customer_Project c = db.Customer_Project.Find(id); EmailHandler email = new EmailHandler(); Boolean result = email.NotifyCustomer(list, notificationType, comments, attachments, c); if (result == true) { if (notificationType == 1) { c.initialNotification = true; } else if (notificationType == 3) { c.finalNotification = true; } db.SaveChanges(); // Returns message that successfully uploaded return(Json("The notification was sent correctly.")); } else { // Returns message that successfully uploaded return(Json("Unable to send notification, please try again.")); } } else { return(Json("-1")); } }
// GET: Customer_Project/Delete/5 public ActionResult Delete(int?id) { if (Utilities.IsUserLogged()) { Customer_Project customer_Project = db.Customer_Project.Find(id); db.Customer_Project.Remove(customer_Project); db.SaveChanges(); return(RedirectToAction("Index")); } else { return(RedirectToAction("Login", "Home")); } }
// GET: Customer_Project/Details/5 public ActionResult Details(int?id) { if (Utilities.IsUserLogged()) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Customer_Project customer_Project = db.Customer_Project.Find(id); if (customer_Project == null) { return(HttpNotFound()); } return(View(customer_Project)); } else { return(RedirectToAction("Login", "Home")); } }
public string Save(Project project, List <Asset> assets, List <Customer> buyers, List <Customer> sellers, List <Customer> thirdpart, List <Guarantor> Guarantor, List <CreditReceiverInfo> creditInfo, string userid) { #region 初始化变量 ISqlMapper mapper = Common.GetMapperFromSession(); ProjectDao projectdao = new ProjectDao(mapper); AssetDao assetdao = new AssetDao(mapper); Asset_ProjectDao apdao = new Asset_ProjectDao(mapper); Customer_ProjectDao cpdao = new Customer_ProjectDao(mapper); CustomerDao customerdao = new CustomerDao(mapper); Customer_AssetDao cadao = new Customer_AssetDao(mapper); CreditReceiverInfoDao cridao = new CreditReceiverInfoDao(mapper); AssetBLL assetbll = new AssetBLL(); CustomerBLL customerbll = new CustomerBLL(); #endregion #region 处理项目信息 DateTime createstart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0); DateTime createend = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59); if (string.IsNullOrEmpty(project.Name)) { int index = projectdao.QueryMaxProjectIndex(new ProjectQueryForm { CreateTime_Start = createstart, CreateTime_End = createend }); string code = DateTime.Now.ToString("yyMMdd") + (index + 1).ToString(); project.Name = code; project.Index = index + 1; } project.Creator = project.LastUpdator = userid; project.IsDeleted = 0; var projecttemp = projectdao.Query(new ProjectQueryForm { ID = project.ID }).FirstOrDefault(); if (projecttemp == null) { projectdao.Add(project); } else { projectdao.Update(new ProjectUpdateForm { Entity = project, ProjectQueryForm = new ProjectQueryForm { ID = project.ID }, }); } cpdao.Delete(new Customer_ProjectQueryForm { ProjectID = project.ID }); cadao.Delete(new Customer_AssetQueryForm { ProjectID = project.ID }); apdao.Delete(new Asset_ProjectQueryForm { ProjectID = project.ID }); #endregion #region 处理房产信息 if (assets != null) { foreach (var asset in assets) { asset.Creator = userid; var a = assetbll.Save(asset); //处理房产和公权人 foreach (var j in asset.Joint) { var c = customerbll.Save(new Customer { Creator = userid, Name = j.Name, IdentityCode = j.IdentityCode, Phone = j.Phone, }); cadao.Add(new Customer_Asset { AssetID = a.ID, CustomerID = c.ID, ProjectID = project.ID, Type = j.JointType, }); } //处理房产和项目关系 Asset_Project ap = new Asset_Project { AssetID = a.ID, ProjectID = project.ID, }; apdao.Add(ap); } } #endregion #region 处理客户信息 ProcessCustomer(buyers, customerdao, cpdao, project.ID, userid, CustomerType.Buyer); ProcessCustomer(sellers, customerdao, cpdao, project.ID, userid, CustomerType.Seller); ProcessCustomer(thirdpart, customerdao, cpdao, project.ID, userid, CustomerType.ThirdParty); #endregion #region 处理共权人信息 if (Guarantor != null) { foreach (Guarantor g in Guarantor) { g.Creator = userid; var c = customerbll.Save(g); Customer_Project cp = new Customer_Project { CustomerID = c.ID, ProjectID = project.ID, Type = (int)CustomerType.Guarantor, }; cpdao.Add(cp); foreach (var asset in g.Assets) { asset.Creator = userid; var a = assetbll.Save(asset); Customer_Asset ca = new Customer_Asset { AssetID = a.ID, CustomerID = c.ID, ProjectID = project.ID, Type = (int)CustomerAssetType.Guarantor, }; cadao.Add(ca); } } } #endregion #region 处理贷款接收账号信息 cridao.Delete(new CreditReceiverInfoQueryForm { ProjectID = project.ID }); if (creditInfo != null) { foreach (var c in creditInfo) { c.ProjectID = project.ID; cridao.Add(c); } } #endregion return(project.ID); }
private String GetCheckText(Customer_Project c) { String checks = "<ul>"; if (c.upgrade_type == false) {//SaaS To SaaS if (c.deactivation == true) { checks += "<li><strong>Deactivate:</strong><ul>"; checks += "<li>Deactivate all projects</li>"; checks += "</ul></li>"; } if (c.undo_checkouts || c.copy_file || c.copy_db || c.change_file) { checks += "<li><strong>Data Copy:</strong><ul>"; if (c.undo_checkouts) { checks += "<li>If VC enabled, verify checkouts</li>"; } if (c.copy_file) { checks += "<li>Copy repository files</li>"; } if (c.copy_db) { checks += "<li>Copy DB schemas</li>"; } if (c.change_file) { checks += "<li>Update configuration files</li>"; } checks += "</ul></li>"; } if (c.restore_project || c.verify_project || c.upgrade_project) { checks += "<li><strong>Upgrade:</strong><ul>"; if (c.restore_project) { checks += "<li>Restore the projects from Site Admin</li>"; } if (c.verify_project) { checks += "<li>Run Verify tool on projects to be migrated</li>"; } if (c.upgrade_project) { checks += "<li>Upgrade projects to desired version</li>"; } checks += "</ul></li>"; } if (c.verification) { checks += "<li><strong>Verification:</strong><ul>"; checks += "<li>Complete internal validation process</li>"; checks += "</ul></li>"; } if (c.release) { checks += "<li><strong>Release:</strong><ul>"; checks += "<li>Projects Released for validation</li>"; checks += "</ul></li>"; } } else {//in house if (c.deactivation == true) { checks += "<li><strong>Download:</strong><ul>"; checks += "<li>Download data from FTP</li>"; checks += "</ul></li>"; } if (c.undo_checkouts || c.copy_file || c.copy_db || c.change_file) { checks += "<li><strong>Data Copy:</strong><ul>"; if (c.copy_file) { checks += "<li>Copy repository files</li>"; } if (c.copy_db) { checks += "<li>Copy DB schemas</li>"; } if (c.change_file) { checks += "<li>Update configuration files</li>"; } if (c.undo_checkouts) { checks += "<li>If VC enabled, verify checkouts</li>"; } checks += "</ul></li>"; } if (c.restore_project || c.verify_project || c.upgrade_project) { checks += "<li><strong>Upgrade:</strong><ul>"; if (c.restore_project) { checks += "<li>Restore the projects from Site Admin</li>"; } if (c.verify_project) { checks += "<li>Run Verify tool on projects to be migrated</li>"; } if (c.upgrade_project) { checks += "<li>Upgrade projects to desired version</li>"; } checks += "</ul></li>"; } if (c.verification) { checks += "<li><strong>Verification:</strong><ul>"; checks += "<li>Complete internal validation process</li>"; checks += "</ul></li>"; } if (c.release) { checks += "<li><strong>Release:</strong><ul>"; checks += "<li>Projects Released for validation</li>"; checks += "</ul></li>"; } } checks += "</ul>"; return(checks); }
public Boolean NotifyCustomer(List <Project_Email> list, int notificationType, String comments, List <HttpPostedFileBase> attachments, Customer_Project c) { Boolean result = false; MailMessage msg = new MailMessage(); msg.To.Clear(); foreach (Project_Email p in list) { MailAddress emailTo = new MailAddress(p.email, p.email); if (!msg.To.Contains(emailTo)) { //to avoid adding duplicate email addresses msg.To.Add(emailTo); } } msg.From = new MailAddress(HttpContext.Current.Session["user_email"].ToString(), HttpContext.Current.Session["username"].ToString()); int attachIndex = 0; foreach (HttpPostedFileBase f in attachments) {//go through all the attachments var attachment = new Attachment(attachments[attachIndex].InputStream, attachments[attachIndex].FileName); msg.Attachments.Add(attachment); ++attachIndex; } //String inhouse = HttpContext.Current.Session["inhouse"].ToString(); switch (notificationType) { case 1: //initial if (c.upgrade_type == true) { //in house if (c.dry_run) { msg.Subject = c.customer_name + " - " + c.service_id + " - In house to SaaS Dry Run " + c.upgrade_version; msg.Body = System.IO.File.ReadAllText(HostingEnvironment.MapPath(@"~/Content/initial_inhouse.txt")); msg.Body = msg.Body.Replace("migration", "Dry Run"); } else { msg.Subject = c.customer_name + " - " + c.service_id + " - In house to SaaS Project Migration " + c.upgrade_version; msg.Body = System.IO.File.ReadAllText(HostingEnvironment.MapPath(@"~/Content/initial_inhouse.txt")); } } else { if (c.dry_run) { msg.Subject = c.customer_name + " - " + c.service_id + " - SaaS to SaaS Dry Run " + c.upgrade_version; msg.Body = System.IO.File.ReadAllText(HostingEnvironment.MapPath(@"~/Content/initial_dry_run.txt")); } else { msg.Subject = c.customer_name + " - " + c.service_id + " - SaaS to SaaS Migration/Upgrade " + c.upgrade_version; msg.Body = System.IO.File.ReadAllText(HostingEnvironment.MapPath(@"~/Content/initial.txt")); } } //check if the keyword Batch appears in the customer name if (c.customer_name.Contains("Batch") || c.customer_name.Contains("batch")) { msg.Body = msg.Body.Replace("@CUSTOMER", c.customer_name.Remove(c.customer_name.IndexOf("Batch"), c.customer_name.Length - c.customer_name.IndexOf("Batch"))); } else { msg.Body = msg.Body.Replace("@CUSTOMER", c.customer_name); } msg.Body = msg.Body.Replace("@URL", c.customer_url); msg.Body = msg.Body.Replace("@LINK", "upgradetool.azurewebsites.net/Customer_Project/Status/" + c.customerId); msg.Body = Regex.Replace(msg.Body, @"(\r\n)|\n|\r", "<br/>"); break; case 2: //intermediate if (c.upgrade_type == true) { if (c.dry_run) { msg.Subject = c.customer_name + " - " + c.service_id + " - In house to SaaS Dry Run " + c.upgrade_version; msg.Body = System.IO.File.ReadAllText(HostingEnvironment.MapPath(@"~/Content/intermediate.txt")); msg.Body = msg.Body.Replace("migration", "Dry Run"); } else { msg.Subject = c.customer_name + " - " + c.service_id + " - In house to SaaS Project Migration " + c.upgrade_version; msg.Body = System.IO.File.ReadAllText(HostingEnvironment.MapPath(@"~/Content/intermediate.txt")); } } else { if (c.dry_run) { msg.Subject = c.customer_name + " - " + c.service_id + " - SaaS to SaaS Dry Run " + c.upgrade_version; msg.Body = System.IO.File.ReadAllText(HostingEnvironment.MapPath(@"~/Content/intermediate.txt")); msg.Body = msg.Body.Replace("migration", "Dry Run"); } else { msg.Subject = c.customer_name + " - " + c.service_id + " - SaaS to SaaS Migration/Upgrade " + c.upgrade_version; msg.Body = System.IO.File.ReadAllText(HostingEnvironment.MapPath(@"~/Content/intermediate.txt")); } } msg.Body = System.IO.File.ReadAllText(HostingEnvironment.MapPath(@"~/Content/intermediate.txt")); //check if the keyword Batch appears in the customer name if (c.customer_name.Contains("Batch") || c.customer_name.Contains("batch")) { msg.Body = msg.Body.Replace("@CUSTOMER", c.customer_name.Remove(c.customer_name.IndexOf("Batch"), c.customer_name.Length - c.customer_name.IndexOf("Batch"))); } else { msg.Body = msg.Body.Replace("@CUSTOMER", c.customer_name); } msg.Body = msg.Body.Replace("@URL", c.customer_url); msg.Body = msg.Body.Replace("@CHECKBOXES", GetCheckText(c)); comments = Regex.Replace(comments, @"(\r\n)|\n|\r", "<br/>"); msg.Body = msg.Body.Replace("@COMMENTS", comments); msg.Body = msg.Body.Replace("@LINK", "upgradetool.azurewebsites.net/Customer_Project/Status/" + c.customerId); msg.Body = Regex.Replace(msg.Body, @"(\r\n)|\n|\r", "<br/>"); break; case 3: //final if (c.upgrade_type == true) { if (c.dry_run) { msg.Subject = c.customer_name + " - " + c.service_id + " - In house to SaaS Dry Run " + c.upgrade_version; msg.Body = System.IO.File.ReadAllText(HostingEnvironment.MapPath(@"~/Content/final.txt")); } else { msg.Subject = c.customer_name + " - " + c.service_id + " - In house to SaaS Project Migration " + c.upgrade_version; msg.Body = System.IO.File.ReadAllText(HostingEnvironment.MapPath(@"~/Content/final.txt")); } } else { if (c.dry_run) { msg.Subject = c.customer_name + " - " + c.service_id + " - SaaS to SaaS Dry Run " + c.upgrade_version; msg.Body = System.IO.File.ReadAllText(HostingEnvironment.MapPath(@"~/Content/final.txt")); } else { msg.Subject = c.customer_name + " - " + c.service_id + " - SaaS to SaaS Migration/Upgrade " + c.upgrade_version; msg.Body = System.IO.File.ReadAllText(HostingEnvironment.MapPath(@"~/Content/final.txt")); } } //check if the keyword Batch appears in the customer name if (c.customer_name.Contains("Batch") || c.customer_name.Contains("batch")) { msg.Body = msg.Body.Replace("@CUSTOMER", c.customer_name.Remove(c.customer_name.IndexOf("Batch"), c.customer_name.Length - c.customer_name.IndexOf("Batch"))); } else { msg.Body = msg.Body.Replace("@CUSTOMER", c.customer_name); } msg.Body = msg.Body.Replace("@URL", c.customer_url); msg.Body = msg.Body.Replace("@LINK", "upgradetool.azurewebsites.net/Customer_Project/Status/" + c.customerId); msg.Body = Regex.Replace(msg.Body, @"(\r\n)|\n|\r", "<br/>"); break; } //Reading the email template files in order to send String htmlEmailStart = System.IO.File.ReadAllText(HostingEnvironment.MapPath(@"~/Content/email-start.html")); String htmlEmailEnd = System.IO.File.ReadAllText(HostingEnvironment.MapPath(@"~/Content/email-end.html")); msg.Body = htmlEmailStart + msg.Body + htmlEmailEnd; msg.IsBodyHtml = true; SmtpClient client = new SmtpClient(); client.UseDefaultCredentials = false; client.Credentials = new System.Net.NetworkCredential(HttpContext.Current.Session["user_email"].ToString(), HttpContext.Current.Session["user_pass"].ToString()); client.Port = 587; // You can use Port 25 if 587 is blocked client.Host = "smtp.office365.com"; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.EnableSsl = true; try { client.Send(msg); result = true;//good } catch (Exception ex) { result = false;//error sending message } finally { client.Dispose();//close the connection } return(result); }