当前位置: 首页>>代码示例>>C#>>正文


C# Repository.FilterBy方法代码示例

本文整理汇总了C#中Repository.FilterBy方法的典型用法代码示例。如果您正苦于以下问题:C# Repository.FilterBy方法的具体用法?C# Repository.FilterBy怎么用?C# Repository.FilterBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Repository的用法示例。


在下文中一共展示了Repository.FilterBy方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: using

        ServiceResponse<IList<BudgetReceipt>> ISearchEngine.FindBudgetItemDescriptions(ServiceRequest<BudgetReceipt> searchRequest)
        {
            var output = new ServiceResponse<IList<BudgetReceipt>>();

            using (var unitOfWork = RepositoryManager<BudgetReceipt>.Instance.CreateWorkUnit())
            {
                try
                {
                    var repo = new Repository<BudgetReceipt>(unitOfWork.Session);
                    var result = repo.FilterBy(x => (x.Subscriber.Id == _subscriber.Id && x.Description.StartsWith(searchRequest.Data.Description))).ToList();
                    unitOfWork.Commit();

                    output.Data = result.Distinct(new BudgetReceipt.DescriptionCompare()).ToList();
                    output.Result = Result.Successful;

                }
                catch (GenericADOException e)
                {
                    output.Message = MessageFactory.CreateGenerator(RepositoryType.Postgres).GenerateErrorMessage(e);
                    _logger.Critical(output.Message, e);
                    output.Result = Result.Failure;
                }
                catch (Exception e)
                {
                    _logger.Critical(e.Message, e);
                }
            }

            return output;
        }
开发者ID:RabidDog,项目名称:myfinfriend,代码行数:30,代码来源:DefaultSearchEngine.cs

示例2: using

        ServiceResponse<Subscriber> ISubscriptionService.Authenticate(ServiceRequest<Subscriber> request)
        {
            var output = new ServiceResponse<Subscriber>();

            using (var unitOfWork = RepositoryManager<Subscriber>.Instance.CreateWorkUnit())
            {
                try
                {
                    var repo = new Repository<Subscriber>(unitOfWork.Session);
                    var data = request.Data;

                    var subscribers = repo.FilterBy(x => x.Email == data.Email).ToList();

                    if (subscribers.Count == 0)
                    {
                        output.Result = Result.LoginFailed;
                        output.Message = "Invalid user name and password";
                        return output;
                    }

                    foreach (var subscriber in subscribers)
                    {
                        var password = Cryptography.GetMD5Hash(Cryptography.CreateInstance().Decrypt(subscriber.Password));

                        if (data.Password != password) continue;

                        var guid = Cryptography.GetMD5Hash(Guid.NewGuid().ToString());
                        output.Data = subscriber;
                        output.Data.Password = guid;
                        output.Result = Result.Successful;
                        ServiceDirectory.CacheService(CacheType.Memory).AddItem(guid, subscriber);

                        return output;
                    }

                }
                catch (GenericADOException e)
                {
                    output.Message = MessageFactory.CreateGenerator(RepositoryType.Postgres).GenerateErrorMessage(e);
                    output.Result = Result.Failure;
                }
                catch (Exception e)
                {
                    _logger.Critical(e.Message, e);
                    output.Message = "Invalid username or password";
                    output.Result = Result.Failure;
                }
            }

            return output;
        }
开发者ID:RabidDog,项目名称:myfinfriend,代码行数:51,代码来源:DefaultSubscriptionService.cs

