コード例 #1
0
        public PartialViewResult UpdateCustomerContact(Int32 id)
        {
            SR_Log_DatabaseSQLEntities db          = new SR_Log_DatabaseSQLEntities();
            tblCustContact             custcontact = db.tblCustContacts.Where(x => x.Id == id).FirstOrDefault();
            CustomerContactViewModel   contact     = new CustomerContactViewModel();

            contact.CustomerContact = custcontact.CustomerContact;
            contact.ContactEmail    = custcontact.ContactEmail;
            contact.ContactPhone    = custcontact.ContactPhone;
            contact.Id         = custcontact.Id;
            contact.CustomerId = custcontact.CustomerId;

            if (custcontact.IsPrimaryContact == true)
            {
                contact.IsPrimaryContact = true;
            }
            else
            {
                contact.IsPrimaryContact = false;
            }
            ViewBag.Adddisable        = false;
            ViewBag.CustomerId        = custcontact.CustomerId;
            ViewBag.CustomerContactId = custcontact.Id;
            return(PartialView("CreateCustomerContact", contact));
        }
コード例 #2
0
        public ActionResult DeleteCustomer(int id)
        {
            SR_Log_DatabaseSQLEntities db = new SR_Log_DatabaseSQLEntities();
            var custcontact = (from c in db.tblCustContacts
                               where c.CustomerId == id
                               select c).ToList();

            foreach (var c in custcontact)
            {
                int            ContactId = c.Id;
                tblCustContact contact   = db.tblCustContacts.Where(x => x.Id == ContactId).FirstOrDefault();
                db.tblCustContacts.Remove(contact);
                db.SaveChanges();
            }

            var custaddress = (from c in db.tblCustAddresses
                               where c.CustomerId == id
                               select c).ToList();

            foreach (var a in custaddress)
            {
                int            AddressId = a.Id;
                tblCustAddress address   = db.tblCustAddresses.Where(x => x.Id == AddressId).FirstOrDefault();
                db.tblCustAddresses.Remove(address);
                db.SaveChanges();
            }


            tblCustomer customer = db.tblCustomers.Where(x => x.CustomerId == id).FirstOrDefault();

            db.tblCustomers.Remove(customer);
            db.SaveChanges();
            return(Json(true, JsonRequestBehavior.AllowGet));
        }
コード例 #3
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);
        }
コード例 #4
0
        public JsonResult DeleteCustomerContact(Int32 Id)
        {
            SR_Log_DatabaseSQLEntities db          = new SR_Log_DatabaseSQLEntities();
            tblCustContact             custcontact = db.tblCustContacts.Where(x => x.Id == Id).FirstOrDefault();
            int    CustomerId = custcontact.CustomerId;
            string contact    = custcontact.CustomerContact;

            db.tblCustContacts.Remove(custcontact);
            db.SaveChanges();


            tblCustomer customer = db.tblCustomers.Where(x => x.CustomerId == CustomerId).FirstOrDefault();

            var act = new ActivityRepository();

            act.AddActivityLog(Convert.ToString(Session["User"]), "Delete contact", "DeleteCustomerContact", "Contact " + contact + " of customer " + customer.CustomerName + " deleted by user " + Convert.ToString(Session["User"]) + ".");
            return(Json(true, JsonRequestBehavior.AllowGet));
        }
コード例 #5
0
        public JsonResult SetPrimaryContact(Int32 Id, Int32 customerId, bool setdefault)
        {
            SR_Log_DatabaseSQLEntities db = new SR_Log_DatabaseSQLEntities();

            if (setdefault == true)
            {
                var cust = (from c in db.tblCustContacts
                            where c.CustomerId == customerId && c.Id != Id
                            select c).ToList();

                foreach (var c in cust)
                {
                    tblCustContact contact = db.tblCustContacts.Where(x => x.Id == c.Id).FirstOrDefault();
                    contact.IsPrimaryContact = false;
                    db.SaveChanges();
                }
            }

            tblCustContact custcontact = db.tblCustContacts.Where(x => x.Id == Id).FirstOrDefault();

            custcontact.IsPrimaryContact = setdefault;
            db.SaveChanges();


            tblCustomer customer = db.tblCustomers.Where(x => x.CustomerId == customerId).FirstOrDefault();

            var act = new ActivityRepository();

            if (setdefault == true)
            {
                act.AddActivityLog(Convert.ToString(Session["User"]), "Update default contact", "SetPrimaryContact", "Default contact set to " + custcontact.CustomerContact + " for customer " + customer.CustomerName + " by user " + Convert.ToString(Session["User"]) + ".");
            }
            else
            {
                act.AddActivityLog(Convert.ToString(Session["User"]), "Update default contact", "SetPrimaryContact", "Default contact " + custcontact.CustomerContact + " removed for customer " + customer.CustomerName + " by user " + Convert.ToString(Session["User"]) + ".");
            }
            return(Json(true, JsonRequestBehavior.AllowGet));
        }
コード例 #6
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));
        }
コード例 #7
0
        public void AddUpdateCustomerContact(CustomerContactViewModel model, string Flag)
        {
            using (var context = new SR_Log_DatabaseSQLEntities())
            {
                if (Flag == "Add")
                {
                    if (model.IsPrimaryContact == true)
                    {
                        var ExistCust = (from c in context.tblCustContacts
                                         where c.CustomerId == model.CustomerId
                                         select c).ToList();
                        if (ExistCust.Count > 0)
                        {
                            foreach (var cust in ExistCust)
                            {
                                if (cust.IsPrimaryContact == true)
                                {
                                    tblCustContact result = (from c in context.tblCustContacts
                                                             where c.Id == cust.Id
                                                             select c).SingleOrDefault();
                                    if (result != null)
                                    {
                                        result.IsPrimaryContact = false;
                                        context.SaveChanges();
                                    }
                                }
                            }
                        }
                    }

                    var customer = context.USP_TT_InsertCustContacts(Convert.ToInt32(model.CustomerId), model.CustomerContact, model.ContactPhone, model.ContactEmail, model.IsPrimaryContact);
                }
                else
                {
                    if (model.IsPrimaryContact == true)
                    {
                        var ExistCust = (from c in context.tblCustContacts
                                         where c.CustomerId == model.CustomerId
                                         select c).ToList();
                        if (ExistCust.Count > 0)
                        {
                            foreach (var cust in ExistCust)
                            {
                                if (cust.IsPrimaryContact == true)
                                {
                                    tblCustContact r = (from c in context.tblCustContacts
                                                        where c.Id == cust.Id && c.Id != model.Id
                                                        select c).SingleOrDefault();
                                    if (r != null)
                                    {
                                        r.IsPrimaryContact = false;
                                        context.SaveChanges();
                                    }
                                }
                            }
                        }
                    }
                    tblCustContact result = (from c in context.tblCustContacts
                                             where c.Id == model.Id
                                             select c).SingleOrDefault();

                    result.CustomerContact  = model.CustomerContact;
                    result.ContactPhone     = model.ContactPhone;
                    result.ContactEmail     = model.ContactEmail;
                    result.IsPrimaryContact = model.IsPrimaryContact;
                    context.SaveChanges();
                }
            }
        }