public async Task<ActionResult> Index(EdStartEmail model) { string result = ""; Email_Service es = new Email_Service(); if (!ModelState.IsValid) { result = ModelState.Values.First().Errors.First().ErrorMessage; } else { if (es.EmailInteresting(model.Message)) result = "Your email has been added to our invite list. Thanks!"; else result = "Please try again !"; } ViewBag.message = result ; return View(); }
public Result Register(DatabaseContext db,HttpPostedFileBase file) { Result res = new Result(); using (var transaction = db.Database.BeginTransaction()) { try { // check email exist if (db.Accounts.Any(x => x.Email == this.Account.Email)) return res.Fail("This Email has already exist"); // if have file's Certificate , save file if (file != null) { string extension = Path.GetExtension(file.FileName); string fileName = ""; string path = ""; bool fileInvalid = true; // check if file's exist . If not : save , else : generate another file name do { // generate file's name by guid fileName = Config.CertificateUrl + Guid.NewGuid().ToString() + extension; path = HttpContext.Current.Server.MapPath("~"); path = path + fileName; fileInvalid = File.Exists(path + fileName); } while (fileInvalid); file.SaveAs(path); this.Certificate = fileName; } // create account login this.Account.Role = eRole.Investor; db.Accounts.Add(this.Account); db.SaveChanges(); if (this.Account.ID == 0) { transaction.Rollback(); return res.Fail("Create account fail"); } // create trustee db.Trustees.Add(this.Trustee); db.SaveChanges(); if (this.Account.ID == 0) { transaction.Rollback(); return res.Fail("Create trustee fail"); } // create investor information this.UserId = Account.ID; this.TrusteeId = Trustee.ID; db.Investors.Add(this); db.SaveChanges(); if (this.ID == 0) { transaction.Rollback(); return res.Fail("Create Investor information fail"); } transaction.Commit(); // send email congratulations for investor Email_Service es = new Email_Service(); es.InvestorRegister(this.Account.Email); es.Notification_Register(this.Account.Email,this.Account.Role); return res.Success(this); } catch (Exception ex) { transaction.Rollback(); return res.Fail(ex.Message); } } }