示例3: btSave_Click

        private void btSave_Click(object sender, EventArgs e)
        {
            if ( ! string.IsNullOrEmpty(tbxSubject.Text)  && ! string.IsNullOrEmpty(tbxBody.Text) )
            {
                if ( dtpExpiryDate.Value < dtpPublishDate.Value )
                {
                    ShowError("Error", "Expiry date cannot be before the publish date.");
                    return;
                }
                _unitOfWork = new UnitOfWork(_sessionHelper.GetSessionFactory("APL"));
                Repository<Guid, State> _stateRepo = new Repository<Guid, State>(_unitOfWork.Session);
                Repository<Guid, APLBackendDB.Region> _regionRepo = new Repository<Guid, APLBackendDB.Region>(_unitOfWork.Session);
                Repository<Guid, Brand> _brandRepo = new Repository<Guid, Brand>(_unitOfWork.Session);
                Repository<Guid, NewsItem> _newsItemRepo = new Repository<Guid, NewsItem>(_unitOfWork.Session);
                Repository<Guid, APLBackendDB.Image> _imageRepo = new Repository<Guid, APLBackendDB.Image>(_unitOfWork.Session);

                _newsItem = _newsItemRepo.FindBy(_newsItemId);
                if ( _newsItem == null )
                {
                    _newsItem = new NewsItem();
                }

                _newsItem.Subject = tbxSubject.Text;
                _newsItem.Active = cbxActive.Checked;
                _newsItem.Author = tbxAuthor.Text;
                _newsItem.Body = tbxBody.Text;

                APLBackendDB.Brand _brand = _brandRepo.FindBy(Guid.Parse(cbxBrand.SelectedValue.ToString()));
                if ( _brand != null )
                {
                    _newsItem.Brand = _brand;
                }
                State _state = _stateRepo.FindBy(Guid.Parse(cbxState.SelectedValue.ToString()));
                if ( _state != null )
                {
                    _newsItem.State = _state;
                }
                APLBackendDB.Region _region = _regionRepo.FindBy(Guid.Parse(cbxRegion.SelectedValue.ToString()));
                if ( _region != null )
                {
                    _newsItem.Region = _region;
                }
                _newsItem.ExpiryDate = dtpExpiryDate.Value;
                _newsItem.PublishDate = dtpPublishDate.Value;
                _newsItem.Push = cbxPush.Checked;

                //_imageRepo.AddOrUpdate(_images);
                _newsItem.Images = _images;

                if (_newsItem.Id == Guid.Empty)
                {
                    _newsItemRepo.Add(_newsItem);
                }
                else
                {
                    _newsItemRepo.Update(_newsItem);
                }

                _unitOfWork.Commit();
                _unitOfWork.Dispose();

                if ( cbxPush.Checked )
                {
                    GoogleInteraction.GCMMessage gcmMessage = new GCMMessage();
                    UnitOfWork unitOfWork = new UnitOfWork(_sessionHelper.GetSessionFactory("APL"));

                    Repository<Guid, UserMobileDevice> userMobileDeviceRepo = new Repository<Guid, UserMobileDevice>(unitOfWork.Session);

                    var devices = userMobileDeviceRepo.FilterBy(x => x.EnablePushNotifications == true);

                    gcmMessage.Data.Add("message", tbxSubject.Text);
                    gcmMessage.Data.Add("type", "news="+_newsItem.Id.ToString());
                    foreach (UserMobileDevice userMobileDevice in devices)
                    {
                        gcmMessage.RecipientDevices.Add(userMobileDevice.Token);
                    }
                    gcmMessage.CollapseKey = "broadcast";
                    gcmMessage.Send();

                }
            } else
            {

            }
        }
开发者ID:themanowar77,项目名称:myaplwin,代码行数:85,代码来源:NewsItemEdit.cs

示例4: Authenticate

        public string Authenticate(string Username, string Password)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();
            JsonSerializerSettings j = new JsonSerializerSettings();
            j.TypeNameHandling = TypeNameHandling.Objects;
            j.Formatting = Newtonsoft.Json.Formatting.Indented;

            string result = "ERR - Unknown";

            string responseString = null;
            Response response = new Response();
            UnitOfWork unitOfWork = new UnitOfWork(_sessionHelper.GetSessionFactory("APL"));
            Repository<Guid, User> userRepo = new Repository<Guid, User>(unitOfWork.Session);
            Repository<Guid, UserToken> userTokenRepo = new Repository<Guid, UserToken>(unitOfWork.Session);
            user = userRepo.FilterBy(x => x.Username == Username).FirstOrDefault();

            if (user != null && user.Id != Guid.Empty)
            {
                if (Password == user.Password)
                {
                    AuthToken token = new AuthToken();

                    if (!string.IsNullOrEmpty(user.AuthToken))
                    {
                        if (CheckToken(user.AuthToken) == null)
                        {
                            user.AuthToken = null;
                        }
                    }

                    if (string.IsNullOrEmpty(user.AuthToken))
                    {
                        result = GenerateAuthToken();
                        APLBackendDB.UserToken userToken = new UserToken();
                        userToken.CreateDate = DateTime.Now;
                        userToken.ExpiryDate = DateTime.Now.AddHours(4);
                        userToken.LastUsedDate = DateTime.Now;
                        userToken.Token = result;
                        userToken.UserId = user.Id;
                        userTokenRepo.Add(userToken);

                        user.AuthToken = result;
                        userRepo.Update(user);

                        token.Token = result;
                    }
                    else
                    {
                        token.Token = user.AuthToken;
                    }

                    response.ResponseCode = "OK";
                    response.ResponseData = token;
                }
                else
                {
                    response.ResponseCode = "ERR";
                    response.ResponseData = "Authentication failed.";
                }
            }
            else
            {
                response.ResponseCode = "ERR";
                response.ResponseData = "User not found.";
            }

            js = new JavaScriptSerializer();
            responseString = JsonConvert.SerializeObject(response, j);
            unitOfWork.Commit();
            return responseString;
        }
