public ActionResult AddCustomer(FormCollection form)
        {
            //init new customer
            customer a = new customer
            {
                customer_firstname  = form["Item1.customer_firstname"],
                customer_lastname   = form["Item1.customer_lastname"],
                customer_middlename = form["Item1.customer_middlename"],
                email               = form["Item1.email"],
                phone_number        = form["Item1.phone_number"],
                second_phone_number = form["Item1.second_phone_number"]
            };

            //check
            if (string.IsNullOrEmpty(a.customer_firstname) ||
                string.IsNullOrEmpty(a.customer_lastname) ||
                string.IsNullOrEmpty(a.phone_number))
            {
                ModelState.AddModelError("customer", "customer info incomplete");
            }
            //int new address
            address b = new address
            {
                address1     = form["Item2.address1"],
                address_type = form["Item2.address_type"],
                city         = form["Item2.city"],
                state        = form["Item2.state"],
                county       = form["Item2.county"],
                zipcode      = form["Item2.zipcode"]
            };

            //che
            if (string.IsNullOrEmpty(b.address_type) ||
                string.IsNullOrEmpty(b.address1) ||
                string.IsNullOrEmpty(b.city) ||
                string.IsNullOrEmpty(b.county) ||
                string.IsNullOrEmpty(b.zipcode))
            {
                ModelState.AddModelError("address", "address info incomplete");
                return(View("AddCustomer"));
            }
            //write change to db,address first
            if (ModelState.IsValid)
            {
                db.addresses.Add(b);
                db.SaveChanges();
                //linking 2 table
                a.address_number = b.address_number;
                db.customers.Add(a);
                db.SaveChanges();
            }



            return(View());
        }
        public ActionResult Add(FormCollection form)
        {
            try
            {
                rate target = new rate();

                //get property

                TryUpdateModel(target, new string[] { "rate_name", "rate_measurement", "amount", "start_date", "end_date", "deleted" }, form.ToValueProvider());

                target.deleted  = false;
                target.end_date = new DateTime(2222, 1, 1);
                ViewBag.Error   = null;

                // Update Previous Cost Detail
                string   query  = "";
                int      PrevId = 0;
                DateTime dt1    = target.start_date;
                dt1 = dt1.AddDays(-1);


                if (db.rates.Any(p => p.rate_name == target.rate_name && p.deleted == false))
                {
                    ViewBag.m = "Duplicate Entry.";
                    return(View());
                }
                else
                {
                    var ctx1 = new ckdatabase();
                    query = "Select Top 1 Rate_number from rates where rate_name ='" + target.rate_name + "' and start_date<'" + target.start_date +
                            "' and deleted=0 order by start_date Desc";

                    PrevId = ctx1.Database.SqlQuery <int>(query).FirstOrDefault <int>();
                    if (PrevId != 0)
                    {
                        query = "Update rates set end_date='" + dt1 + "' where tax_number='" + PrevId.ToString() + "'";
                        var ctx2           = new ckdatabase();
                        int noOfRowUpdated = ctx2.Database.ExecuteSqlCommand(query);
                    }


                    db.rates.Add(target);
                    db.SaveChanges();
                    ViewBag.m = "The Labor Cost was successfully created " + "on " + System.DateTime.Now;
                    string search = null;
                    return(RedirectToAction("ListLaborCost", new { search, msg = ViewBag.m }));
                }
            }
            catch (Exception e)
            {
                ViewBag.m = "The Labor was not created " + e.Message;
                return(View());
            }
        }
Exemple #3
0
        public ActionResult Add(FormCollection form)
        {
            //setting dropdown list for forgern key
            var utype = new List <SelectListItem> {
                new SelectListItem {
                    Text = "---select---", Selected = true, Value = ""
                }
            };

            utype.AddRange(db.users_types.Select(a => new SelectListItem
            {
                Text     = a.user_type_name,
                Selected = false,
                Value    = a.user_type_number.ToString()
            }));

            var branchtypes = new List <SelectListItem> {
                new SelectListItem {
                    Text = "---select---", Selected = true, Value = ""
                }
            };

            branchtypes.AddRange(db.branches.Select(b => new SelectListItem
            {
                Text     = b.branch_name,
                Selected = false,
                Value    = b.branch_number.ToString()
            }));
            //setting variable passing
            ViewBag.utype  = utype;
            ViewBag.branch = branchtypes;
            //create instance
            employee target = new employee();

            //get property
            TryUpdateModel(target, new string[] { "emp_firstname", "emp_middlename", "emp_lastname", "emp_username", "user_type_number", "branch_number", "emp_number", "phone_number" }, form.ToValueProvider());
            //validate
            if (string.IsNullOrEmpty(target.emp_firstname))
            {
                ModelState.AddModelError("firstname", "firstname is required");
            }

            if (ModelState.IsValid)
            {
                db.employees.Add(target);
                db.SaveChanges();
            }

            return(View(target));
        }
