Пример #1
0
        public JsonResult Save(PromotionModel.PromotionSaveModel model)
        {
            Promotion promotion;
            IList <PromotionDetail> promotionDetails = JsonConvert.DeserializeObject <IList <PromotionDetail> >(model.Details);

            DateTime start = DateTimeHelper.ConvertToLongDay(model.StartDay);
            DateTime end   = DateTimeHelper.ConvertToLongDay(model.EndDay);

            if (model.id_ == 0)
            {
                promotion = new Promotion()
                {
                    Active             = model.Active,
                    Discount           = model.Discount,
                    EndDay             = end,
                    StartDay           = start,
                    IdUserOk           = 0,
                    ProductCategoryIds = model.ProductCategoryIds,
                    ProductIds         = model.ProductIds,
                    Region             = model.Region,
                    Title  = model.Title,
                    IdUser = 15
                };

                _promotionRepository.Add(promotion);
                _unitOfWork.Commit();
            }
            else
            {
                promotion                    = _promotionRepository.GetById(model.id_);
                promotion.Active             = model.Active;
                promotion.Discount           = model.Discount;
                promotion.EndDay             = end;
                promotion.StartDay           = start;
                promotion.ProductCategoryIds = model.ProductCategoryIds;
                promotion.ProductIds         = model.ProductIds;
                promotion.Region             = model.Region;
                promotion.Title              = model.Title;

                _promotionRepository.Update(promotion);
            }

            #region

            IList <PromotionDetail> oldDetails = model.id_ != 0
                                                    ? _promotionDetailRepository.GetMany(o => o.PromotionId == model.id_).ToList()
                                                    : new List <PromotionDetail>();

            foreach (var dt in promotionDetails)
            {
                if (dt.id_ == 0)
                {
                    PromotionDetail promotionDetail = new PromotionDetail()
                    {
                        Percent       = dt.Percent,
                        ProductId     = dt.ProductId,
                        PriceDiscount = dt.PriceDiscount,
                        PromotionId   = promotion.id_,
                        Price         = dt.Price
                    };
                    _promotionDetailRepository.Add(promotionDetail);
                }
                else
                {
                    PromotionDetail promotionDetail = oldDetails.FirstOrDefault(o => o.id_ == dt.id_);
                    if (promotionDetail != null)
                    {
                        promotionDetail.Percent       = dt.Percent;
                        promotionDetail.PriceDiscount = dt.PriceDiscount;
                        promotionDetail.Price         = dt.Price;
                        _promotionDetailRepository.Update(promotionDetail);
                    }
                }
            }
            #endregion

            _promotionRepository.ClearBannerCache();
            _unitOfWork.Commit();

            return(Json(new
            {
                PromotionId = promotion.id_
            }, JsonRequestBehavior.AllowGet));
        }
 public Promotion Add(Promotion promotion)
 {
     return(_promotionRepository.Add(promotion));
 }
Пример #3
0
 public void Add(Promotion promotion)
 {
     _promotionRepository.Add(promotion);
 }
Пример #4
0
 public bool Add(Promotion promo)
 {
     return(_repo.Add(promo));
 }
Пример #5
0
 public bool Add(PromotionView entity)
 {
     return(_promotion.Add(entity));
 }
Пример #6
0
 public ResultMessage <Promotion> Add(Promotion data)
 {
     data.isActive = true;
     return(_promotionRepository.Add(data));
 }