开发者ID:themanowar77,项目名称:myaplwin,代码行数:71,代码来源:APL.asmx.cs

示例5: CheckToken

        private User CheckToken(string token)
        {
            UnitOfWork unitOfWork = new UnitOfWork(_sessionHelper.GetSessionFactory("APL"));
            Repository<Guid, User> userRepo = new Repository<Guid, User>(unitOfWork.Session);
            User check_user = userRepo.FilterBy(x => x.AuthToken == token).FirstOrDefault();
            if (check_user != null)
            {
                UserToken currentUt = null;

                if (check_user.AuthTokens.Count > 0)
                {
                    IList<UserToken> utList = check_user.AuthTokens;
                    foreach (UserToken ut in utList)
                    {
                        if (ut.Token == token)
                        {
                            currentUt = ut;
                            break;
                        }
                    }
                }

                if (currentUt != null)
                {
                    if (currentUt.ExpiryDate < DateTime.Now)
                    {
                        check_user.AuthTokens.Remove(currentUt);
                        check_user.AuthToken = null;
                        userRepo.Update(check_user);
                    }
                    else
                    {
                        check_user.AuthTokens.Remove(currentUt);
                        currentUt.LastUsedDate = DateTime.Now;
                        check_user.AuthTokens.Add(currentUt);
                        userRepo.Update(check_user);
                    }
                }
            }
            unitOfWork.Commit();
            return check_user;
        }
开发者ID:themanowar77,项目名称:myaplwin,代码行数:42,代码来源:APL.asmx.cs

示例6: RegisterDevice

        public string RegisterDevice(string token, string deviceType, string deviceId)
        {
            UnitOfWork unitOfWork = new UnitOfWork(_sessionHelper.GetSessionFactory("APL"));

            Repository<Guid, User> userRepo = new Repository<Guid, User>(unitOfWork.Session);

            JavaScriptSerializer js = new JavaScriptSerializer();
            JsonSerializerSettings j = new JsonSerializerSettings();
            j.TypeNameHandling = TypeNameHandling.Objects;
            j.Formatting = Newtonsoft.Json.Formatting.Indented;

            string responseString = null;
            Response response = new Response();

            user = CheckToken(token);
            if (user.AuthToken == null || user.AuthToken != token)
            {
                user.AuthToken = token;
                userRepo.Update(user);
            }

            if (!string.IsNullOrEmpty(user.AuthToken))
            {
                if (CheckToken(user.AuthToken) == null)
                {
                    user.AuthToken = null;
                }
            }

            if (user != null)
            {
                if (DEVICE_TYPES.Contains(deviceType.ToLower()))
                {
                    UserMobileDevice userMobileDevice = new UserMobileDevice();
                    Repository<Guid, UserMobileDevice> userMobileDevRepo = new Repository<Guid, UserMobileDevice>(unitOfWork.Session);
                    userMobileDevice = userMobileDevRepo.FilterBy(x => x.Token == deviceId).FirstOrDefault();
                    if (userMobileDevice != null && userMobileDevice.Id != Guid.Empty)
                    {
                        if (userMobileDevice.MobileDeviceType.ToLower() == deviceType.ToLower() && userMobileDevice.User.Id == user.Id)
                        {
                            response.ResponseCode = "OK";
                            response.ResponseData = "Device registered.";
                        }
                        else
                        {
                            response.ResponseCode = "ERR";
                            response.ResponseData = "Invalid device registration";
                        }

                    }
                    else
                    {
                        userMobileDevice = new UserMobileDevice();
                        userMobileDevice.MobileDeviceType = deviceType.ToLower();
                        userMobileDevice.Token = deviceId;
                        userMobileDevice.User = user;
                        userMobileDevice.EnablePushNotifications = true;
                        user.MobileDevices.Add(userMobileDevice);
                        userMobileDevRepo.Add(userMobileDevice);
                        response.ResponseCode = "OK";
                        response.ResponseData = "Device registered.";
                    }
                }
                else
                {
                    response.ResponseCode = "ERR";
                    response.ResponseData = "Unknown DeviceType";
                }

            }
            else
            {
                response.ResponseCode = "ERR";
                response.ResponseData = "Authentication required.";
            }
            unitOfWork.Commit();

            js = new JavaScriptSerializer();
            responseString = JsonConvert.SerializeObject(response, j);
            return responseString;
        }
