public ActionResult RegistrationEn(int?id) { ViewData["Title"] = "Сервисный центр: Registration"; Models.Login.Dir.DirCustomerReg dirCustomerReg = new Models.Login.Dir.DirCustomerReg(); dirCustomerReg.Refer = Convert.ToInt32(HttpContext.Request.QueryString["ref"]); return(View(dirCustomerReg)); }
public async Task <ActionResult> RegistrationUk(Models.Login.Dir.DirCustomerReg dirCustomerReg) { ViewData["Title"] = "Сервисный центр: реєстрація"; if (await Task.Run(() => mRegistration(dirCustomerReg, 2))) { return(View("RegistrationSuccess", dirCustomerReg)); } else { return(View(dirCustomerReg)); } }
private bool mRegistration(Models.Login.Dir.DirCustomerReg dirCustomerReg, int iLanguage) { //Для записи в БД, т.к. использовать "dirCustomerReg" нельзя! Models.Login.Dir.DirCustomer dirCustomer = new Models.Login.Dir.DirCustomer(); if (dirCustomerReg != null && ModelState.IsValid) { try { using (DbConnectionLogin con = new DbConnectionLogin("ConnStrMSSQL")) { #region Проверка // на существования такого логина int iCount = ( ( from dirCustomers in con.DirCustomers where dirCustomers.Login == dirCustomerReg.Login select dirCustomers.Login ).Concat ( from dirLoginNot in con.DirLoginNot where dirLoginNot.Login == dirCustomerReg.Login select dirLoginNot.Login ) ).Count(); if (iCount > 0) { con.Database.Connection.Close(); ViewData["Msg"] = Classes.Language.Login.Language.msg1(iLanguage); return(false); } // на существования такого реферала if (dirCustomerReg.Refer != 0) { int iCountRefer = ( from DirCustomers in con.DirCustomers where dirCustomerReg.DirCustomersID == dirCustomerReg.Refer select dirCustomerReg.Login ).Count(); if (iCountRefer == 0) { dirCustomerReg.Refer = 0; } } #endregion #region Сохраняем //Формирование пароля Classes.Function.FunctionMSSQL.RandomSymbol randomSymbol = new Classes.Function.FunctionMSSQL.RandomSymbol(); dirCustomerReg.Pswd = randomSymbol.ReturnRandom(10); //Переносим данные в "нужную" модель: dirCustomerReg => dirCustomer dirCustomer.DirCustomersDate = DateTime.Now; dirCustomer.Email = dirCustomerReg.Email; dirCustomer.Login = dirCustomerReg.Login; dirCustomer.DomainName = dirCustomerReg.Login; dirCustomer.Pswd = dirCustomerReg.Pswd; dirCustomer.Telefon = dirCustomerReg.Telefon; dirCustomer.FIO = dirCustomerReg.FIO; dirCustomer.DirLanguageID = dirCustomerReg.DirLanguageID; dirCustomer.DirCountryID = dirCustomerReg.DirCountryID; dirCustomer.Refer = dirCustomerReg.Refer; dirCustomer.SendMail = false; dirCustomer.Active = false; dirCustomer.Pay = true; dirCustomer.Confirmed = false; con.Entry(dirCustomer).State = EntityState.Added; try { con.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); foreach (var failure in ex.EntityValidationErrors) { //sb.AppendFormat("{0} failed validation\n", failure.Entry.Entity.GetType()); foreach (var error in failure.ValidationErrors) { sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage); sb.AppendLine(); } } throw new System.Data.Entity.Validation.DbEntityValidationException( //"Entity Validation Failed - errors follow:\n" + sb.ToString(), ex ); // Add the original exception as the innerException } /*catch (Exception ex) * { * throw new System.InvalidOperationException(ex.Message); * }*/ #endregion } #region Отправка письма на E-Mail try { //Текс на русском string sSendTest = Classes.Language.Login.Language.txtRegistrationMail(dirCustomer, iLanguage); Classes.Function.FunctionMSSQL.FunMailSend funMailSend = new Classes.Function.FunctionMSSQL.FunMailSend(); //Отправка клиенту funMailSend.SendTo_OtherEMail(Classes.Language.Login.Language.msg2(iLanguage), sSendTest, dirCustomer.Email); //Отправка себе try { funMailSend.SendTo_ESklad24(Classes.Language.Login.Language.msg2(iLanguage), "E-Mail: " + dirCustomer.Email + ", Login: "******"<br />" + Classes.Language.Login.Language.msg2(iLanguage) + "<hr />" + sSendTest); } catch { } } catch (Exception ex) { ViewData["Msg"] = Classes.Language.Login.Language.msg4(iLanguage) + ex.Message + ""; ViewData["Title"] = Classes.Language.Login.Language.msg5(iLanguage); return(true); } #endregion using (DbConnectionLogin con = new DbConnectionLogin("ConnStrMSSQL")) { #region Пишем в БД, что Мейл отправлен (SendMail=true) dirCustomer.SendMail = true; con.Entry(dirCustomer).State = EntityState.Modified; con.SaveChanges(); #endregion } } catch (Exception ex) { string sMsg = exceptionEntry.Return(ex); ViewData["Msg"] = Classes.Language.Login.Language.error(iLanguage) + ": <br />" + sMsg + "<br /> " + Classes.Language.Login.Language.msg6(iLanguage) + ": <a href='mailto:[email protected]' rel='nofollow'>[email protected]</a>"; return(false); } ViewData["Title"] = Classes.Language.Login.Language.msg5(iLanguage); ViewData["Msg"] = Classes.Language.Login.Language.msg7(iLanguage); return(true); } else { return(false); } }