Example #1
0
        public ActionResult Index(int SelectedCustId = -1, int SelectedContractId = -1)
        {
            string  auth    = GetCookie("Auth");
            AbzHash abzHash = hashRepo.GetHash(auth);
            string  usr     = abzHash.Email;

            if ((SelectedCustId > 0) && ((int)abzHash.CustID != SelectedCustId))
            {
                abzHash.CustID = SelectedCustId;
                contract       = repo.GetContract((int)abzHash.CustID);
                if (contract == null)
                {
                    ContractID = 0;
                }
                else
                {
                    ContractID = contract.ContractID;
                }
                abzHash.ContractID = ContractID;
                hashRepo.UpdateHash(abzHash);
            }
            else
            {
                if ((SelectedContractId > 0) && ((int)abzHash.ContractID != SelectedContractId))
                {
                    abzHash.ContractID = SelectedContractId;
                    hashRepo.UpdateHash(abzHash);
                }
            }
            contract = repo.GetContract((int)abzHash.CustID);
            if (contract == null)
            {
                ContractID = 0;
            }
            else
            {
                ContractID = contract.ContractID;
            }

            Cust cust = db.Custs.Find((int)abzHash.CustID);

            contracts            = repo.GetContracts((int)abzHash.CustID);
            ViewData["Contract"] = new SelectList(contracts, "ContractID", "Num", ContractID);

            IEnumerable <OrgView> orgView = repo.GetCust(usr);

            ViewData["Cust"] = new SelectList(orgView, "ID", "Txt", abzHash.CustID);
            ViewBag.MenuItem = "recv";
            ViewBag.User     = usr;


            BalanceRepository bl = new BalanceRepository();

            ViewBag.customer  = cust.SmalName;
            ViewBag.balance   = bl.GetBalance(CustID, (int)abzHash.ContractID).ToString();
            ViewBag.contractn = "";
            Contract contractcc = db.Contracts.Find((int)abzHash.ContractID);

            if (contractcc != null)
            {
                ViewBag.contractn = "Договор № " + contractcc.Num;
            }

            SetCookie("custid", CustID.ToString());
            SetCookie("contractid", abzHash.ContractID.ToString());
            SetCookie("customer", ViewBag.customer);
            SetCookie("balance", ViewBag.balance);
            SetCookie("contract", ViewBag.contractn);



            return(View("Index", cust));
        }
Example #2
0
        public ActionResult Index(int SelectedCustId = 0, int SelectedContractId = -1)
        {
            //Определить контрагента и договор
            string qq  = User.Identity.Name;
            string cst = GetCookie("Cust");
            string dog = GetCookie("Dog");

            if (!String.IsNullOrWhiteSpace(cst) && !String.IsNullOrWhiteSpace(dog))
            {
                //Назначаем и быбираем контрагента и договор
                CustID     = Convert.ToInt32(cst);
                ContractID = Convert.ToInt32(dog);
            }
            else
            {
                //Получить данные по юзеру
                string usr = GetCookie("MyAuth");

                //cust = await db.Custs.FindAsync(user.CustID);
            }


            MyMenu menu = (MyMenu)Session["Menu"];

            if (SelectedContractId > 0 && menu.ContractId != SelectedContractId)
            {
                menu = ChangeControl(menu, SelectedCustId, SelectedContractId);
                ViewData["Contract"] = new SelectList(contracts, "ContractID", "Num", ContractID);
            }
            else
            {
                if (SelectedCustId > 0 && SelectedCustId != menu.CustId)
                {
                    menu = ChangeControl(menu, SelectedCustId, 0);
                }
                else
                {
                    menu = ChangeControl(menu, menu.CustId, 0);
                }

                if (ContractID > 0)
                {
                    ViewData["Contract"] = new SelectList(contracts, "ContractID", "Num", ContractID);
                }
                else
                {
                    ViewData["Contract"] = null;
                }
            }
            BalanceRepository bl = new BalanceRepository();

            menu.sm = bl.GetBalance(CustID, ContractID);

            menu.ChangeSelected(1, 1);
            Session["Menu"] = menu;

            //не верно для админа, однако работает?
            IEnumerable <OrgView> orgView = repo.GetCust(menu.UserId);

            ViewData["Cust"] = new SelectList(orgView, "ID", "Txt", CustID);

            return(View("Index", cust));
        }
Example #3
0
        public ActionResult Index(int SelectedCustId = -1, int SelectedContractId = -1)
        {
            string usr = User.Identity.Name;

            int state = CalcState(SelectedCustId, SelectedContractId);

            switch (state)
            {
            case 3:
                ContractID = SelectedContractId;
                break;

            case 4:
                CustID   = SelectedCustId;
                contract = repo.GetContract(CustID);
                if (contract == null)
                {
                    ContractID = 0;
                }
                else
                {
                    ContractID = contract.ContractID;
                }
                break;

            case 5:
                //1й вход после логина
                CustID   = repo.GetCustEmail(usr);
                contract = repo.GetContract(CustID);
                if (contract == null)
                {
                    ContractID = 0;
                }
                else
                {
                    ContractID = contract.ContractID;
                }
                break;
            }

            Cust cust = db.Custs.Find(CustID);

            try
            {
                abzHash.CustID = CustID;
            }
            catch
            {
                RedirectToAction("Logout", "Account");
            }

            contracts = repo.GetContracts(CustID);

            try
            {
                abzHash.ContractID = ContractID;
            }
            catch
            {
                RedirectToAction("Logout", "Account");
            }

            if (abzHash != null)
            {
                UpdateHash(abzHash);
            }
            else
            {
                RedirectToAction("Logout", "Account");
            }

            ViewData["Contract"] = new SelectList(contracts, "ContractID", "Num", ContractID);

            //не верно для админа, однако работает?
            IEnumerable <OrgView> orgView = repo.GetCust(usr);

            ViewData["Cust"] = new SelectList(orgView, "ID", "Txt", CustID);

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