开发者ID:themanowar77,项目名称:myaplwin,代码行数:81,代码来源:APL.asmx.cs

示例7: GetVenues

        public string GetVenues(string token, string regionId, string stateId)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();
            JsonSerializerSettings j = new JsonSerializerSettings();
            j.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            j.TypeNameHandling = TypeNameHandling.Objects;
            j.Formatting = Newtonsoft.Json.Formatting.Indented;

            Guid regionGuid;
            Guid stateGuid;

            if ( ! Guid.TryParse(regionId, out regionGuid))
            {
                regionGuid = Guid.Empty;
            }

            if ( ! Guid.TryParse(stateId, out stateGuid))
            {
                stateGuid = Guid.Empty;
            }

            string responseString = null;
            Response response = new Response();

            Repository<Guid, Venue> venueRepo = new Repository<Guid, Venue>(_sessionHelper.GetSession("APL"));

            var list = venueRepo.FilterBy(x => ( x.Active == true
                                                && ( regionGuid==Guid.Empty || x.Region.Id == regionGuid )
                                                && ( stateGuid == Guid.Empty || x.Region.State.Id == stateGuid )
                                                )).OrderBy(x => x.Name);
            response.ResponseCode = "OK";
            response.ResponseData = list;

            var serialiser = new JsonSerializer
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                ContractResolver = new NHibernateContractResolver(),
                TypeNameHandling = TypeNameHandling.Objects,
                Formatting = Newtonsoft.Json.Formatting.Indented
            };
            StringWriter stringWriter = new StringWriter();
            JsonWriter jsonWriter = new JsonTextWriter(stringWriter);
            serialiser.Serialize(jsonWriter, response);
            responseString = stringWriter.ToString();

            return responseString;
        }
开发者ID:themanowar77,项目名称:myaplwin,代码行数:47,代码来源:APL.asmx.cs

示例8: GetRegions

        public string GetRegions(string token, string brandId, string stateId)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();
            JsonSerializerSettings j = new JsonSerializerSettings();
            j.TypeNameHandling = TypeNameHandling.Objects;
            j.Formatting = Newtonsoft.Json.Formatting.Indented;

            string responseString = null;
            Response response = new Response();
            Guid brandID = Guid.Empty;
            if (! Guid.TryParse(brandId, out brandID))
            {
                brandID = Guid.Empty;
            }

            Guid stateID = Guid.Empty;
            if (!Guid.TryParse(stateId, out stateID))
            {
                brandID = Guid.Empty;
            }

            Repository<Guid, Region> _regionRepo = new Repository<Guid, Region>(_sessionHelper.GetSession("APL"));

            var list = _regionRepo.FilterBy((p => (
                            (brandID==Guid.Empty|| p.Brand.Id==brandID )
                            && p.Active == true
                            && (stateID==Guid.Empty || p.State.Id == stateID)))).OrderBy(p=>p.Name);

            response.ResponseCode = "OK";
            response.ResponseData = list;
            var serialiser = new JsonSerializer { ReferenceLoopHandling = ReferenceLoopHandling.Ignore, ContractResolver = new NHibernateContractResolver(), TypeNameHandling = TypeNameHandling.Objects, Formatting = Newtonsoft.Json.Formatting.Indented };
            StringWriter stringWriter = new StringWriter();
            JsonWriter jsonWriter = new JsonTextWriter(stringWriter);
            serialiser.Serialize(jsonWriter, response);

            responseString = stringWriter.ToString();

            return responseString;
        }
开发者ID:themanowar77,项目名称:myaplwin,代码行数:39,代码来源:APL.asmx.cs

