예제 #1
0
 public static void FillDbObject(this Offer from, tbOffer to)
 {
     to.id = from.Id;
      if (to.tbCoreArticleData == null)
      {
          to.tbCoreArticleData = new tbCoreArticleData();
      }
      to.tbCoreArticleData.categoryId = (int)from.Category;
      to.tbCoreArticleData.header = from.Header;
      to.tbCoreArticleData.text = from.TextBody;
      to.tbCoreArticleData.imageUrl = from.ImageUrl;
      to.tbCoreArticleData.publishDate = from.PublishDate;
      to.typeId = (int)from.OfferType;
      to.price = from.Price;
 }
예제 #2
0
        public void Update(Offer @object)
        {
            if (@object == null)
            {
                // ReSharper disable NotResolvedInText
                throw new ArgumentNullException("offer");
                // ReSharper restore NotResolvedInText
            }

            if (@object.Id == 0)
            {
                @object.PublishDate = DateTime.Now;

                var check = @object.Validate();
                if (!string.IsNullOrEmpty(check))
                {
                    throw new DomainException(check);
                }

                var offerDb = new tbOffer();
                @object.FillDbObject(offerDb);

                DataContext.tbCoreArticleDatas.InsertOnSubmit(offerDb.tbCoreArticleData);
                DataContext.tbOffers.InsertOnSubmit(offerDb);
                DataContext.SubmitChanges();

                @object.Id = offerDb.id;
            }
            else if (@object.Id > 0)
            {
                var offerDb = DataContext.tbOffers.SingleOrDefault(l => l.id == @object.Id);
                if (offerDb != null)
                {
                    @object.FillDbObject(offerDb);
                    DataContext.SubmitChanges();
                }
                else
                {
                    throw new DomainException("Нельзя удалить статью с id = " + @object.Id);
                }
            }
        }