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


C# IRepository.Remove方法代码示例

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


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

示例1: GetChangeTracker

		protected virtual ObservableChangeTracker GetChangeTracker(IRepository repository)
		{
			var retVal = new ObservableChangeTracker
			{
                RemoveAction = x => repository.Remove(x),
                AddAction = x => repository.Add(x)
			};

			return retVal;
		}
开发者ID:adwardliu,项目名称:vc-community,代码行数:10,代码来源:ServiceBase.cs

示例2: Import


//.........这里部分代码省略.........
							var catNames = string.Empty;
							sourceItems.ForEach(x => catNames = catNames + x.CatalogId + ", ");
							_error = string.Format(notUniqueSourceError, source, catNames);
							return _error;
						}
					}
					//aa: if 1 item found set it to sourceItem and go further
					else
					{
						sourceItem = sourceItems.FirstOrDefault();
					}

					var targetItems = _repository.Items.Where(x => x.ItemId == target || x.Code == target).ToList();
					
					Item targetItem;

					//aa: below condition checks if more than 1 item found - catalogId should be provided and item of the catalog selected, otherwise return error
					if (targetItems.Count() > 1)
					{
						var targetCatName = systemValues.First(y => y.Name == "TargetCatalogId").Value;
						if (!string.IsNullOrEmpty(targetCatName))
							catalogId = _repository.Catalogs.Where(cat => cat.Name == targetCatName).First().CatalogId;

						if (!string.IsNullOrEmpty(catalogId))
							targetItem = targetItems.FirstOrDefault(x => x.CatalogId == catalogId);
						else
						{
							var catNames = string.Empty;
							targetItems.ForEach(x => catNames = catNames + x.CatalogId + ", ");
							_error = string.Format(notUniqueTargetError, target, catNames);
							return _error;
						}
					}
					//aa: if 1 item found set it to sourceItem and go further
					else
					{
						targetItem = targetItems.FirstOrDefault();
					}
					
					if (!string.IsNullOrEmpty(group) && targetItem != null && sourceItem != null)
					{
						var associationGroup = _repository.Associations.Where(x => x.AssociationGroup.Name == group && x.ItemId == targetItem.ItemId).SingleOrDefault();
						string groupId;
						if (associationGroup == null)
						{
							var addGroup = new AssociationGroup() { ItemId = targetItem.ItemId, Name = group };
							_repository.Add(addGroup);
							groupId = addGroup.AssociationGroupId;
						}
						else
						{
							groupId = associationGroup.AssociationGroupId;
						}

						var addItem = InitializeItem(null, systemValues);
						((Association)addItem).AssociationGroupId = groupId;
						((Association)addItem).ItemId = sourceItem.ItemId;
						
						_repository.Add(addItem);
					}
					else
					{
						_error = "Not all required data provided";
					}
					break;
				case ImportAction.InsertAndReplace:
					var itemR = systemValues.FirstOrDefault(y => y.Name == "AssociationId");
					if (itemR != null)
					{
						var originalItem = _repository.Associations.Where(x => x.ItemId == itemR.Value).SingleOrDefault();
						if (originalItem != null)
							repository.Remove(originalItem);
					}
					var replaceItem = InitializeItem(null, systemValues);
					repository.Add(replaceItem);
					break;
				case ImportAction.Update:
					var itemU = systemValues.FirstOrDefault(y => y.Name == "AssociationId");
					if (itemU != null)
					{
						var origItem = _repository.Associations.Where(x => x.ItemId == itemU.Value).SingleOrDefault();
						if (origItem != null)
						{
							InitializeItem(origItem, systemValues);
							_repository.Update(origItem);
						}
					}
					break;
				case ImportAction.Delete:
					var itemD = systemValues.FirstOrDefault(y => y.Name == "AssociationId");
					if (itemD != null)
					{
						var deleteItem = _repository.Associations.Where(x => x.ItemId == itemD.Value).SingleOrDefault();
						if (deleteItem != null)
							_repository.Remove(deleteItem);
					}
					break;
			}
			return _error;
		}
开发者ID:gitter-badger,项目名称:vc-community-1.x,代码行数:101,代码来源:AssociationImporter.cs

示例3: GetChangeTracker

		private ObservableChangeTracker GetChangeTracker(IRepository repository, CustomerOrderEntity customerOrderEntity)
		{
			var retVal = new ObservableChangeTracker
			{
				RemoveAction = (x) =>
				{
					repository.Remove(x);
				},
				AddAction = (x) =>
				{
					var address = x as AddressEntity;
					var shipment = x as ShipmentEntity;
					var lineItem = x as LineItemEntity;

					if (address != null)
					{
						address.CustomerOrder = customerOrderEntity;
					}
					if (shipment != null)
					{
						foreach (var shipmentItem in shipment.Items)
						{
							var orderLineItem = customerOrderEntity.Items.FirstOrDefault(item => item.Id == shipmentItem.Id);
							if (orderLineItem != null)
							{
								orderLineItem.Shipment = shipment;
							}
							else
							{
								shipmentItem.CustomerOrder = customerOrderEntity;
							}
						}
						shipment.Items = new NullCollection<LineItemEntity>();
					}
					if (lineItem != null)
					{
						lineItem.CustomerOrder = customerOrderEntity;
						lineItem.CustomerOrderId = customerOrderEntity.Id;
					}
					repository.Add(x);
				}
			};

			return retVal;
		}
开发者ID:alt-soft,项目名称:vc-community,代码行数:45,代码来源:CustomerOrderServiceImpl.cs

示例4: CountryModule

        // TODO: let's do content negotiation ourselves unless there is a nice
        // way to do it in Nancy like there seems to be for most things
        public CountryModule(IRepository<Domain.Country> countryRepository, CountryFactory countryFactory)
            : base("/countries")
        {
            Get["/"] = parameters =>
                {
                    var countryResources = countryRepository.FindAll()
                        .Select(c => new Country {id = c.Id.ToString(), Name = c.Name});

                    var resource = countryResources.ToArray();

                    return Response.AsJson(resource);
                };

            Get["/{id}"] = parameters =>
                {
                    var country = countryRepository.GetById((int)parameters.id);
                    if (country == null)
                        return HttpStatusCode.NotFound;

                    var resource = new Country {id = country.Id.ToString(), Name = country.Name};

                    return Response.AsJson(resource);
                };

            Post["/"] = parameters =>
                {
                    var countryResource = this.Bind<Country>(blacklistedProperties:"id");

                    var validationResult = this.Validate(countryResource);
                    if (! validationResult.IsValid)
                    {
                        var response = Response.AsJson(validationResult.Errors);
                        response.StatusCode = HttpStatusCode.BadRequest;
                        return response;
                    }

                    var country = countryFactory.CreateCountry(countryResource.Name);
                    countryRepository.Add(country);

                    return Response.AsRedirect("/countries/"+country.Id);
                };

            Put["/{id}"] = parameters =>
                {
                    var country = countryRepository.GetById((int) parameters.id);
                    if (country == null)
                        return HttpStatusCode.NotFound; // this correct for a put? should probably be some error

                    // we don't actually support updates to countries!
                    //country.Name = parameters.Name;

                    return Response.AsRedirect("/countries/" + country.Id);
                };

            Delete["/{id}"] = parameters =>
                {
                    var country = countryRepository.GetById((int)parameters.id);
                    if (country == null)
                        return HttpStatusCode.NotFound; // this correct for a put? should probably be some error

                    countryRepository.Remove(country);

                    return HttpStatusCode.OK;
                };
        }
开发者ID:christensena,项目名称:DDDIntro,代码行数:67,代码来源:CountryModule.cs


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