示例9: GetNewsItems

        public string GetNewsItems(string token)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();
            JsonSerializerSettings j = new JsonSerializerSettings();
            j.ContractResolver = new NHibernateContractResolver();
            j.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            j.TypeNameHandling = TypeNameHandling.Objects;
            j.Formatting = Newtonsoft.Json.Formatting.Indented;

            string responseString = null;
            Response response = new Response();

            Repository<Guid, NewsItem> newsItemRepo = new Repository<Guid, NewsItem>(_sessionHelper.GetSession("APL"));

            var list = newsItemRepo.FilterBy(x => x.Active == true && x.ExpiryDate >= DateTime.Today).OrderBy(x=>x.Importance).OrderByDescending(x => x.PublishDate);
            response.ResponseCode = "OK";
            response.ResponseData = list;

            responseString = JsonConvert.SerializeObject(response, j);

            return responseString;
        }
开发者ID:themanowar77,项目名称:myaplwin,代码行数:22,代码来源:APL.asmx.cs

示例10: GetGameList

        public string GetGameList(string token, string stateId, string brandId, string regionId, string venueId, int daysInAdvance)
        {
            Guid stateID = Guid.Empty;
            Guid brandID = Guid.Empty;
            Guid regionID = Guid.Empty;
            Guid venueID = Guid.Empty;

            Repository<Guid, Game> gameRepo = new Repository<Guid, Game>(_sessionHelper.GetSession("APL"));

            // Parse out the Guids.

            if (!Guid.TryParse(stateId, out stateID))
            {
                stateID = Guid.Empty;
            }
            if (!Guid.TryParse(brandId, out brandID))
            {
                brandID = Guid.Empty;
            }
            if (!Guid.TryParse(regionId, out regionID))
            {
                regionID = Guid.Empty;
            }
            if (!Guid.TryParse(venueId, out venueID))
            {
                venueID = Guid.Empty;
            }

            Response response = new Response();

            var g = gameRepo.FilterBy(x => (
                                                (stateID == Guid.Empty || x.Venue.Region.State.Id == stateID)
                                                && (brandID == Guid.Empty || x.Venue.Region.Brand.Id == brandID)
                                                && (regionID == Guid.Empty || x.Venue.Region.Id == regionID)
                                                && (venueID == Guid.Empty || x.Venue.Id == venueID)
                                                && (x.GameDate >= DateTime.Today && x.GameDate <= DateTime.Today.AddDays(daysInAdvance) )
                                                && (x.Active == true )
                                                && (x.Venue.Active == true )
                                                && (x.Venue.Region.Active == true )
                                                )
            ).OrderBy(x=>x.GameDate);

            if (g != null && g.Count() > 0)
            {
                response.ResponseCode = "OK";
                response.ResponseData = g;
            }
            else
            {
                response.ResponseCode = "ERR";
                response.ResponseData = "No events returned";
            }

            JavaScriptSerializer js = new JavaScriptSerializer();
            JsonSerializerSettings j = new JsonSerializerSettings();
            j.TypeNameHandling = TypeNameHandling.Objects;
            j.Formatting = Newtonsoft.Json.Formatting.Indented;
            var serialiser = new JsonSerializer { ReferenceLoopHandling = ReferenceLoopHandling.Ignore, ContractResolver = new NHibernateContractResolver(), TypeNameHandling = TypeNameHandling.Objects, Formatting = Newtonsoft.Json.Formatting.Indented };
            StringWriter stringWriter = new StringWriter();
            JsonWriter jsonWriter = new JsonTextWriter(stringWriter);
            serialiser.Serialize(jsonWriter, response);

            string responseString = stringWriter.ToString();
            return responseString;
        }
开发者ID:themanowar77,项目名称:myaplwin,代码行数:65,代码来源:APL.asmx.cs

示例11: using

        ServiceResponse<IList<BudgetItem>> IBudgetService.BudgetItemList(String budgetId)
        {
            var output = new ServiceResponse<IList<BudgetItem>>();

            using (var unitOfWork = RepositoryManager<BudgetItem>.Instance.CreateWorkUnit())
            {
                try
                {
                    var repo = new Repository<BudgetItem>(unitOfWork.Session);
                    List<BudgetItem> result;

                    result = String.IsNullOrEmpty(budgetId)
                        ? repo.FilterBy(x => x.Subscriber.Id == _subscriber.Id).ToList()
                        : repo.FilterBy(x => (x.Subscriber.Id == _subscriber.Id && x.Budget.Id == budgetId)).ToList();

                    unitOfWork.Commit();

                    foreach (var item in result)
                    {
                        if (item.ReceiptList == null)
                        {
                            continue;
                        }

                        foreach (var receipt in item.ReceiptList.Where(receipt => !receipt.BudgetPeriod.EndDate.HasValue))
                        {
                            item.CurrentPeriod = receipt.BudgetPeriod;
                        }

                    }

                    output.Data = result;
                    output.Result = Result.Successful;

                }
                catch (GenericADOException e)
                {
                    output.Message = MessageFactory.CreateGenerator(RepositoryType.Postgres).GenerateErrorMessage(e);
                    _logger.Critical(output.Message, e);
                    output.Result = Result.Failure;
                }
                catch (Exception e)
                {
                    _logger.Critical(e.Message, e);
                }
            }

            return output;
        }
