Exemple #1
0
 public void DeleteArticle(Offer offerToDelete)
 {
     if (offerToDelete == null)
     {
         throw new ArgumentNullException("offerToDelete");
     }
     offerRepository.Remove(offerToDelete);
 }
        private void BindControls(Offer offer)
        {
            if (offer != null)
            {
                lblHeader.Text = offer.Header;
                lblPrice.Text = NumberFormatter.Format(offer.Price);
                lblText.Text = offer.TextBody;
                imgOffer.ImageUrl = offer.ImageUrl.FormatForHtml(Page.GetHost());

                offerInformation.Bind(offer);
            }
        }
        public void Add(Offer @object)
        {
            if (@object == null)
            {
                // ReSharper disable NotResolvedInText
                throw new ArgumentNullException("offer");
                // ReSharper restore NotResolvedInText
            }

            @object.Id = 0;

            Update(@object);
        }
Exemple #4
0
 public OfferType GetOfferType(Offer offer)
 {
     if (offer == null)
     {
         throw new ArgumentNullException("offer");
     }
     if ((int)offer.OfferType > 0)
     {
         var offerType = offerTypeRepository.Read((int)offer.OfferType);
         return offerType;
     }
     return null;
 }
        public void Remove(Offer @object)
        {
            var offer = DataContext.tbOffers.SingleOrDefault(art => art.id == @object.Id);
            if (offer == null)
            {
                return;
            }
            var coreArticle = DataContext.tbCoreArticleDatas.SingleOrDefault(i => i.id == offer.coreArticleDataId);
            if (coreArticle != null)
            {
                DataContext.tbCoreArticleDatas.DeleteOnSubmit(coreArticle);
            }
            DataContext.tbOffers.DeleteOnSubmit(offer);

            DataContext.SubmitChanges();
        }
Exemple #6
0
        public static void Copy(Offer from, Offer to)
        {
            if (from == null)
            {
                throw new ArgumentNullException("from");
            }
            if (to == null)
            {
                throw new ArgumentNullException("to");
            }

            to.OfferType = from.OfferType;
            to.Header = from.Header;
            to.TextBody = from.TextBody;
            to.Price = from.Price;
        }
        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);
                }
            }
        }
        private Offer FillOfferOrCreate(int id)
        {
            int offerTypeId;
            if (!int.TryParse(ddlOfferType.SelectedValue, out offerTypeId))
            {
                throw new PageException("Неправильный id типа акции");
            }

            double price;
            if (!double.TryParse(txtPrice.Text, out price))
            {
                throw new PageException("Введите число для цены");
            }
            if (id == 0)
            {
                var currentOffer = new Offer
                {
                    Id = id,
                    OfferType = (OfferTypes)offerTypeId,
                    Header = txtHeader.Text,
                    TextBody = txtText.Text,
                    Price = price,
                    ImageUrl = RelativeImagePath
                };
                return currentOffer;
            }
            return ReadOffer(id);
        }
 private bool IsImageVisible(Offer offer)
 {
     return !string.IsNullOrEmpty(offer.ImageUrl);
 }