public OpResult SetState(string ids, short state)
        {
            var idlist = ids.Split(',').Select(o => int.Parse(o));
            var list   = CompanyAuthorRepository.GetQuery(o => idlist.Contains(o.Id)).ToList();

            list.ForEach(o => o.Status = state);
            CompanyAuthorRepository.SaveChanges();
            return(OpResult.Success());
        }
        public CompanyAuthorize GetOneTitleByCID(int cid)
        {
            var company = CompanyAuthorRepository.GetQuery(o => o.CID == cid).OrderByDescending(o => o.CreateDT).FirstOrDefault();

            if (company != null && !company.OpenScopeId.IsNullOrEmpty())
            {
                var scopeids = company.OpenScopeId.Split(',');
                company.OpenScopeId = string.Join(",", BusinessRepository.GetQuery(o => scopeids.Contains(o.ById)).Select(o => o.Title));
            }
            return(company);
        }
 public OpResult Add(CompanyAuthorize obj)
 {
     if (CompanyAuthorRepository.GetQuery(o => o.CID == obj.CID && (o.Status == 0 || o.Status == 1)).Any())
     {
         return(OpResult.Fail("商户已续签!"));
     }
     obj.AppProper    = obj.AppProper ?? "N";
     obj.StoreProper  = obj.StoreProper ?? "N";
     obj.PosMinorDisp = obj.PosMinorDisp ?? "N";
     obj.MemberShared = obj.MemberShared ?? "Y";
     obj.CreateDT     = DateTime.Now;
     obj.CreateUID    = CurrentUser.UID;
     obj.ExpirationDT = DateTime.Parse(obj.EffectiveDT).AddMonths(obj.ValidityNum.GetValueOrDefault()).ToString("yyyy-MM-dd");
     CompanyAuthorRepository.Add(obj);
     return(OpResult.Success());
 }
 public bool RegisterAgain(CompanyAuthorize company)
 {
     if (company.CID.HasValue)
     {
         var obj = CompanyAuthorRepository.GetQuery(o => o.CID == company.CID.Value).OrderByDescending(o => o.CreateDT).FirstOrDefault();
         if (obj == null)
         {
             return(false);
         }
         obj.Way           = company.Way;
         obj.Title         = company.Title;
         obj.UserNum       = company.UserNum;
         obj.StoreNum      = company.StoreNum;
         obj.StoreProper   = company.StoreProper;
         obj.PosMinorDisp  = company.PosMinorDisp;
         obj.AppProper     = company.AppProper;
         obj.OpenVersionId = company.OpenVersionId;
         obj.MachineSN     = company.MachineSN;
         obj.SerialNo      = company.SerialNo;
         CompanyAuthorRepository.SaveChanges();
         return(true);
     }
     return(false);
 }
 public OpResult SaveOrUpdate(CompanyAuthorize obj)
 {
     if (!TraderRepository.GetQuery(o => o.CID == obj.CID).Any())
     {
         return(OpResult.Fail("商户不存在!"));
     }
     //if(!obj.RealmName.IsNullOrEmpty()) obj.RealmName=obj.RealmName.Trim();
     //if(!obj.RealmName.IsNullOrEmpty() && RealmRepository.GetQuery(o => o.Name == obj.RealmName && o.Url!=obj.RealmUrl).Any())
     //    return OpResult.Fail("子域名已存在!");
     obj.AppProper    = obj.AppProper ?? "N";
     obj.StoreProper  = obj.StoreProper ?? "N";
     obj.PosMinorDisp = obj.PosMinorDisp ?? "N";
     obj.MemberShared = obj.MemberShared ?? "Y";
     if (obj.Id == 0)
     {
         if (CompanyAuthorRepository.GetQuery(o => o.CID == obj.CID).Any())
         {
             return(OpResult.Fail("该商户已存在,如果已过期,请选择续约方式"));
         }
         obj.CreateDT     = DateTime.Now;
         obj.CreateUID    = CurrentUser.UID;
         obj.ExpirationDT = DateTime.Parse(obj.EffectiveDT).AddMonths(obj.ValidityNum.GetValueOrDefault()).ToString("yyyy-MM-dd");
         if (obj.RealmName.IsNullOrEmpty())
         {
             CompanyAuthorRepository.Add(obj);
         }
         else
         {
             //CompanyAuthorRepository.Add(obj, false);
             //RealmRepository.Add(new Realm() { CID = obj.CID.Value, Name = obj.RealmName, State = Convert.ToInt16(obj.RealmState), Url = obj.RealmName + obj.RealmSuffixUrl });
         }
     }
     else
     {
         var res = CompanyAuthorRepository.Get(obj.Id);
         var pwd = res.SupperPassword;
         obj.ToCopyProperty(res, new List <string>()
         {
             "CreateDT", "CreateUID", "CID", "MachineSN", "SerialNo"
         });
         res.ExpirationDT = DateTime.Parse(obj.EffectiveDT).AddMonths(obj.ValidityNum.GetValueOrDefault()).ToString("yyyy-MM-dd");
         if (obj.SupperPassword.IsNullOrEmpty())
         {
             res.SupperPassword = pwd;
         }
         //if(!res.RealmName.IsNullOrEmpty())
         //{
         //    var realm = RealmRepository.Find(o => o.Url == res.RealmUrl && o.CID==res.CID.Value);
         //    if (realm == null)
         //    {
         //        realm = new Realm();
         //        realm.CID = res.CID.Value;
         //        RealmRepository.Add(realm,false);
         //    }
         //    realm.Name = res.RealmName;
         //    realm.Url = res.RealmName + res.RealmSuffixUrl;
         //    realm.State = Convert.ToInt16(res.RealmState);
         //}
         //else if (res.RealmName.IsNullOrEmpty())
         //{
         //    var reals = RealmRepository.GetQuery(o => o.Url == res.RealmUrl && o.CID == res.CID).ToList();
         //    RealmRepository.RemoveRange(reals, false);
         //}
         CompanyAuthorRepository.SaveChanges();
     }
     return(OpResult.Success());
 }
        public Pharos.Utility.OpResult Deletes(int[] ids)
        {
            var list = CompanyAuthorRepository.GetQuery(o => ids.Contains(o.Id)).ToList();

            return(OpResult.Result(CompanyAuthorRepository.RemoveRange(list)));
        }
        public IEnumerable <dynamic> GetPageList(System.Collections.Specialized.NameValueCollection nvl, out int recordCount)
        {
            var text            = nvl["searchText"];
            var searchField     = nvl["searchField"];
            var state           = nvl["state"];
            var Assigner        = nvl["Assigner"];
            var Way             = nvl["Way"];
            var OpenVersionId   = nvl["OpenVersionId"];
            var ValidityNum     = nvl["ValidityNum"];
            var queryUser       = UserRepository.GetQuery();
            var queryDict       = DataDictRepository.GetQuery();
            var queryProductVer = ProductVerRepository.GetQuery();
            var bussinessList   = BusinessRepository.GetQuery().ToList();

            var where = DynamicallyLinqHelper.Empty <CompanyAuthorize>();
            if (!text.IsNullOrEmpty())
            {
                int cid = 0;
                text = text.Trim();
                int.TryParse(text, out cid);
                if (searchField == "Cid")
                {
                    where = where.And(o => o.CID == cid);
                }
                else if (searchField == "Title")
                {
                    where = where.And(o => o.Title.Contains(text));
                }
                else if (searchField == "ContractNo")
                {
                    where = where.And(o => o.ContractNo != null && o.ContractNo.StartsWith(text));
                }
            }
            short way = 0, st = 0, verid = 0, validnum = 0;

            short.TryParse(Way, out way);
            short.TryParse(state, out st);
            short.TryParse(OpenVersionId, out verid);
            short.TryParse(ValidityNum, out validnum);
            where = where.And(o => o.AssignerUID == Assigner, Assigner.IsNullOrEmpty()).And(o => o.Way == way, Way.IsNullOrEmpty()).And(o => o.Status == st, state.IsNullOrEmpty())
                    .And(o => o.OpenVersionId == verid, OpenVersionId.IsNullOrEmpty()).And(o => o.ValidityNum == validnum, ValidityNum.IsNullOrEmpty());
            var query = CompanyAuthorRepository.GetQuery(where);
            var q     = from x in query
                        join y in queryProductVer on x.OpenVersionId equals y.ProductId
                        select new
            {
                x.Id,
                x.CreateDT,
                x,
                BusinessModeTitle = queryDict.Where(o => o.DicSN == x.BusinessMode).Select(o => o.Title).FirstOrDefault(),
                Assigner          = queryUser.Where(o => o.UserId == x.AssignerUID).Select(o => o.FullName).FirstOrDefault(),
                y.ProductId,
                y.SysName
            };

            recordCount = q.Count();
            var list = q.ToPageList();

            return(list.Select(o => new{
                o.x.Id,
                o.x.CID,
                o.x.Source,
                o.x.Way,
                o.x.AppProper,
                o.x.StoreProper,
                o.x.Title,
                o.x.ContractNo,
                o.x.EffectiveDT,
                o.x.ExpirationDT,
                o.x.ValidityNum,
                o.x.UserNum,
                o.x.StoreNum,
                o.x.PosMinorDisp,
                o.x.MemberShared,
                o.x.OpenVersionId,
                o.x.Status,
                o.x.SupperAccount,
                o.x.CreateDT,
                o.x.OpenScopeId,
                o.BusinessModeTitle,
                o.Assigner,
                OpenVersionTitle = "(" + o.ProductId + ")" + o.SysName,
                StatusTitle = Enum.GetName(typeof(CompanyAuthorizeState), o.x.Status),
                OpenScopeTitle = o.x.OpenScopeId.IsNullOrEmpty() ? "" : string.Join(",", bussinessList.Where(i => o.x.OpenScopeId.Split(',').Contains(i.ById)).Select(i => i.Title))
            }));
        }