开发者ID:RabidDog,项目名称:myfinfriend,代码行数:49,代码来源:DefaultBudgetService.cs

示例12: SyncVenue

        public void SyncVenue()
        {
            ProgressUpdateArgs e = new ProgressUpdateArgs();
            // Venue Table

            _UnitOfWorkAPL = new UnitOfWork(_sessionHelper.GetSessionFactory("APL"));
            _UnitOfWorkFHG = new UnitOfWork(_sessionHelper.GetSessionFactory("FHG"));

            Repository<int, CusOrgentity> _fhgVenueRepo = new Repository<int, CusOrgentity>(_UnitOfWorkFHG.Session);
            Repository<Guid, Venue> _aplVenueRepo = new Repository<Guid, Venue>(_UnitOfWorkAPL.Session);
            Repository<Guid, Region> _aplRegionRepo = new Repository<Guid, Region>(_UnitOfWorkAPL.Session);

            //IList<object[]> fhgVenue = _sessionHelper.GetStatelessSession("FHG").QueryOver<CusOrgentity>()
            //                            .Select(c => c.Orgentityid,
            //                            c => c.Active,
            //                            c => c.Name).List<object[]>();

            //IList<object[]> aplVenueResult = _sessionHelper.GetStatelessSession("APL").QueryOver<Venue>()
            //    .Select(c => c.Id,
            //    c => c.FHGVenueId,
            //    c => c.Active,
            //    c => c.Name).List<object[]>();

            var fhgVenue = _fhgVenueRepo.All().ToList();
            var aplVenueResult = _aplVenueRepo.All().ToList();

            Dictionary<int, object> aplVenues = new Dictionary<int, object>();
            foreach (Venue o in aplVenueResult)
            {
                aplVenues.Add(o.FHGVenueId, o);
            }

            // Add Missing data
            int itemCount = 1;
            foreach (CusOrgentity fhgCustOrgEntity in fhgVenue)
            {
                try
                {
                     e.TotalWorkItems = fhgVenue.Count();
                    e.CurrentWorkItem = itemCount;
                    e.StatusString = "Syncing Venues - (" + itemCount.ToString() + "/" + e.TotalWorkItems.ToString() + ")";
                    this.ProgressUpdate(e);

                    if (!aplVenues.ContainsKey(fhgCustOrgEntity.Id))
                    {
                        CusOrgentity c = fhgCustOrgEntity;
                        Venue v = new Venue();
                        v.Name = c.Name;
                        v.Active = (c.Active != null) ? (bool)c.Active : true;
                        v.FHGVenueId = c.Id;
                        if (c.Region.Count > 0)
                        {
                            v.Region = _aplRegionRepo.FilterBy(x => x.Name == c.Region[0].Regionname).FirstOrDefault();
                        }
                        _aplVenueRepo.Add(v);
                    }
                    else
                    {
                        Venue aplVenue = (Venue)aplVenues[fhgCustOrgEntity.Id];

                        if (aplVenue.Active != fhgCustOrgEntity.Active || aplVenue.Name != fhgCustOrgEntity.Name)
                        {
                            aplVenue.Name = fhgCustOrgEntity.Name;
                            aplVenue.Active = (bool)(fhgCustOrgEntity.Active.HasValue ? false : fhgCustOrgEntity.Active);
                            _aplVenueRepo.Update(aplVenue);
                        }
                    }
                    itemCount++;
                }
                catch (Exception mException)
                {
                    int x = 1;
                    continue;
                }
            }

            _UnitOfWorkAPL.Commit();
            _UnitOfWorkFHG.Commit();
        }
开发者ID:themanowar77,项目名称:myaplwin,代码行数:79,代码来源:DBSync.cs

