コード例 #1
0
        public ActionResult Save(CustomerViewModel cust)
        {
            ModelState.Remove("CustomerId");
            int CustomerId = 0;

            CustomerId = cust.CustomerId;
            if (ModelState.IsValid)
            {
                // string jobsite = Convert.ToString(form["hdnJobSiteAddress"]);
                string Customer = cust.CustomerName.ToUpper();
                cust.CustomerName = cust.CustomerName.ToUpper();
                if (string.IsNullOrEmpty(cust.Notes) == false)
                {
                    cust.Notes = cust.Notes.ToUpper();
                }

                SR_Log_DatabaseSQLEntities db = new SR_Log_DatabaseSQLEntities();


                if (cust.CustomerId != 0)
                {
                    var editcust = db.tblCustomers.Where(x => x.CustomerName.Trim().ToUpper() == Customer.Trim().ToUpper() && x.CustomerId != cust.CustomerId).FirstOrDefault();
                    if (editcust != null)
                    {
                        cust.CustomerId       = cust.CustomerId;
                        ViewBag.CustomerId    = cust.CustomerId;
                        ViewBag.Message       = "This Customer already present. Please add different name And Try Again.";
                        ViewBag.Adddisable    = true;
                        ViewBag.Deletedisable = true;
                        var customerexist = _repository.GetCustomerDetails(Convert.ToInt32(CustomerId));
                        cust.lstCustAddress = customerexist.lstCustAddress;
                        cust.lstCustContact = customerexist.lstCustContact;
                        return(View("Index", cust));
                    }
                }
                else
                {
                    var existcust = db.tblCustomers.Where(x => x.CustomerName.Trim().ToUpper() == Customer.Trim().ToUpper()).FirstOrDefault();
                    if (existcust != null)
                    {
                        cust.CustomerId       = cust.CustomerId;
                        ViewBag.CustomerId    = cust.CustomerId;
                        ViewBag.Message       = "This Customer already present. Please add different name And Try Again.";
                        ViewBag.Adddisable    = true;
                        ViewBag.Deletedisable = true;
                        var customerexist2 = _repository.GetCustomerDetails(Convert.ToInt32(CustomerId));
                        cust.lstCustAddress = customerexist2.lstCustAddress;
                        cust.lstCustContact = customerexist2.lstCustContact;
                        return(View("Index", cust));
                    }
                }


                CustomerRepository objdata = new CustomerRepository();

                // CustomerId = objdata.AddUpdateCustomer(cust, "Add");
                CustomerId = objdata.AddUpdateCustomer(cust);
                // Call SaveActivityLog("frmAddCustomer", "Add Customer", "Customer " + UCase(txtCustomerName.Text) + " added by user " & UserInfo.UserName & ".")
                var act = new ActivityRepository();
                act.AddActivityLog(Convert.ToString(Session["User"]), "Add Customer", "Save", "Customer " + cust.CustomerName.ToUpper() + " added by user " + Convert.ToString(Session["User"]) + ".");

                if (cust.CustomerId == 0)
                {
                    SendCustomerMailSMTP(Convert.ToInt32(CustomerId), cust.CustomerName);
                }

                cust.CustomerId       = CustomerId;
                ViewBag.CustomerId    = CustomerId;
                ViewBag.Adddisable    = false;
                ViewBag.Deletedisable = false;
                ViewBag.Message       = "Customer details saved successfully.";
            }
            else
            {
                ViewBag.Adddisable = true;
            }

            var customer = _repository.GetCustomerDetails(Convert.ToInt32(CustomerId));



            return(View("Index", customer));
        }