Beispiel #1
0
        public Company AddCompany(CompanyModel companyСlient, string userId)
        {
            var company = companyСlient.GetCompany();

            company.UserId = userId;
            _companyRepository.AddCompany(company);
            _context.SaveChanges();
            return(company);
        }
Beispiel #2
0
        public Company ChangeCompany(CompanyModel companyModel, string userId)
        {
            var companyClient = companyModel.GetCompany();
            var company       = _companyRepository.GetCompanyById(companyClient.CompanyId);

            if (company == null)
            {
                throw new Exception("Компания не была найдена");
            }
            _companyRepository.ChangeCompany(company, companyClient, userId);
            _context.SaveChanges();

            return(company);
        }
        //  1: ok
        //  0: code error
        // -1: password error
        // -2: too many time
        //
        int tryLogin(string password, string code)
        {
            var result = 0;

            while (true)
            {
                if (string.IsNullOrEmpty(password))
                {
                    break;
                }

                if (Session[c_code] == null)
                {
                    break;
                }

                if (string.IsNullOrEmpty(code))
                {
                    if (ConfigurationManager.AppSettings[c_uname] == password)
                    {
                        Session[G.super] = TS.s1;
                        result           = 1;
                    }
                    break;
                }

                if (code != Session[c_code].ToString())
                {
                    break;
                }

                int tryLimit = THelper.StringToInt(ConfigurationManager.AppSettings[c_try]);
                if (Session[c_try] != null && (int)Session[c_try] >= tryLimit)
                {
                    result = -2;
                    break;
                }

                var model = new CompanyModel();
                var row   = model.GetCompany(password);
                if (row != null)
                {
                    Session[G.companyid] = row.id.Value;
                    Session[G.super]     = TS.s2;
                    Session.Remove(c_try);
                    result = 1;
                }
                else
                {
                    result = -1;
                    if (Session[c_try] == null)
                    {
                        Session[c_try] = 1;
                    }
                    else
                    {
                        Session[c_try] = (int)Session[c_try] + 1;
                    }
                }

                Session.Remove(c_code);
                break;
            }

            return(result);
        }