public ActionResult UpdateCustomerAddress(CustomerAddressViewModel custaddress) { SR_Log_DatabaseSQLEntities db = new SR_Log_DatabaseSQLEntities(); if (custaddress.CustomerId != 0) { CustomerRepository objdata = new CustomerRepository(); if (string.IsNullOrEmpty(custaddress.Address1) == false) { custaddress.Address1 = custaddress.Address1.ToUpper(); } if (string.IsNullOrEmpty(custaddress.Address2) == false) { custaddress.Address2 = custaddress.Address2.ToUpper(); } if (string.IsNullOrEmpty(custaddress.City) == false) { custaddress.City = custaddress.City.ToUpper(); } if (string.IsNullOrEmpty(custaddress.Country) == false) { custaddress.Country = custaddress.Country.ToUpper(); } if (string.IsNullOrEmpty(custaddress.State) == false) { custaddress.State = custaddress.State.ToUpper(); } if (string.IsNullOrEmpty(custaddress.ZipCode) == false) { custaddress.ZipCode = custaddress.ZipCode.ToUpper(); } if (string.IsNullOrEmpty(custaddress.SiteName) == false) { custaddress.SiteName = custaddress.SiteName.ToUpper(); } objdata.AddUpdateCustomerAddress(custaddress, "Update"); tblCustomer customer = db.tblCustomers.Where(x => x.CustomerId == custaddress.CustomerId).FirstOrDefault(); var act = new ActivityRepository(); act.AddActivityLog(Convert.ToString(Session["User"]), "Edit address", "UpdateCustomerAddress", "Addresses for customer " + customer.CustomerName.ToUpper() + " edited by " + Convert.ToString(Session["User"]) + "."); } //CustomerRepository _repository = new CustomerRepository(); //var cust = _repository.GetCustomerDetails(custaddress.CustomerId); tblCustAddress cust = new tblCustAddress(); return(Json(cust, JsonRequestBehavior.AllowGet)); }
public ActionResult ImportCustomerAddress(HttpPostedFileBase postedFile) { try { string filePath = string.Empty; if (postedFile != null) { string path = Server.MapPath("~/ImportCustomerAddress/"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } filePath = path + Path.GetFileName(postedFile.FileName); string extension = Path.GetExtension(postedFile.FileName); postedFile.SaveAs(filePath); DataTable dtToExport = new DataTable(); int cnt = 0; using (StreamReader sr = new StreamReader(filePath)) { while (!sr.EndOfStream) { //string[] col = sr.ReadLine().Split(','); string[] col = Regex.Split(sr.ReadLine(), ",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)"); DataRow dr = dtToExport.NewRow(); if (col.Length > 0) { for (int i = 0; i < col.Length; i++) { if (cnt == 0) { DataColumn dc = new DataColumn(); dc.ColumnName = col[i].ToString(); dtToExport.Columns.Add(dc); } else { dr[i] = col[i].ToString(); } } if (cnt > 0) { dtToExport.Rows.Add(dr); } if (cnt == 0) { cnt++; } } } } string[] columnNames = dtToExport.Columns.Cast <DataColumn>().Select(x => x.ColumnName).ToArray(); if (columnNames[0] != "Customer Name" && columnNames[1] != "Street 1" && columnNames[2] != "Street 2" && columnNames[3] != "City" && columnNames[4] != "State" && columnNames[5] != "ZIP Code" && columnNames[6] != "Country" && columnNames[7] != "Site Name") { ViewBag.Message = "CSV file not in correct format. Please select valid CSV file and try again!"; return(View("ManageCustomerAddress")); } CustomerRepository _respository = new CustomerRepository(); for (int i = 0; i < dtToExport.Rows.Count; i++) { CustomerViewModel cst = new CustomerViewModel(); //cst.CustomerName = dtToExport.Rows[i][0].ToString(); cst.CustomerName = dtToExport.Rows[i][0].ToString().Replace(@"""", ""); // string cust = cst.CustomerName.Replace("\"", ""); cst.InActive = false; cst.Notes = ""; int CustomerId; CustomerId = _respository.AddUpdateCustomerImport(cst); // Call SaveActivityLog("frmImportCustomers", "Import Customer", "Customer " + cst.CustomerName + " added from csv file " + postedFile.FileName + " by user " + Convert.ToString(Session["User"]) + ".") var act = new ActivityRepository(); act.AddActivityLog(Convert.ToString(Session["User"]), "Import Customer", "ImportCustomer", "Customer " + cst.CustomerName + " added from csv file " + postedFile.FileName + " by user " + Convert.ToString(Session["User"]) + "."); if (dtToExport.Rows[i]["Street 1"].ToString() != "") { CustomerAddressViewModel cstAdd = new CustomerAddressViewModel(); cstAdd.CustomerId = CustomerId; cstAdd.Address1 = dtToExport.Rows[i][1].ToString(); cstAdd.Address2 = dtToExport.Rows[i][2].ToString(); cstAdd.City = dtToExport.Rows[i][3].ToString(); cstAdd.State = dtToExport.Rows[i][4].ToString(); cstAdd.ZipCode = dtToExport.Rows[i][5].ToString(); cstAdd.Country = dtToExport.Rows[i][6].ToString(); cstAdd.SiteName = dtToExport.Rows[i][7].ToString(); _respository.AddUpdateCustomerAddress(cstAdd, "Add"); act = new ActivityRepository(); act.AddActivityLog(Convert.ToString(Session["User"]), "Import Customer Address", "ImportCustomer", "Address added for customer " + cst.CustomerName + " from csv file " + postedFile.FileName + " by user " + Convert.ToString(Session["User"]) + "."); //Call SaveActivityLog("frmImportCustomers", "Import Customer Address", "Address added for customer " & fileColumns(0) & " from csv file " & cmdDialog.FileTitle & " by user " & UserInfo.UserName & ".") } } } else { ViewBag.Message = "Please select file to import"; } return(View("ManageCustomerAddress")); } catch (Exception ex) { ViewBag.Message = "CSV file not in correct format. Please select valid CSV file and try again!"; return(View("ManageCustomerAddress")); } }
public ActionResult CreateCustomerAddress(CustomerAddressViewModel custaddress) { SR_Log_DatabaseSQLEntities db = new SR_Log_DatabaseSQLEntities(); if (custaddress.CustomerId != 0) { var existcustcontact = db.tblCustAddresses.Where(x => x.Address1.Trim().ToUpper() == custaddress.Address1.Trim().ToUpper() && x.CustomerId == custaddress.CustomerId && x.SiteName.ToUpper() == custaddress.SiteName).FirstOrDefault(); if (existcustcontact != null) { ViewBag.Message = "This address is already added for this site. Please choose a different site name."; return(Json(custaddress, JsonRequestBehavior.AllowGet)); } else { CustomerRepository objdata = new CustomerRepository(); if (string.IsNullOrEmpty(custaddress.Address1) == false) { custaddress.Address1 = custaddress.Address1.ToUpper(); } if (string.IsNullOrEmpty(custaddress.Address2) == false) { custaddress.Address2 = custaddress.Address2.ToUpper(); } if (string.IsNullOrEmpty(custaddress.City) == false) { custaddress.City = custaddress.City.ToUpper(); } if (string.IsNullOrEmpty(custaddress.Country) == false) { custaddress.Country = custaddress.Country.ToUpper(); } if (string.IsNullOrEmpty(custaddress.State) == false) { custaddress.State = custaddress.State.ToUpper(); } if (string.IsNullOrEmpty(custaddress.ZipCode) == false) { custaddress.ZipCode = custaddress.ZipCode.ToUpper(); } if (string.IsNullOrEmpty(custaddress.SiteName) == false) { custaddress.SiteName = custaddress.SiteName.ToUpper(); } objdata.AddUpdateCustomerAddress(custaddress, "Add"); } } //CustomerRepository _repository = new CustomerRepository(); //var cust = _repository.GetCustomerDetails(custaddress.CustomerId); tblCustAddress cust = new tblCustAddress(); return(Json(cust, JsonRequestBehavior.AllowGet)); }