/// <summary> /// Initializes a new instance of the <see cref="SegmentFilter"/> class. /// </summary> /// <param name="serviceVariationId">service_variation_id.</param> /// <param name="teamMemberIdFilter">team_member_id_filter.</param> public SegmentFilter( string serviceVariationId, Models.FilterValue teamMemberIdFilter = null) { this.ServiceVariationId = serviceVariationId; this.TeamMemberIdFilter = teamMemberIdFilter; }
public CustomerFilter(Models.CustomerCreationSourceFilter creationSource = null, Models.TimeRange createdAt = null, Models.TimeRange updatedAt = null, Models.FilterValue groupIds = null) { CreationSource = creationSource; CreatedAt = createdAt; UpdatedAt = updatedAt; GroupIds = groupIds; }
public CustomerFilter(Models.CustomerCreationSourceFilter creationSource = null, Models.TimeRange createdAt = null, Models.TimeRange updatedAt = null, Models.CustomerTextFilter emailAddress = null, Models.CustomerTextFilter phoneNumber = null, Models.CustomerTextFilter referenceId = null, Models.FilterValue groupIds = null) { CreationSource = creationSource; CreatedAt = createdAt; UpdatedAt = updatedAt; EmailAddress = emailAddress; PhoneNumber = phoneNumber; ReferenceId = referenceId; GroupIds = groupIds; }
public async Task <bool> Update(ShopAggregate shop) { if (shop == null) { throw new ArgumentNullException(nameof(shop)); } using (var transaction = await _context.Database.BeginTransactionAsync().ConfigureAwait(false)) { try { var record = await _context.Shops .Include(s => s.Comments) .Include(s => s.ProductCategories) .Include(s => s.ShopTags) .Include(c => c.ShopGameEntities).ThenInclude(s => s.GameEntity) .Include(s => s.Filters).ThenInclude(f => f.Values) .FirstOrDefaultAsync(s => s.Id == shop.Id).ConfigureAwait(false); if (record == null) { transaction.Rollback(); return(false); } record.BannerImage = shop.BannerImage; record.CategoryId = shop.CategoryId; record.Country = shop.Country; record.Description = shop.Description; record.GooglePlaceId = shop.GooglePlaceId; record.Latitude = shop.Latitude; record.Locality = shop.Locality; record.Longitude = shop.Longitude; record.Name = shop.Name; record.PostalCode = shop.PostalCode; record.ProfileImage = shop.ProfileImage; record.StreetAddress = shop.StreetAddress; record.Subject = shop.Subject; record.TotalScore = shop.TotalScore; record.AverageScore = shop.AverageScore; record.UpdateDateTime = shop.UpdateDateTime; var tags = new List <Models.ShopTag>(); // Update tags. var shopTags = shop.TagNames == null ? new List <string>() : shop.TagNames; var tagNames = shop.TagNames; var connectedTags = _context.Tags.Where(t => tagNames.Any(tn => t.Name == tn)); foreach (var connectedTag in connectedTags) { tags.Add(new Models.ShopTag { Id = Guid.NewGuid().ToString(), TagName = connectedTag.Name, ShopId = shop.Id }); } var connectedTagNames = (await connectedTags.Select(t => t.Name).ToListAsync().ConfigureAwait(false)); foreach (var notExistingTagName in tagNames.Where(tn => !connectedTagNames.Contains(tn))) { var newTag = new Models.Tag { Name = notExistingTagName, Description = notExistingTagName }; _context.Tags.Add(newTag); tags.Add(new Models.ShopTag { Id = Guid.NewGuid().ToString(), TagName = notExistingTagName, ShopId = shop.Id, Tag = newTag }); } record.ShopTags = tags; var productCategories = shop.ProductCategories == null ? new List <ShopProductCategory>() : shop.ProductCategories; var productCategoryIds = productCategories.Select(p => p.Id); var productCategoriesToUpdate = record.ProductCategories.Where(c => productCategoryIds.Contains(c.Id)); var productCategoriesToRemove = record.ProductCategories.Where(c => !productCategoryIds.Contains(c.Id)); var existingCategoryIds = record.ProductCategories.Select(c => c.Id); var productCategoriesToAdd = productCategories.Where(c => !existingCategoryIds.Contains(c.Id)); foreach (var productCategoryToUpdate in productCategoriesToUpdate) { var productCategory = productCategories.First(p => p.Id == productCategoryToUpdate.Id); productCategoryToUpdate.Name = productCategory.Name; productCategoryToUpdate.UpdateDateTime = productCategory.UpdateDateTime; productCategoryToUpdate.Description = productCategory.Description; } foreach (var productCategoryToRemove in productCategoriesToRemove) { _context.ProductCategories.Remove(productCategoryToRemove); } foreach (var productCategoryToAdd in productCategoriesToAdd) { var rec = new Models.ProductCategory { Id = productCategoryToAdd.Id, Description = productCategoryToAdd.Description, Name = productCategoryToAdd.Name, CreateDateTime = productCategoryToAdd.CreateDateTime, UpdateDateTime = productCategoryToAdd.UpdateDateTime, ShopId = shop.Id }; _context.ProductCategories.Add(rec); } var filters = shop.ShopFilters == null ? new List <ShopFilter>() : shop.ShopFilters; // Update filters. var filterIds = filters.Select(c => c.Id); var filtersToUpdate = record.Filters.Where(c => filterIds.Contains(c.Id)); var filtersToRemove = record.Filters.Where(c => !filterIds.Contains(c.Id)); var existingFilterIds = record.Filters.Select(c => c.Id); var filtersToAdd = filters.Where(c => !existingFilterIds.Contains(c.Id)); foreach (var filterToUpdate in filtersToUpdate) { var filter = filters.First(c => c.Id == filterToUpdate.Id); filterToUpdate.Name = filter.Name; var filterValues = filter.Values == null ? new List <ShopFilterValue>() : filter.Values; var filterValueIds = filterValues.Select(f => f.Id); var filterValuesToUpdate = filterToUpdate.Values.Where(v => filterValueIds.Contains(v.Id)); // Update filter values. var filterValuesToRemove = filterToUpdate.Values.Where(v => !filterValueIds.Contains(v.Id)); var existingFilterValueIds = filterToUpdate.Values.Select(v => v.Id); var filterValuesToAdd = filter.Values.Where(v => !existingFilterValueIds.Contains(v.Id)); foreach (var filterValueToUpdate in filterValuesToUpdate) { var filterValue = filterToUpdate.Values.First(v => v.Id == filterValueToUpdate.Id); filterValue.UpdateDateTime = filterValueToUpdate.UpdateDateTime; filterValue.Content = filterValueToUpdate.Content; } foreach (var filterValueToRemove in filterValuesToRemove) { _context.FilterValues.Remove(filterValueToRemove); } foreach (var filterValueToAdd in filterValuesToAdd) { var rec = new Models.FilterValue { Id = filterValueToAdd.Id, Content = filterValueToAdd.Content, CreateDateTime = filterValueToAdd.CreateDateTime, UpdateDateTime = filterValueToAdd.UpdateDateTime, FilterId = filter.Id }; _context.FilterValues.Add(rec); } } foreach (var filterToRemove in filtersToRemove) { _context.Filters.Remove(filterToRemove); } foreach (var filterToAdd in filtersToAdd) { var rec = new Models.Filter { Id = filterToAdd.Id, Name = filterToAdd.Name, ShopId = shop.Id, Values = filterToAdd.Values == null ? new List <Models.FilterValue>() : filterToAdd.Values.Select(v => new Models.FilterValue { Id = v.Id, Content = v.Content, CreateDateTime = v.CreateDateTime, UpdateDateTime = v.UpdateDateTime, FilterId = filterToAdd.Id }).ToList() }; _context.Filters.Add(rec); } var comments = shop.Comments == null ? new List <ShopComment>() : shop.Comments; // Update comments var commentIds = comments.Select(c => c.Id); var commentsToUpdate = record.Comments.Where(c => commentIds.Contains(c.Id)); var commentsToRemove = record.Comments.Where(c => !commentIds.Contains(c.Id)); var existingCommentIds = record.Comments.Select(c => c.Id); var commentsToAdd = comments.Where(c => !existingCommentIds.Contains(c.Id)); foreach (var commentToUpdate in commentsToUpdate) { var comment = comments.First(c => c.Id == commentToUpdate.Id); commentToUpdate.Score = comment.Score; commentToUpdate.Subject = comment.Subject; commentToUpdate.UpdateDateTime = comment.UpdateDateTime; commentToUpdate.Content = comment.Content; } foreach (var commentToRemove in commentsToRemove) { _context.Comments.Remove(commentToRemove); } foreach (var commentToAdd in commentsToAdd) { var rec = new Models.Comment { Id = commentToAdd.Id, Content = commentToAdd.Content, Score = commentToAdd.Score, CreateDateTime = commentToAdd.CreateDateTime, ShopId = shop.Id, UpdateDateTime = commentToAdd.UpdateDateTime, Subject = commentToAdd.Subject }; _context.Comments.Add(rec); } var gameEntities = shop.ShopGameEntities == null ? new List <ShopAggregateGameEntity>() : shop.ShopGameEntities; // Update game entities. var gameEntitiesId = gameEntities.Select(c => c.Id); var gameEntitiesToUpdate = record.ShopGameEntities.Where(c => gameEntitiesId.Contains(c.Id)); var gameEntitiesToRemove = record.ShopGameEntities.Where(c => !gameEntitiesId.Contains(c.Id)); var existingGameEntitiesId = record.ShopGameEntities.Select(c => c.Id); var gameEntitiesToAdd = gameEntities.Where(c => !existingGameEntitiesId.Contains(c.Id)); foreach (var gameEntityToUpdate in gameEntitiesToUpdate) { var gameEntity = gameEntities.First(c => c.Id == gameEntityToUpdate.Id); gameEntityToUpdate.Col = gameEntity.Col; gameEntityToUpdate.Row = gameEntity.Row; gameEntityToUpdate.GameEntityId = gameEntity.Name; gameEntityToUpdate.ProductCategoryId = gameEntity.ProductCategoryId; gameEntityToUpdate.IsFlipped = gameEntity.IsFlipped; } foreach (var gameEntityToRemove in gameEntitiesToRemove) { _context.ShopGameEntities.Remove(gameEntityToRemove); } foreach (var gameEntityToAdd in gameEntitiesToAdd) { var rec = new Models.ShopGameEntity { Id = gameEntityToAdd.Id, Col = gameEntityToAdd.Col, Row = gameEntityToAdd.Row, GameEntityId = gameEntityToAdd.Name, ProductCategoryId = gameEntityToAdd.ProductCategoryId, ShopId = shop.Id, IsFlipped = gameEntityToAdd.IsFlipped }; _context.ShopGameEntities.Add(rec); } await _context.SaveChangesAsync().ConfigureAwait(false); transaction.Commit(); return(true); } catch (Exception ex) { transaction.Rollback(); return(false); } } }
/// <summary> /// GroupIds. /// </summary> /// <param name="groupIds"> groupIds. </param> /// <returns> Builder. </returns> public Builder GroupIds(Models.FilterValue groupIds) { this.groupIds = groupIds; return(this); }
public Builder TeamMemberIdFilter(Models.FilterValue teamMemberIdFilter) { this.teamMemberIdFilter = teamMemberIdFilter; return this; }
public Builder GroupIds(Models.FilterValue value) { groupIds = value; return(this); }