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 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());
 }