public CompanyAuthorize GetOne(object id)
        {
            var obj = CompanyAuthorRepository.Get(id);

            if (obj != null)
            {
                var realm = RealmRepository.Find(o => o.CID == obj.CID);
                if (realm != null)
                {
                    obj.RealmName  = realm.Name;
                    obj.RealmState = realm.State == 1;
                    obj.RealmUrl   = realm.Url;
                }
            }
            return(obj);
        }
 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());
 }