示例13: SyncRegion

        public void SyncRegion()
        {
            ProgressUpdateArgs e = new ProgressUpdateArgs();
            // Region Table
            //
            // Select data from FHGLocal
            // Select data from Local DB
            // Compare and update/insert.

            _UnitOfWorkAPL = new UnitOfWork(_sessionHelper.GetSessionFactory("APL"));
            _UnitOfWorkFHG = new UnitOfWork(_sessionHelper.GetSessionFactory("FHG"));

            DataLayer.Repository<int, CusRegion> _fhgRegionRepo = new Repository<int, CusRegion>(_UnitOfWorkFHG.Session);
            Repository<Guid, Region> _aplRegionRepo = new Repository<Guid, Region>(_UnitOfWorkAPL.Session);
            Repository<Guid, State> _aplStateRepo = new Repository<Guid, State>(_UnitOfWorkAPL.Session);
            Repository<Guid, Brand> _aplBrandRepo = new Repository<Guid, Brand>(_UnitOfWorkAPL.Session);

            var regionAPLDB = _aplRegionRepo.All().ToList();
            var regionFHG = _fhgRegionRepo.All().ToList();
            int itemCount = 1;
            // Add Missing data
            foreach (CusRegion c in regionFHG)
            {
                e.TotalWorkItems = regionFHG.Count();
                e.CurrentWorkItem = itemCount;
                e.StatusString = "Syncing Regions - (" + itemCount.ToString() + "/" + e.TotalWorkItems.ToString() + ")";
                this.ProgressUpdate(e);

                bool found = false;
                foreach (Region s in regionAPLDB)
                {
                    if (s.Name == c.Regionname)
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    Region r = new Region();
                    r.Name = c.Regionname;
                    r.Active = !c.Archived.HasValue ? false : !(bool)c.Archived;
                    r.State = _aplStateRepo.FilterBy(s => s.Name == c.CusState.Fullname).FirstOrDefault();
                    r.Brand = _aplBrandRepo.FilterBy(x => x.FhgBrandId == c.Brandid).FirstOrDefault();
                    _aplRegionRepo.Add(r);
                }
                itemCount++;
            }

            // Remove extra data.
            foreach (Region r in regionAPLDB)
            {
                bool found = false;
                foreach (CusRegion cr in regionFHG)
                {
                    if (r.Name == cr.Regionname)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    _aplRegionRepo.Delete(r);
                }
            }

            _UnitOfWorkAPL.Commit();
            _UnitOfWorkFHG.Commit();
        }
开发者ID:themanowar77,项目名称:myaplwin,代码行数:71,代码来源:DBSync.cs