Exemple #4
0
        public ActionResult Edit(int id, FormCollection fo)
        {
            try {
                //setting dropdown list for forgern key
                var utype = new List <SelectListItem>();
                utype.AddRange(db.users_types.Where(x => x.deleted != true).Select(a => new SelectListItem
                {
                    Text     = a.user_type_name,
                    Selected = false,
                    Value    = a.user_type_number.ToString()
                }));

                var branchtypes = new List <SelectListItem>();
                branchtypes.AddRange(db.branches.Where(x => x.deleted != true).Select(b => new SelectListItem
                {
                    Text     = b.branch_name,
                    Selected = false,
                    Value    = b.branch_number.ToString()
                }));
                //setting variable passing
                ViewBag.utype  = utype;
                ViewBag.branch = branchtypes;


                List <employee> Employees_list = db.employees.Where(d => d.emp_number == id).ToList();
                ViewBag.Employeeslist = Employees_list;
                employee target      = Employees_list[0];
                string   oldpassword = target.emp_password;
                TryUpdateModel(target, new string[] { "emp_firstname", "emp_middlename", "emp_lastname", "emp_username", "emp_password", "user_type_number", "branch_number", "phone_number" }, fo.ToValueProvider());
                if (target.emp_password == oldpassword)
                {
                }
                else
                {
                    target.emp_password = EncryptionHelper.Encrypt(target.emp_password);
                }

                db.SaveChanges();

                ViewBag.m = " The employee was successfully updated " + " on " + System.DateTime.Now;

                return(View(target));
            }
            catch (Exception e)
            {
                ViewBag.m = "Something went wrong ... " + e.Message;
                return(View());
            }
        }
        public ActionResult Edit(int id, FormCollection fo)
        {
            List <employee> Employees_list = db.employees.Where(d => d.emp_number == id).ToList();

            foreach (employee a in Employees_list)
            {
                a.emp_password = EncryptionHelper.Decrypt(a.emp_password);
            }
            ViewBag.Customerslist = Employees_list;
            employee target = Employees_list[0];

            TryUpdateModel(target, new string[] { "emp_firstname", "emp_middlename", "emp_lastname", "emp_username", "user_type_number", "branch_number", "emp_number", "phone_number" }, fo.ToValueProvider());
            target.emp_password = EncryptionHelper.Encrypt(target.emp_password);
            db.SaveChanges();
            return(View(target));
        }
Exemple #6
0
        public ActionResult Add(FormCollection fo, int lid)
        {
            lead    mian   = db.leads.Where(a => a.lead_number == lid).FirstOrDefault();
            product target = new product();

            TryUpdateModel <product>(target, new string[] { "cat_anme", "quantity", "Description", "model", "color", "product_source", "manufacture", "location", "price" }, fo.ToValueProvider());
            //target.cat_anme = fo["Product Category"];
            if (ModelState.IsValid)
            {
                mian.products.Add(target);
                db.products.Add(target);
                db.SaveChanges(lid);
            }

            return(Redirect(HttpContext.Request.UrlReferrer.AbsoluteUri));
        }
Exemple #7
0
        public ActionResult Edit(int id, FormCollection fo)
        {
            ViewBag.addressnumber1 = db.customers.Where(x => x.customer_number == id).Select(v => v.address_number).First();
            try
            {
                List <customer> Customers_list = db.customers.Where(d => d.customer_number == id).ToList();
                ViewBag.Customerslist = Customers_list;
                customer target = Customers_list[0];
                TryUpdateModel(target, new string[] { "customer_firstname", "customer_middlename", "customer_lastname", "phone_number", "second_phone_number", "email" }, fo.ToValueProvider());
                db.SaveChanges();
                ViewBag.m = " The customer was successfully updated on " + System.DateTime.Now;
                return(View(target));
            }

            catch (Exception e)
            {
                ViewBag.m = " Something went wrong ... " + e.Message;
                return(View());
            }
        }
        public ActionResult ProjectStatusAdd(FormCollection form)
        {
            project_status target = new project_status();

            //get property
            TryUpdateModel(target, new string[] { "project_status_name" }, form.ToValueProvider());
            //validate
            if (string.IsNullOrEmpty(target.project_status_name))
            {
                ModelState.AddModelError("project_status_name", "Project Status is required");
            }

            if (ModelState.IsValid)
            {
                db.project_status.Add(target);
                db.SaveChanges();
            }

            return(RedirectToAction("ProjectStatus"));
        }
Exemple #9
0
        public ActionResult handler(FormCollection fo)
        {
            int                iid    = int.Parse(fo["installation_number"]);
            string             msg    = "The task was created successfully at " + System.DateTime.Now;;
            int                lid    = db.installations.Where(a => a.installation_number == iid).First().lead_number;
            lead               idk    = db.leads.Where(d => d.lead_number == lid).First();
            GeneralHelper      helper = new GeneralHelper();
            tasks_installation target = new tasks_installation();

            if (int.Parse(fo["mode"]) == 0)
            {
                target.hours                = double.Parse(fo["hours"]);
                target.task_number          = int.Parse(fo["task_number"]);
                target.m_cost               = double.Parse(fo["m_cost"]);
                target.labor_cost           = helper.GetInstallationLaborRate(idk) * target.hours;
                target.material_retail_cost = helper.GetInstallationMaterialRate(idk) * target.m_cost;
                target.installation_number  = iid;
                try
                {
                    db.tasks_installation.Add(target);
                    db.SaveChanges(lid);
                    //db.SaveChanges(lid, "create new");
                }
                catch (Exception e)
                {
                    msg = e.Message;
                }
            }
            else
            {
                task ctask = new task();
                ctask.special_task  = true;
                ctask.task_main_cat = "MISC";
                ctask.task_sub_cat  = "Disclaimers";
                ctask.task_name     = fo["task_name"];
                db.tasks.Add(ctask);


                target.task = ctask;

                target.hours                = double.Parse(fo["hours"]);
                target.m_cost               = double.Parse(fo["m_cost"]);
                target.labor_cost           = helper.GetInstallationLaborRate(idk) * target.hours;
                target.material_retail_cost = helper.GetInstallationMaterialRate(idk) * target.m_cost;
                db.tasks_installation.Add(target);
                target.installation_number = iid;
                try
                {
                    db.SaveChanges(lid);
                }
                catch (Exception e)
                {
                    msg = e.Message;
                }
            }


            return(RedirectToAction("lis", new { lid = lid, msg = msg }));
        }
