Пример #1
0
        public ActionResult CreateCustomerContact(CustomerContactViewModel custconact)
        {
            SR_Log_DatabaseSQLEntities db = new SR_Log_DatabaseSQLEntities();

            if (custconact.CustomerId != 0)
            {
                var existcustcontact = db.tblCustContacts.Where(x => x.CustomerContact.Trim().ToUpper() == custconact.CustomerContact.Trim().ToUpper() && x.CustomerId == custconact.CustomerId).FirstOrDefault();
                if (existcustcontact != null)
                {
                    ViewBag.Message = "This Contact already present. Please add different name And Try Again.";
                    return(Json(custconact, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    CustomerRepository objdata = new CustomerRepository();
                    if (string.IsNullOrEmpty(custconact.ContactEmail) == false)
                    {
                        custconact.ContactEmail = custconact.ContactEmail.ToUpper();
                    }

                    if (string.IsNullOrEmpty(custconact.ContactPhone) == false)
                    {
                        custconact.ContactPhone = custconact.ContactPhone.ToUpper();
                    }

                    if (string.IsNullOrEmpty(custconact.CustomerContact) == false)
                    {
                        custconact.CustomerContact = custconact.CustomerContact.ToUpper();
                    }


                    objdata.AddUpdateCustomerContact(custconact, "Add");
                }
            }

            //CustomerRepository _repository = new CustomerRepository();
            //var cust = _repository.GetCustomerDetails(custconact.CustomerId);
            tblCustContact cust = new tblCustContact();

            return(Json(cust, JsonRequestBehavior.AllowGet));



            //db.Products.InsertOnSubmit(product);
            //db.SubmitChanges();
            //return Json(cust, JsonRequestBehavior.AllowGet);

            //CustomerRepository _repository = new CustomerRepository();
            //var cust = _repository.GetCustomerDetails(2);
            //// parts.Add(new Part() {PartName="crank arm", PartId=1234});
            //cust.lstCustContact.Add(new tblCustContact() { Id = 0, CustomerId = 0, CustomerContact = product.CustomerContact, ContactEmail = product.ContactEmail, IsPrimaryContact = product.IsPrimaryContact });
            //return View("Index", cust);
        }
Пример #2
0
        public ActionResult UpdateCustomerContact(CustomerContactViewModel custconact)
        {
            SR_Log_DatabaseSQLEntities db = new SR_Log_DatabaseSQLEntities();

            if (custconact.CustomerId != 0)
            {
                CustomerRepository objdata = new CustomerRepository();
                if (string.IsNullOrEmpty(custconact.ContactEmail) == false)
                {
                    custconact.ContactEmail = custconact.ContactEmail.ToUpper();
                }

                if (string.IsNullOrEmpty(custconact.ContactPhone) == false)
                {
                    custconact.ContactPhone = custconact.ContactPhone.ToUpper();
                }

                if (string.IsNullOrEmpty(custconact.CustomerContact) == false)
                {
                    custconact.CustomerContact = custconact.CustomerContact.ToUpper();
                }

                objdata.AddUpdateCustomerContact(custconact, "Update");

                tblCustomer customer = db.tblCustomers.Where(x => x.CustomerId == custconact.CustomerId).FirstOrDefault();
                var         act      = new ActivityRepository();
                act.AddActivityLog(Convert.ToString(Session["User"]), "Edit Contact", "UpdateCustomerContact", "Contacts for customer " + customer.CustomerName.ToUpper() + " edited by " + Convert.ToString(Session["User"]) + ".");
                //Call SaveActivityLog("frmAddCustomer", "Edit Contact", "Contacts for customer " & UCase(txtCustomerName.Text) & " edited by " & UserInfo.UserName)
            }


            //CustomerRepository _repository = new CustomerRepository();
            //var cust = _repository.GetCustomerDetails(custconact.CustomerId);
            tblCustContact cust = new tblCustContact();

            return(Json(cust, JsonRequestBehavior.AllowGet));
        }
Пример #3
0
        public ActionResult ImportCustomerContacts(HttpPostedFileBase postedFile)
        {
            try
            {
                string filePath = string.Empty;
                if (postedFile != null)
                {
                    string path = Server.MapPath("~/ImportCustomerContacts/");
                    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] != "Customer Contact" && columnNames[2] != "Contact Phone" && columnNames[3] != "Contact Email")
                    {
                        ViewBag.Message = "CSV file not in correct format. Please select valid CSV file and try again!";
                        return(View("ManageCustomerContacts"));
                    }
                    CustomerRepository _respository = new CustomerRepository();
                    for (int i = 0; i < dtToExport.Rows.Count; i++)
                    {
                        CustomerViewModel cst = new CustomerViewModel();
                        cst.CustomerName = dtToExport.Rows[i][0].ToString().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", "ImportCustomerContacts", "Customer " + cst.CustomerName + " added from csv file " + postedFile.FileName + " by user " + Convert.ToString(Session["User"]) + ".");
                        if (dtToExport.Rows[i][1].ToString() != "" && dtToExport.Rows[i][2].ToString() != " && dtToExport.Rows[i][3].ToString() != ")
                        {
                            CustomerContactViewModel cstAdd = new CustomerContactViewModel();
                            cstAdd.CustomerId       = CustomerId;
                            cstAdd.CustomerContact  = dtToExport.Rows[i][1].ToString();
                            cstAdd.ContactPhone     = dtToExport.Rows[i][2].ToString();
                            cstAdd.ContactEmail     = dtToExport.Rows[i][3].ToString();
                            cstAdd.IsPrimaryContact = false;
                            // cstAdd.DateAdded = System.DateTime.Now;
                            CommonFunctions c = new CommonFunctions();
                            cstAdd.DateAdded = c.GetCurrentDate();

                            _respository.AddUpdateCustomerContact(cstAdd, "Add");
                            act = new ActivityRepository();
                            act.AddActivityLog(Convert.ToString(Session["User"]), "Import Customer Contacts", "ImportCustomer", "Contacts added for customer " + cst.CustomerName + " from csv file " + postedFile.FileName + " by user " + Convert.ToString(Session["User"]) + ".");
                        }
                    }
                }
                else
                {
                    ViewBag.Message = "Please select file to import";
                }

                return(View("ManageCustomerContacts"));
            }
            catch (Exception ex)
            {
                ViewBag.Message = "CSV file not in correct format. Please select valid CSV file and try again!";
                return(View("ManageCustomerContacts"));
            }
        }