Пример #1
0
        public Item Add(Item Item)
        {
            var item = _ItemRepository.Add(Item);

            _unitOfWork.Commit();
            if (!string.IsNullOrEmpty(Item.Tags))
            {
                string[] tags = Item.Tags.Split(',');
                for (var i = 0; i < tags.Length; i++)
                {
                    var tagId = StringHelper.ToUnsignString(tags[i]);
                    if (_tagRepository.Count(x => x.ID == tagId) == 0)
                    {
                        Tag tag = new Tag();
                        tag.ID   = tagId;
                        tag.Name = tags[i];
                        tag.Type = CommonConstants.ProductTag;
                        _tagRepository.Add(tag);
                    }

                    ProductTag productTag = new ProductTag();
                    productTag.ProductID = Item.ID;
                    productTag.TagID     = tagId;
                    _ItemTagRepository.Add(productTag);
                }
            }
            return(Item);
        }
Пример #2
0
 public Order Post([FromServices] ICustomerRepository customerRepository,
                   [FromServices] IOrderRepository orderRepository,
                   [FromServices] IUniOfWork unityOfWork)
 {
     try
     {
         var customer = new Customer {
             Name = "Fernando Henrique Leme"
         };
         var order = new Order {
             Number = "123", Customer = customer
         };
         customerRepository.Save(customer);
         orderRepository.Save(order);
         unityOfWork.Commit();
         return(order);
     }
     catch
     {
         unityOfWork.Rollback();
         return(null);
     }
 }
Пример #3
0
 public void Save()
 {
     _unitOfWork.Commit();
 }
Пример #4
0
 public void SaveChanges()
 {
     _unitOfWork.Commit();
 }