Exemple #10
0
        //string Emp = null,

        /*
         *    public ActionResult StateTax()
         *    {
         *
         *        try
         *        {
         *
         *            var state = new List<SelectListItem>
         *            {
         *                //  new SelectListItem() { Text = "WV", Selected = true, Value = "" }
         *            };
         *            state.AddRange(db.taxes.Where(CCVV => CCVV.state != null).Select(b => new SelectListItem
         *
         *            {
         *                Text = b.state,
         *                Selected = true,
         *                Value = b.state.ToString()
         *            }).Distinct());
         *            ViewBag.state = state;
         *
         *            var result = db.taxes.Where(l => ((l.state=="Type") && l.tax_anme == "State Tax")).ToList();
         *            //LogController.lst = result;
         *            return View();
         *
         *            //return View(db.leads.Where(x => (x.project_name.Contains(search) || search == null) && x.project_status_number == type && (x.project_status_number != 6 && x.deleted == false)).ToList());
         *        }
         *        catch (Exception e)
         *        {
         *            ViewBag.m = "Something went wrong ... " + e.Message;
         *            return View();
         *        }
         *    }
         *
         *
         */

        /*    public ActionResult StateTax(int? page, string search = null, string Type = null, string Start = null, string end = null, string msg = null)
         *  {
         *
         *
         *      DateTime start = string.IsNullOrEmpty(Start) ? DateTime.MinValue : DateTime.Parse(Start);
         *      DateTime end2 = string.IsNullOrEmpty(end) ? DateTime.MaxValue : DateTime.Parse(end);
         *      TimeSpan ts = new TimeSpan(23, 59, 59);
         *      end2 = end2.Date + ts;
         *
         *
         *      try
         *      {
         *          ViewBag.m = msg;
         *          var ClassInfo = new List<SelectListItem>();
         *
         *          ClassInfo.AddRange(db.taxes.Where(CCVV => CCVV.state != null).Select(b => new SelectListItem
         *
         *          {
         *              Text = b.state,
         *              Selected = true,
         *              Value = b.state.ToString()
         *          }).Distinct());
         *          ViewBag.lead_type = ClassInfo;
         *
         *
         *
         *
         *          var result = db.taxes.Where(l => (l.state == Type)  && l.tax_anme == "State Tax" ).ToList();
         *          //LogController.lst = result;
         *
         *      //   return View(result.ToPagedList(page ?? 1, 8));
         *
         *          return View(db.leads.Where(x => (x.project_name.Contains(search) || search == null) && x.project_status_number == type && (x.project_status_number != 6 && x.deleted == false)).ToList());
         *      }
         *      catch (Exception e)
         *      {
         *          ViewBag.m = "Something went wrong ... " + e.Message;
         *          return View();
         *      }
         *  }
         *
         *
         *
         *
         */
        /*
         *  public ActionResult StateTax(FormCollection form)
         *  {
         *      try
         *      {
         *          //setting dropdown list for forgern key
         *          var state = new List<SelectListItem>();
         *          state.AddRange(db.taxes.Where(x => x.state != null).Select(a => new SelectListItem
         *          {
         *              Text = a.state,
         *              Selected = false,
         *              Value = a.state.ToString()
         *          }).Distinct());
         *
         *          //setting variable passing
         *          ViewBag.state = state;
         *
         *          //create instance
         *          tax target = new tax();
         *          //get property
         *          TryUpdateModel(target, new string[] { "tax_value", "tax_anme", "city", "state", "county", "zipcode", "end_date", "tax_number", "start_date" }, form.ToValueProvider());
         *
         *          //validate
         *          //  double tempPhoneNumber = 0;
         *          ViewBag.Error = null;
         *
         *
         *          {
         *              target.tax_anme = "State Tax";
         *              target.city = "";
         *              target.county = "";
         *              target.zipcode = "";
         *
         *              target.start_date = System.DateTime.Now;
         *              target.end_date = System.DateTime.Now;
         *
         *              db.taxes.Add(target);
         *              db.SaveChanges();
         *              ViewBag.m = "Tax was successfully updated " + "on " + System.DateTime.Now;
         *          }
         *          return View();
         *
         *
         *
         *
         *      }
         *
         *
         *      catch (Exception e)
         *      {
         *          ViewBag.m = "The customer was not created ... " + e.Message;
         *          return View();
         *      }
         *  }
         *
         */



        public ActionResult StateTax(FormCollection form)
        {
            try
            {
                //setting dropdown list for forgern key
                var state = new List <SelectListItem>();
                state.AddRange(db.taxes.Where(x => x.state != null).Select(a => new SelectListItem
                {
                    Text     = a.state,
                    Selected = false,
                    Value    = a.state.ToString()
                }).Distinct());

                //setting variable passing
                ViewBag.state = state;

                //create instance
                tax target = new tax();
                //get property
                TryUpdateModel(target, new string[] { "tax_value", "tax_anme", "city", "state", "county", "zipcode", "end_date", "tax_number", "start_date" }, form.ToValueProvider());

                //validate
                //  double tempPhoneNumber = 0;
                ViewBag.Error = null;


                {
                    target.tax_anme = "State Tax";
                    target.city     = "";
                    target.county   = "";
                    target.zipcode  = "";

                    target.start_date = System.DateTime.Now;
                    target.end_date   = System.DateTime.Now;

                    db.taxes.Add(target);
                    db.SaveChanges();
                    ViewBag.m = "Tax was successfully updated " + "on " + System.DateTime.Now;
                }
                return(View());
            }


            catch (Exception e)
            {
                ViewBag.m = "The Tax was not created ... " + e.Message;
                return(View());
            }
        }
        public ActionResult Psge2(FormCollection form)
        {
            users_types a = new users_types();

            TryUpdateModel(a, new string[] { "user_type_name" }, form.ToValueProvider());
            if (string.IsNullOrEmpty(a.user_type_name))
            {
                ModelState.AddModelError("usertypename", "this field is required");
            }

            if (ModelState.IsValid)
            {
                db.users_types.Add(a);
                db.SaveChanges();
            }
            return(View(a));
        }
        public ActionResult AddTax(FormCollection form)
        {
            tax target = new tax();

            //get property
            TryUpdateModel(target, new string[] { "tax_anme", "tax_value", "city", "state", "county", "zipcode", "start_date", "end_date" }, form.ToValueProvider());
            //validate
            if (string.IsNullOrEmpty(target.tax_anme))
            {
                ModelState.AddModelError("tax_anme", "Tax Type is required");
            }

            if (ModelState.IsValid)
            {
                db.taxes.Add(target);
                db.SaveChanges();
            }

            return(View(target));
        }
        public ActionResult Add(FormCollection form, int id, String msg = null)
        {
            ViewBag.m = msg;
            List <SelectListItem> CustomerInfo = new List <SelectListItem>();

            CustomerInfo.AddRange(db.customers.Where(x => x.deleted != true).Select(a => new SelectListItem
            {
                Text     = a.customer_lastname,
                Selected = false,
                Value    = a.customer_number.ToString()
            }));

            var ClassInfo = new List <SelectListItem>();

            ClassInfo.AddRange(db.project_class.Where(x => x.deleted != true).Select(LLL => new SelectListItem
            {
                Text     = LLL.class_name,
                Selected = false,
                Value    = LLL.class_number.ToString()
            }));

            var StatusInfo = new List <SelectListItem>();

            StatusInfo.AddRange(db.project_status.Where(x => x.deleted != true).Select(c => new SelectListItem
            {
                Text     = c.project_status_name,
                Selected = false,
                Value    = c.project_status_number.ToString()
            }));

            var ProjectTypeInfo = new List <SelectListItem>();

            ProjectTypeInfo.AddRange(db.project_type.Where(x => x.deleted != true).Select(VVVb => new SelectListItem
            {
                Text     = VVVb.project_type_name,
                Selected = false,
                Value    = VVVb.project_type_number.ToString()
            }));

            var SourceInfo = new List <SelectListItem>();

            SourceInfo.AddRange(db.lead_source.Where(x => x.deleted != true).Select(ffb => new SelectListItem
            {
                Text     = ffb.source_name,
                Selected = false,
                Value    = ffb.source_number.ToString()
            }));

            var AddressInfo = new List <SelectListItem>();

            AddressInfo.AddRange(db.addresses.Where(x => x.deleted != true).Select(a => new SelectListItem
            {
                Text     = a.address_type,
                Selected = false,
                Value    = a.address_number.ToString()
            }));

            var AddressCityInfo = new List <SelectListItem>();

            var EmpInfo = new List <SelectListItem>();

            EmpInfo.AddRange(db.employees.Where(x => x.deleted != true).Select(a => new SelectListItem
            {
                Text     = a.emp_firstname + " " + a.emp_lastname,
                Selected = false,
                Value    = a.emp_number.ToString()
            }));

            var BranchInfo = new List <SelectListItem>();

            BranchInfo.AddRange(db.branches.Where(x => x.deleted != true).Select(a => new SelectListItem
            {
                Text     = a.branch_name,
                Selected = false,
                Value    = a.branch_number.ToString()
            }));

            var DeliveryStatusInfo = new List <SelectListItem>();

            DeliveryStatusInfo.AddRange(db.delivery_status.Select(a => new SelectListItem
            {
                Text     = a.delivery_status_name,
                Selected = false,
                Value    = a.delivery_status_number.ToString()
            }));


            var TaxExemptInfo = new List <SelectListItem> {
                new SelectListItem()
                {
                    Text = "Taxable", Value = "0"
                },
                new SelectListItem {
                    Text = "Tax Exempt", Value = "1"
                }
            };

            ViewBag.TaxExemptInfo = TaxExemptInfo;

            //setting variable passing
            ViewBag.Customer_Info       = CustomerInfo;
            ViewBag.Class_Info          = ClassInfo;
            ViewBag.Status_Info         = StatusInfo;
            ViewBag.ProjectType_Info    = ProjectTypeInfo;
            ViewBag.Source_Info         = SourceInfo;
            ViewBag.Address_Info        = AddressInfo;
            ViewBag.Emp_Info            = EmpInfo;
            ViewBag.Branch_Info         = BranchInfo;
            ViewBag.DeliveryStatus_Info = DeliveryStatusInfo;



            var Sstate = new List <SelectListItem> {
                new SelectListItem()
                {
                    Text = "Alabama", Value = "AL"
                },
                new SelectListItem()
                {
                    Text = "Alaska", Value = "AK"
                },
                new SelectListItem()
                {
                    Text = "Arizona", Value = "AZ"
                },
                new SelectListItem()
                {
                    Text = "Arkansas", Value = "AR"
                },
                new SelectListItem()
                {
                    Text = "California", Value = "CA"
                },
                new SelectListItem()
                {
                    Text = "Colorado", Value = "CO"
                },
                new SelectListItem()
                {
                    Text = "Connecticut", Value = "CT"
                },
                new SelectListItem()
                {
                    Text = "District of Columbia", Value = "DC"
                },
                new SelectListItem()
                {
                    Text = "Delaware", Value = "DE"
                },
                new SelectListItem()
                {
                    Text = "Florida", Value = "FL"
                },
                new SelectListItem()
                {
                    Text = "Georgia", Value = "GA"
                },
                new SelectListItem()
                {
                    Text = "Hawaii", Value = "HI"
                },
                new SelectListItem()
                {
                    Text = "Idaho", Value = "ID"
                },
                new SelectListItem()
                {
                    Text = "Illinois", Value = "IL"
                },
                new SelectListItem()
                {
                    Text = "Indiana", Value = "IN"
                },
                new SelectListItem()
                {
                    Text = "Iowa", Value = "IA"
                },
                new SelectListItem()
                {
                    Text = "Kansas", Value = "KS"
                },
                new SelectListItem()
                {
                    Text = "Kentucky", Value = "KY"
                },
                new SelectListItem()
                {
                    Text = "Louisiana", Value = "LA"
                },
                new SelectListItem()
                {
                    Text = "Maine", Value = "ME"
                },
                new SelectListItem()
                {
                    Text = "Maryland", Value = "MD"
                },
                new SelectListItem()
                {
                    Text = "Massachusetts", Value = "MA"
                },
                new SelectListItem()
                {
                    Text = "Michigan", Value = "MI"
                },
                new SelectListItem()
                {
                    Text = "Minnesota", Value = "MN"
                },
                new SelectListItem()
                {
                    Text = "Mississippi", Value = "MS"
                },
                new SelectListItem()
                {
                    Text = "Missouri", Value = "MO"
                },
                new SelectListItem()
                {
                    Text = "Montana", Value = "MT"
                },
                new SelectListItem()
                {
                    Text = "Nebraska", Value = "NE"
                },
                new SelectListItem()
                {
                    Text = "Nevada", Value = "NV"
                },
                new SelectListItem()
                {
                    Text = "New Hampshire", Value = "NH"
                },
                new SelectListItem()
                {
                    Text = "New Jersey", Value = "NJ"
                },
                new SelectListItem()
                {
                    Text = "New Mexico", Value = "NM"
                },
                new SelectListItem()
                {
                    Text = "New York", Value = "NY"
                },
                new SelectListItem()
                {
                    Text = "North Carolina", Value = "NC"
                },
                new SelectListItem()
                {
                    Text = "North Dakota", Value = "ND"
                },
                new SelectListItem()
                {
                    Text = "Ohio", Value = "OH"
                },
                new SelectListItem()
                {
                    Text = "Oklahoma", Value = "OK"
                },
                new SelectListItem()
                {
                    Text = "Oregon", Value = "OR"
                },
                new SelectListItem()
                {
                    Text = "Pennsylvania", Value = "PA"
                },
                new SelectListItem()
                {
                    Text = "Rhode Island", Value = "RI"
                },
                new SelectListItem()
                {
                    Text = "South Carolina", Value = "SC"
                },
                new SelectListItem()
                {
                    Text = "South Dakota", Value = "SD"
                },
                new SelectListItem()
                {
                    Text = "Tennessee", Value = "TN"
                },
                new SelectListItem()
                {
                    Text = "Texas", Value = "TX"
                },
                new SelectListItem()
                {
                    Text = "Utah", Value = "UT"
                },
                new SelectListItem()
                {
                    Text = "Vermont", Value = "VT"
                },
                new SelectListItem()
                {
                    Text = "Virginia", Value = "VA"
                },
                new SelectListItem()
                {
                    Text = "Washington", Value = "WA"
                },
                new SelectListItem()
                {
                    Text = "West Virginia", Value = "WV"
                },
                new SelectListItem()
                {
                    Text = "Wisconsin", Value = "WI"
                },
                new SelectListItem()
                {
                    Text = "Wyoming", Value = "WY"
                }
            };

            ViewBag.Sstate = Sstate;


            try
            {
                lead target = new lead();
                {
                    target.customer = db.customers.Where(aa => aa.customer_number == id).FirstOrDefault();
                    int a = Int32.Parse(form["class_number"]);
                    target.project_class = db.project_class.Where(KL => KL.class_number == a).FirstOrDefault();
                    int c = Int32.Parse(form["project_type_number"]);
                    target.project_type = db.project_type.Where(GH => GH.project_type_number == c).FirstOrDefault();
                    int dd = Int32.Parse(form["source_number"]);
                    target.lead_source = db.lead_source.Where(TY => TY.source_number == dd).FirstOrDefault();
                    int ee = Int32.Parse(form["source_number"]);
                    target.lead_source = db.lead_source.Where(qq => qq.source_number == ee).FirstOrDefault();
                    int ff = Int32.Parse(form["emp_number"]);
                    target.employee = db.employees.Where(ww => ww.emp_number == ff).FirstOrDefault();
                    int gg = Int32.Parse(form["branch_number"]);
                    target.branch = db.branches.Where(ss => ss.branch_number == gg).FirstOrDefault();
                    int hh = Int32.Parse(form["delivery_status_number"]);
                    target.delivery_status = db.delivery_status.Where(xx => xx.delivery_status_number == hh).FirstOrDefault();


                    target.in_city = Convert.ToBoolean(form["Item1.in_city"].Split(',')[0]);
                    string aaa = form["Item1.in_city"];
                    // target.tax_exempt = Convert.ToBoolean(form["Item1.tax_exempt"].Split(',')[0]);
                    target.tax_exempt          = string.Equals(form["tax_exempt"], "1") ? true : false;
                    target.project_name        = form["Item1.project_name"];
                    target.phone_number        = form["Item1.phone_number"];
                    target.second_phone_number = form["Item1.second_phone_number"];
                    target.email        = form["Item1.email"];
                    target.lead_creator = User.Identity.GetUserName();
                    target.note         = form["Item1.note"];

                    target.deleted = false;
                    //   target.address_number = b.address_number;
                    target.project_status_number = 3;
                    target.lead_date             = System.DateTime.Now;
                    target.Last_update_date      = System.DateTime.Now;
                };
                db.leads.Add(target);
                db.SaveChanges();

                address b = new address
                {
                    address1     = form["Item2.address1"],
                    address_type = "JobAddress",
                    city         = form["Item2.city"],
                    //  state = form["state"],
                    state       = form["state1"],
                    county      = form["Item2.county"],
                    zipcode     = form["Item2.zipcode"],
                    deleted     = false,
                    lead_number = target.lead_number
                };
                db.addresses.Add(b);
                db.SaveChanges();
                if (string.IsNullOrEmpty(form["Item3.address1"]))
                {
                }
                else
                {
                    address BC = new address
                    {
                        address1 = form["Item3.address1"],
                        //     address_type = form["Item2.address_type"],
                        address_type = "alternativeAddress",
                        city         = form["Item3.city"],
                        state        = form["state2"],
                        // state = form["state"],

                        //   state = "Not fixed yet",
                        county      = form["Item3.county"],
                        zipcode     = form["Item3.zipcode"],
                        deleted     = false,
                        lead_number = target.lead_number
                    };
                    db.addresses.Add(BC);
                    db.SaveChanges();
                }


                ViewBag.m = " The lead was successfully created to " + target.customer.customer_firstname + " " + target.customer.customer_lastname + " on " + System.DateTime.Now;


                return(RedirectToAction("Edit/" + target.lead_number, "lead", new { msg = ViewBag.m }));
            }
            catch (Exception e)
            {
                ViewBag.m = "The lead was not created ..." + e.Message;
                return(View());
            }
        }
        public ActionResult Add(FormCollection form)
        {
            try
            {
                tax target = new tax();

                //get property

                TryUpdateModel(target, new string[] { "tax_anme", "tax_value", "city", "state", "county", "zipcode", "start_date", "end_date", "deleted", "in_city" }, form.ToValueProvider());

                target.tax_anme = "County Tax";
                target.city     = "";
                target.zipcode  = "";
                target.deleted  = false;
                target.in_city  = false;
                target.end_date = new DateTime(2222, 1, 1);
                ViewBag.Error   = null;


                // Update Previous Tax Detail
                string   query  = "";
                int      PrevId = 0;
                DateTime dt1    = target.start_date;
                dt1 = dt1.AddDays(-1);


                if (db.taxes.Any(p => p.state == target.state) && db.taxes.Any(p => p.tax_anme == "County Tax") && db.taxes.Any(p => p.county == target.county && p.deleted == false))
                {
                    ViewBag.m = "Duplicate Tax.";
                    return(View());
                }
                else
                {
                    var ctx1 = new ckdatabase();
                    query = "Select Top 1 tax_number from taxes where tax_anme = 'County Tax' and state = '" + target.state + "' and county='" + target.county + "' and start_date<'" +
                            target.start_date + "' and deleted=0 order by start_date Desc";

                    PrevId = ctx1.Database.SqlQuery <int>(query).FirstOrDefault <int>();
                    if (PrevId != 0)
                    {
                        query = "Update taxes set end_date='" + dt1 + "' where tax_anme='County Tax' and state='" + target.state + "' and county='" + target.county + "'";
                        query = query + " and tax_number='" + PrevId.ToString() + "'";

                        var ctx2           = new ckdatabase();
                        int noOfRowUpdated = ctx2.Database.ExecuteSqlCommand(query);
                    }


                    db.taxes.Add(target);
                    db.SaveChanges();
                    ViewBag.m = "The County Tax was successfully created " + "on " + System.DateTime.Now;
                    return(View(target));

                    string search = null;
                    return(RedirectToAction("CountyTaxNew", new { search, msg = ViewBag.m }));
                }
            }
            catch (Exception e)
            {
                ViewBag.m = "The County Tax was not created " + e.Message;
                return(View());
            }
        }