示例14: SyncGame

        public void SyncGame()
        {
            ProgressUpdateArgs e = new ProgressUpdateArgs();
            e.StatusString = "Syncing Games - Reading data";
            this.ProgressUpdate(e);

            _UnitOfWorkAPL = new UnitOfWork(_sessionHelper.GetSessionFactory("APL"));
            _UnitOfWorkFHG = new UnitOfWork(_sessionHelper.GetSessionFactory("FHG"));

            // Customer/Memeber Table
            Repository<int, EvtEvent> _fhgEventRepo = new Repository<int, EvtEvent>(_UnitOfWorkFHG.Session);
            Repository<Guid, EvtGame> _fhgEvtGameRepo = new Repository<Guid, EvtGame>(_UnitOfWorkFHG.Session);
            Repository<Guid, Game> _aplGameRepo = new Repository<Guid, Game>(_UnitOfWorkAPL.Session);
            Repository<Guid, Venue> _aplVenueRepo = new Repository<Guid, Venue>(_UnitOfWorkAPL.Session);
            Repository<Guid, GameType> _aplGameTypeRepo = new Repository<Guid, GameType>(_UnitOfWorkAPL.Session);

            IList<object[]> fhgEvents = _UnitOfWorkFHG.Session.QueryOver<EvtEvent>()
                .Select(x => x.Eventid,
                x => x.Updateversion).Where(x => x.Eventdate >= DateTime.Today.AddDays(-7)).List<object[]>();

            IList<object[]> aplGames = _UnitOfWorkAPL.Session.QueryOver<Game>()
                .Select(c => c.Id,
                c => c.FHGEventId,
                c => c.FHGUpdateVersion).List<object[]>();

            Dictionary<int, object> aplGameList = new Dictionary<int, object>();
            foreach (object[] o in aplGames)
            {
                aplGameList.Add(int.Parse(o[1].ToString()), o);
            }

            int itemCount = 1;

            foreach (object[] fhgEventObject in fhgEvents)
            {
                try
                {
                    e.TotalWorkItems = fhgEvents.Count();
                    e.CurrentWorkItem = itemCount;
                    e.StatusString = "Syncing Games - (" + itemCount.ToString() + "/" + e.TotalWorkItems.ToString() + ")";
                    this.ProgressUpdate(e);

                    int fhgEventId = int.Parse(fhgEventObject[0].ToString());
                    Guid fhgUpdateVersion = Guid.Parse(fhgEventObject[1].ToString());

                    if (!aplGameList.ContainsKey(fhgEventId))
                    {

                        EvtEvent curEvent = _fhgEventRepo.FindBy(fhgEventId);

                        // Skip events which don't have a venue assigned.  Why??
                        if (!curEvent.Orgentityid.HasValue)
                        {
                            continue;
                        }

                        EvtGame curEventGame = curEvent.EvtGame[0];

                        Venue gameVenue = _aplVenueRepo.FilterBy(x => x.FHGVenueId == curEvent.Orgentityid).FirstOrDefault();
                        GameType gameType = _aplGameTypeRepo.FilterBy(x => x.FhgDivisionId == curEventGame.Divisionid).FirstOrDefault();

                        Game newGame = new Game();
                        newGame.FHGEventId = fhgEventId;
                        newGame.FHGUpdateVersion = curEvent.Updateversion;
                        newGame.Description = (!string.IsNullOrEmpty(curEventGame.Gamedescription)) ? curEventGame.Gamedescription : curEvent.Eventdescription;
                        newGame.GameDate = curEvent.Eventdate;
                        newGame.Name = curEvent.Eventname;
                        newGame.RegoTime = DateTime.Parse(curEvent.Eventdate.Value.ToShortDateString() + " " + curEvent.Registrationtime);
                        newGame.StartTime = DateTime.Parse(curEvent.Eventdate.Value.ToShortDateString() + " " + curEvent.Starttime);
                        newGame.Venue = gameVenue;
                        newGame.GameType = gameType;
                        newGame.Active = !curEvent.Archived.HasValue ? false : !(bool)curEvent.Archived;
                        newGame.BuyIn = curEventGame.Playerentryfee != null ? (float)curEventGame.Playerentryfee : 0;

                        _aplGameRepo.Add(newGame);

                    }
                    else
                    {
                        object[] aplComparison = (object[])aplGameList[fhgEventId];
                        Guid aplGameId = Guid.Parse(aplComparison[0].ToString());
                        int aplfhgGameId = int.Parse(aplComparison[1].ToString());
                        Guid aplfhgGameUpdateVersion = Guid.Parse(aplComparison[2].ToString());
                        // Check for updates.
                        if (fhgUpdateVersion != aplfhgGameUpdateVersion)
                        {
                            Game aplGame = _aplGameRepo.FindBy(aplGameId);
                            EvtEvent curEvent = _fhgEventRepo.FindBy(fhgEventId);
                            EvtGame curEventGame = curEvent.EvtGame[0];
                            Venue gameVenue = _aplVenueRepo.FilterBy(x => x.FHGVenueId == curEvent.Orgentityid).FirstOrDefault();
                            GameType gameType = _aplGameTypeRepo.FilterBy(x => x.FhgDivisionId == curEventGame.Divisionid).FirstOrDefault();
                            aplGame.FHGEventId = fhgEventId;
                            aplGame.FHGUpdateVersion = curEvent.Updateversion;
                            aplGame.Description = (!string.IsNullOrEmpty(curEventGame.Gamedescription)) ? curEventGame.Gamedescription : curEvent.Eventdescription;
                            aplGame.GameDate = curEvent.Eventdate;
                            aplGame.Name = curEvent.Eventname;
                            aplGame.RegoTime = DateTime.Parse(curEvent.Eventdate.Value.ToShortDateString() + " " + curEvent.Registrationtime);
                            aplGame.StartTime = DateTime.Parse(curEvent.Eventdate.Value.ToShortDateString() + " " + curEvent.Starttime);
                            aplGame.Venue = gameVenue;
                            aplGame.GameType = gameType;
//.........这里部分代码省略.........
开发者ID:themanowar77,项目名称:myaplwin,代码行数:101,代码来源:DBSync.cs


注:本文中的Repository.FilterBy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。