public ReturnData AJAX_BE_StatusToggle(int idCustomer) { try { DataClassesDataContext db = new DataClassesDataContext(); TBCustomer selected = db.TBCustomers.Where(x => x.IDCustomer == idCustomer && !x.Deflag).FirstOrDefault(); if (selected == null) { return(ReturnData.MessageFailed("Data not found", null)); } selected.Active = !selected.Active; selected.DateLastUpdate = DateTime.Now; db.SubmitChanges(); return(ReturnData.MessageSuccess(selected.FirstName + " status has changed", null)); } catch (Exception ex) { return(ReturnData.MessageFailed(ex.Message, null)); } }
public ReturnData AJAX_FE_RegisterCustomGroup(string firstName, string lastName, string gender, string email, string password, string phoneNumber, DateTime birthday, bool isSubscribe, string addressname, string address, string postalCode, int idCountry, int idProvince, int idCity, int idDistrict, int idCustomerGroup, string DeliveryAddressName) { try { using (DataClassesDataContext db = new DataClassesDataContext()) { if (idCustomerGroup == 3) { if (IsExistsEmail(email)) { return(ReturnData.MessageFailed("Email is already registered, Please update following customer data", null)); } var customerGroup = db.TBCustomer_Groups.Where(x => x.IDCustomer_Group == idCustomerGroup).FirstOrDefault(); TBCustomer _newCust = new TBCustomer(); _newCust.FirstName = firstName; _newCust.LastName = lastName; _newCust.Gender = gender; _newCust.Email = email; _newCust.Password = EncryptPassword(password); _newCust.PhoneNumber = phoneNumber; _newCust.Birthday = birthday; _newCust.IsSubscribe = isSubscribe; _newCust.Active = true; _newCust.DateInsert = DateTime.Now; _newCust.DateLastUpdate = DateTime.Now; _newCust.IDCustomer_Group = idCustomerGroup; db.TBCustomers.InsertOnSubmit(_newCust); //db.SubmitChanges(); TBAddress _newAddress = new TBAddress(); _newAddress.TBCustomer = _newCust; _newAddress.IDCountry = idCountry; _newAddress.IDProvince = idProvince; _newAddress.IDCity = idCity; _newAddress.IDDistrict = idDistrict; _newAddress.Name = addressname; _newAddress.Address = address; _newAddress.Phone = _newCust.PhoneNumber; _newAddress.PostalCode = postalCode; _newAddress.PeopleName = DeliveryAddressName; _newAddress.Active = true; _newAddress.DateInsert = DateTime.Now; _newAddress.DateLastUpdate = DateTime.Now; db.TBAddresses.InsertOnSubmit(_newAddress); db.SubmitChanges(); Dictionary <string, dynamic> result = new Dictionary <string, dynamic>(); result.Add("IDCustomer", _newCust.IDCustomer); result.Add("IDAddress", _newAddress.IDAddress); //SEND EMAIL using (StreamReader reader = new StreamReader(HttpContext.Current.Server.MapPath("~/assets/email-template/template-email-register.html"))) { Class_Configuration _config = new Class_Configuration(); var emailLogo = _config.Dynamic_Get_EmailLogo(); string body = ""; body = reader.ReadToEnd(); body = body.Replace("{name}", _newCust.FirstName); body = body.Replace("{email}", _newCust.Email); body = body.Replace("{password}", password); body = body.Replace("{title}", System.Configuration.ConfigurationManager.AppSettings["Title"]); body = body.Replace("{email_logo}", System.Configuration.ConfigurationManager.AppSettings["url"] + "/assets/images/email_logo/" + emailLogo); body = body.Replace("{shop_url}", System.Configuration.ConfigurationManager.AppSettings["url"]); OurClass.SendEmail(_newCust.Email, WebConfigurationManager.AppSettings["Title"] + " Account Registration", body, ""); } return(ReturnData.MessageSuccess("Register success", result)); } else { var adminOrder = db.TBCustomers.Where(x => x.IDCustomer_Group == 4 && x.Email.ToLower() == email).FirstOrDefault(); if (adminOrder == null) { return(ReturnData.MessageFailed("Account not found", null)); } TBAddress _newAddress = new TBAddress(); _newAddress.IDCustomer = adminOrder.IDCustomer; _newAddress.IDCountry = idCountry; _newAddress.IDProvince = idProvince; _newAddress.IDCity = idCity; _newAddress.IDDistrict = idDistrict; _newAddress.Name = addressname; _newAddress.Address = address; _newAddress.Phone = phoneNumber; _newAddress.PostalCode = postalCode; _newAddress.PeopleName = DeliveryAddressName; _newAddress.Active = true; _newAddress.DateInsert = DateTime.Now; _newAddress.DateLastUpdate = DateTime.Now; db.TBAddresses.InsertOnSubmit(_newAddress); db.SubmitChanges(); Dictionary <string, dynamic> result = new Dictionary <string, dynamic>(); result.Add("IDCustomer", adminOrder.IDCustomer); result.Add("IDAddress", _newAddress.IDAddress); return(ReturnData.MessageSuccess("Register success", result)); } } } catch (Exception ex) { return(ReturnData.MessageFailed(ex.Message, null)); } }
protected void btnImport_Click(object sender, EventArgs e) { if (fuFile.HasFile) { lblSuccess.Text = ""; lblError.Text = ""; try { DataClassesDataContext db = new DataClassesDataContext(); Class_Employee emp = new Class_Employee(); //if (emp.DecryptToken(HttpContext.Current.Request.Cookies[System.Configuration.ConfigurationManager.AppSettings["cookieAdmin"].ToString()].Value) == null || HttpContext.Current.Request.Cookies[System.Configuration.ConfigurationManager.AppSettings["cookieAdmin"].ToString()] == null) { fuFile.SaveAs(Server.MapPath("~/assets/import/customer/" + fuFile.FileName)); StreamReader sr = new StreamReader(Server.MapPath("~/assets/import/customer/" + fuFile.FileName)); try { CsvReader csvread = new CsvReader(sr); csvread.Configuration.Delimiter = ";"; csvread.Configuration.HasHeaderRecord = false; char[] delimeter = { ',' }; List <CSV_Customer> record = csvread.GetRecords <CSV_Customer>().ToList(); int totalRead = 0; int totalNotfound = 0; int totalUpdate = 0; List <TBCustomer> listCustomer = new List <TBCustomer>(); foreach (var item in record) { totalRead++; TBCustomer cust = db.TBCustomers.Where(x => !x.Deflag && x.IDCustomer_Group == 1 && x.Email == item.Email).FirstOrDefault(); //var employee = emp.GetData_By_Token(HttpContext.Current.Request.Cookies[System.Configuration.ConfigurationManager.AppSettings["cookieAdmin"].ToString()].Value); if (cust == null) { TBCustomer newCust = new TBCustomer(); newCust.FirstName = item.FirstName; newCust.LastName = item.LastName; newCust.Email = item.Email; if (item.Gender == 2) { newCust.Gender = "P"; } else { newCust.Gender = "L"; } newCust.DateInsert = DateTime.ParseExact(item.CreateDate, "dd/MM/yyyy H:mm", System.Globalization.CultureInfo.InvariantCulture); newCust.DateLastUpdate = DateTime.ParseExact(item.LastUpdateDate, "dd/MM/yyyy H:mm", System.Globalization.CultureInfo.InvariantCulture); if (item.Birthday != null && item.Birthday != "NULL") { newCust.Birthday = DateTime.ParseExact(item.Birthday, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture); } newCust.IDCustomer_Group = 1; newCust.Active = true; newCust.Password = ""; //Class_Customer classCustomer = new Class_Customer(); //string text = item.Email + "-" + item.FirstName.Substring(0, 2); //string pass = classCustomer.EncryptToken(item.Email, DateTime.Now.ToString("MMddHHmmss")); //newCust.Password = pass; listCustomer.Add(newCust); db.SP_Insert_Customer(1, item.FirstName, item.LastName, newCust.Gender, item.Email, "", "", newCust.Birthday, true, newCust.DateInsert, newCust.DateLastUpdate); } else { totalNotfound++; } } //db.TBCustomers.InsertAllOnSubmit(listCustomer); //db.SubmitChanges(); foreach (var item in listCustomer) { Class_Customer classCustomer = new Class_Customer(); classCustomer.AJAX_Forget_Password(item.Email); } sr.Close(); lblSuccess.Text += totalRead + " row(s) read, " + totalUpdate + " row(s) updated, " + totalNotfound + " row(s) customer exists"; alertError.Style.Add(HtmlTextWriterStyle.Display, "none"); alertSuccess.Style.Add(HtmlTextWriterStyle.Display, "block"); } catch (Exception ex) { sr.Close(); lblError.Text = ex.Message; alertError.Style.Add(HtmlTextWriterStyle.Display, "block"); alertSuccess.Style.Add(HtmlTextWriterStyle.Display, "none"); } } } catch (Exception ex) { lblError.Text = ex.Message; alertError.Style.Add(HtmlTextWriterStyle.Display, "block"); alertSuccess.Style.Add(HtmlTextWriterStyle.Display, "none"); } } }