Exemple #15
0
        public void SaveProjectTotal(int leadNbr)
        {
            var lead = db.leads.Where(l => l.lead_number == leadNbr).First();

            if ((lead.products != null && lead.products.Count != 0) || (lead.installations != null && lead.installations.Count != 0))
            {
                // set calculated installation data
                lead = this.SetAllInstallationCosts(lead);

                //set totalcost data
                TotalCostHelper cHelper = new TotalCostHelper();
                InstallationCalculationHelper installHelper = new InstallationCalculationHelper();
                double buildingPermit   = 0;
                double installationCost = 0;
                double materialCost     = 0;
                foreach (var item in lead.installations)
                {
                    buildingPermit   = (double)item.building_permit_cost;
                    installationCost = (double)item.total_installation_labor_cost;
                    materialCost     = (double)item.total_construction_materials_cost;
                }

                if (lead.total_cost.Count == 0)
                {
                    total_cost total = new total_cost
                    {
                        lead_number          = (int)lead.lead_number,
                        product_cost         = cHelper.CalculateProductCost(lead),
                        building_permit_cost = buildingPermit,
                        tax_cost             = cHelper.CalculateApplicableTax(lead)
                    };

                    // this is when there is no installation data
                    if (installationCost == 0)
                    {
                        buildingPermit   = installHelper.CalculateBuildingPermit(lead);
                        installationCost = cHelper.CalculateInstallationCost(lead);
                    }

                    total.total_cost1 = total.product_cost + materialCost + total.installation_cost + total.tax_cost;
                    List <total_cost> costList = new List <total_cost>
                    {
                        total
                    };

                    lead.total_cost = costList;
                }
                else
                {
                    foreach (var item2 in lead.total_cost)
                    {
                        item2.product_cost         = cHelper.CalculateProductCost(lead);
                        item2.installation_cost    = cHelper.CalculateInstallationCost(lead);
                        item2.building_permit_cost = installHelper.CalculateBuildingPermit(lead);
                        item2.tax_cost             = cHelper.CalculateApplicableTax(lead);
                        item2.total_cost1          = item2.product_cost + materialCost + item2.installation_cost + item2.tax_cost;
                    }
                }

                db.SaveChanges();
            }
        }
        public ActionResult Edit(int id, string mode, FormCollection fo)
        {
            var Sstate = new List <SelectListItem> {
                new SelectListItem()
                {
                    Text = "Alabama", Value = "AL"
                },
                new SelectListItem()
                {
                    Text = "Alaska", Value = "AK"
                },
                new SelectListItem()
                {
                    Text = "Arizona", Value = "AZ"
                },
                new SelectListItem()
                {
                    Text = "Arkansas", Value = "AR"
                },
                new SelectListItem()
                {
                    Text = "California", Value = "CA"
                },
                new SelectListItem()
                {
                    Text = "Colorado", Value = "CO"
                },
                new SelectListItem()
                {
                    Text = "Connecticut", Value = "CT"
                },
                new SelectListItem()
                {
                    Text = "District of Columbia", Value = "DC"
                },
                new SelectListItem()
                {
                    Text = "Delaware", Value = "DE"
                },
                new SelectListItem()
                {
                    Text = "Florida", Value = "FL"
                },
                new SelectListItem()
                {
                    Text = "Georgia", Value = "GA"
                },
                new SelectListItem()
                {
                    Text = "Hawaii", Value = "HI"
                },
                new SelectListItem()
                {
                    Text = "Idaho", Value = "ID"
                },
                new SelectListItem()
                {
                    Text = "Illinois", Value = "IL"
                },
                new SelectListItem()
                {
                    Text = "Indiana", Value = "IN"
                },
                new SelectListItem()
                {
                    Text = "Iowa", Value = "IA"
                },
                new SelectListItem()
                {
                    Text = "Kansas", Value = "KS"
                },
                new SelectListItem()
                {
                    Text = "Kentucky", Value = "KY"
                },
                new SelectListItem()
                {
                    Text = "Louisiana", Value = "LA"
                },
                new SelectListItem()
                {
                    Text = "Maine", Value = "ME"
                },
                new SelectListItem()
                {
                    Text = "Maryland", Value = "MD"
                },
                new SelectListItem()
                {
                    Text = "Massachusetts", Value = "MA"
                },
                new SelectListItem()
                {
                    Text = "Michigan", Value = "MI"
                },
                new SelectListItem()
                {
                    Text = "Minnesota", Value = "MN"
                },
                new SelectListItem()
                {
                    Text = "Mississippi", Value = "MS"
                },
                new SelectListItem()
                {
                    Text = "Missouri", Value = "MO"
                },
                new SelectListItem()
                {
                    Text = "Montana", Value = "MT"
                },
                new SelectListItem()
                {
                    Text = "Nebraska", Value = "NE"
                },
                new SelectListItem()
                {
                    Text = "Nevada", Value = "NV"
                },
                new SelectListItem()
                {
                    Text = "New Hampshire", Value = "NH"
                },
                new SelectListItem()
                {
                    Text = "New Jersey", Value = "NJ"
                },
                new SelectListItem()
                {
                    Text = "New Mexico", Value = "NM"
                },
                new SelectListItem()
                {
                    Text = "New York", Value = "NY"
                },
                new SelectListItem()
                {
                    Text = "North Carolina", Value = "NC"
                },
                new SelectListItem()
                {
                    Text = "North Dakota", Value = "ND"
                },
                new SelectListItem()
                {
                    Text = "Ohio", Value = "OH"
                },
                new SelectListItem()
                {
                    Text = "Oklahoma", Value = "OK"
                },
                new SelectListItem()
                {
                    Text = "Oregon", Value = "OR"
                },
                new SelectListItem()
                {
                    Text = "Pennsylvania", Value = "PA"
                },
                new SelectListItem()
                {
                    Text = "Rhode Island", Value = "RI"
                },
                new SelectListItem()
                {
                    Text = "South Carolina", Value = "SC"
                },
                new SelectListItem()
                {
                    Text = "South Dakota", Value = "SD"
                },
                new SelectListItem()
                {
                    Text = "Tennessee", Value = "TN"
                },
                new SelectListItem()
                {
                    Text = "Texas", Value = "TX"
                },
                new SelectListItem()
                {
                    Text = "Utah", Value = "UT"
                },
                new SelectListItem()
                {
                    Text = "Vermont", Value = "VT"
                },
                new SelectListItem()
                {
                    Text = "Virginia", Value = "VA"
                },
                new SelectListItem()
                {
                    Text = "Washington", Value = "WA"
                },
                new SelectListItem()
                {
                    Text = "West Virginia", Value = "WV"
                },
                new SelectListItem()
                {
                    Text = "Wisconsin", Value = "WI"
                },
                new SelectListItem()
                {
                    Text = "Wyoming", Value = "WY"
                }
            };

            ViewBag.Sstate = Sstate;

            switch (fo["mode"])
            {
            case "l":    //lead add update mode
                address lad = db.addresses.Where(t => t.address_number == id).First();
                lad.address_type = "JobAddress";
                lad.state        = fo["state"];
                lad.deleted      = false;
                TryUpdateModel(lad, new string[] { "address1", "city", "county", "zipcode" }, fo.ToValueProvider());
                lad.address1 = fo["item.address1"];
                lad.city     = fo["item.city"];
                lad.county   = fo["item.county"];
                lad.zipcode  = fo["item.zipcode"];
                try
                {
                    db.SaveChanges();
                }
                catch (Exception e) { ViewBag.m = e.Message; }

                break;

            case "c":    //customer add update mode
                address custadd = db.addresses.Where(r => r.address_number == id).First();
                custadd.address_type = "Billing";
                custadd.deleted      = false;
                //TryUpdateModel(custadd, new string[] { "item.address1", "item.city", "item.county", "item.zipcode" }, fo.ToValueProvider());
                custadd.address1 = fo["item.address1"];
                custadd.city     = fo["item.city"];
                custadd.county   = fo["item.county"];
                custadd.zipcode  = fo["item.zipcode"];

                try
                {
                    db.SaveChanges();
                }
                catch (Exception e) { ViewBag.m = e.Message; }
                break;

            case "ll":    //lead second add mode
                int?lid = db.addresses.Where(t => t.address_number == id).First().lead_number;
                if (int.Parse(fo["address_number"]) < 0)
                {
                    //new  second address
                    address n = new address();
                    n.deleted      = false;
                    n.address_type = "Alternative";
                    TryUpdateModel(n, new string[] { "address1", "city", "county", "zipcode" }, fo.ToValueProvider());
                    n.address1    = fo["item.address1"];
                    n.city        = fo["item.city"];
                    n.county      = fo["item.county"];
                    n.zipcode     = fo["item.zipcode"];
                    n.lead_number = lid;
                    try
                    {
                        db.addresses.Add(n);
                        db.SaveChanges();
                    }
                    catch (Exception e) { ViewBag.m = e.Message; }
                }
                else
                {
                    //update second
                    int     aid = int.Parse(fo["address_number"]);
                    address q   = db.addresses.Where(c => c.address_number == aid).First();
                    TryUpdateModel(q, new string[] { "address1", "city", "county", "zipcode" }, fo.ToValueProvider());
                    q.address1     = fo["item.address1"];
                    q.city         = fo["item.city"];
                    q.county       = fo["item.county"];
                    q.zipcode      = fo["item.zipcode"];
                    q.address_type = "Alternative";
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (Exception e) { ViewBag.m = e.Message; }
                }


                break;

            case "b":    //branch add update mode
                address target = db.addresses.Where(r => r.address_number == id).First();
                target.deleted      = false;
                target.state        = fo["state"];
                target.address_type = "BranchAddress";
                TryUpdateModel(target, new string[] { "address1", "city", "county", "zipcode" }, fo.ToValueProvider());
                target.address1 = fo["item.address1"];
                target.city     = fo["item.city"];
                target.county   = fo["item.county"];
                target.zipcode  = fo["item.zipcode"];
                try {
                    db.SaveChanges();
                } catch (Exception e) { ViewBag.m = e.Message; }
                break;
            }

            ViewBag.m = " The address was successfully updated on " + System.DateTime.Now;
            return(RedirectToAction("Edit", new { id = id, mode = mode }));
        }