public ActionResult SetupType(GeneralSetupVM vm)
        {
            if (vm.SetupTypeID != null)
            {
                Session["SetupTypeID"] = vm.SetupTypeID;
            }

            int branchid = Convert.ToInt32(Session["SetupBranchId"]);

            return(RedirectToAction("GeneralSetup", "BranchMaster", new { id = branchid }));
        }
        public ActionResult GeneralSetup(GeneralSetupVM vm)
        {
            int          companyid = Convert.ToInt32(Session["CurrentCompanyID"].ToString());
            GeneralSetup v         = new GeneralSetup();

            v = db.GeneralSetups.Where(cc => cc.BranchId == vm.BranchId && cc.SetupTypeID == vm.SetupTypeID).FirstOrDefault();

            if (v == null)
            {
                v = new GeneralSetup();
                int max = (from d in db.GeneralSetups orderby d.SetupID descending select d.SetupID).FirstOrDefault();
                v.SetupID     = max + 1;;
                v.BranchId    = vm.BranchId;
                v.AcCompanyId = companyid;
                v.SetupTypeID = vm.SetupTypeID;
                //v.Text1 = vm.TextDoc;
                if (v.SetupTypeID != 1)
                {
                    v.Text1 = vm.TextDoc;
                }
                else if (v.SetupID == 1)
                {
                    v.Text1 = vm.Text1;
                    v.Text2 = vm.Text2;
                    v.Text3 = vm.Text3;
                    v.Text4 = vm.Text4;
                    v.Text5 = vm.Text5;
                }
                db.GeneralSetups.Add(v);
                db.SaveChanges();
            }
            else
            {
                if (v.SetupTypeID != 1)
                {
                    v.Text1 = vm.TextDoc;
                }
                else if (v.SetupID == 1) //invoice footer
                {
                    v.Text1 = vm.Text1;  // Doc;
                    v.Text2 = vm.Text2;
                    v.Text3 = vm.Text3;
                    v.Text4 = vm.Text4;
                    v.Text5 = vm.Text5;
                }

                db.Entry(v).State = EntityState.Modified;
                db.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
        public ActionResult SetupType()
        {
            GeneralSetupVM vm = new GeneralSetupVM();

            if (Session["SetupTypeID"] != null)
            {
                int setuptypeid = Convert.ToInt32(Session["SetupTypeID"].ToString());
                vm.SetupTypeID = setuptypeid;
            }
            int branchid = Convert.ToInt32(Session["SetupBranchId"]);

            ViewBag.SetupType  = db.GeneralSetupTypes.ToList();
            ViewBag.BranchName = db.BranchMasters.Find(branchid).BranchName;
            return(View(vm));
        }
        public ActionResult GeneralSetup(int id)
        {
            int setuptypeid = 0;

            if (Session["SetupTypeID"] != null)
            {
                setuptypeid = Convert.ToInt32(Session["SetupTypeID"].ToString());
            }
            else
            {
                Session["SetupTypeID"]   = 1;
                Session["SetupBranchID"] = id;
                setuptypeid = 1;
            }
            GeneralSetup   v  = new GeneralSetup();
            GeneralSetupVM vm = new GeneralSetupVM();

            v = db.GeneralSetups.Where(cc => cc.BranchId == id && cc.SetupTypeID == setuptypeid).FirstOrDefault();

            if (v == null)
            {
                vm.SetupID     = 0;
                vm.BranchId    = id;
                vm.SetupTypeID = setuptypeid; // db.GeneralSetupTypes.FirstOrDefault().ID;
                vm.TextDoc     = "";
                vm.Text1       = "";
                vm.Text2       = "";
                vm.Text3       = "";
                vm.Text4       = "";
                vm.Text5       = "";
            }
            else
            {
                vm.SetupID     = v.SetupID;
                vm.BranchId    = v.BranchId;
                vm.SetupTypeID = v.SetupTypeID;
                vm.TextDoc     = v.Text1;
                vm.Text1       = v.Text1;
                vm.Text2       = v.Text2;
                vm.Text3       = v.Text3;
                vm.Text4       = v.Text4;
                vm.Text5       = v.Text5;
            }

            ViewBag.SetupType = db.GeneralSetupTypes.ToList();
            return(View(vm));
        }