public void Save(FreeOfChargeDiscountViewModel model, out bool isEdit)
       {
          
           FreeOfChargeDiscount discount=null;
           if(model.Id !=Guid.Empty)
               discount = _freeOfChargeDiscountRepository.GetById(model.Id);
           else
           {
               model.Id = Guid.NewGuid();
           }

           if(discount ==null)
           {
               discount = new FreeOfChargeDiscount(model.Id)
               {
                   ProductRef = new ProductRef { ProductId = model.ProductId },
                   isChecked = true,
                   EndDate = DateTime.Parse(model.EndDate),
                   StartDate = DateTime.Parse(model.StartDate)
               };
               isEdit = false;
           }
           else
           {
               discount.EndDate =DateTime.Parse(model.EndDate);
               discount.StartDate = DateTime.Parse(model.StartDate);
               discount.ProductRef=new ProductRef(){ProductId = model.ProductId};
               discount.Id = model.Id;
               isEdit = true;
           }
           _freeOfChargeDiscountRepository.Save(discount);
       }
 public FreeOfChargeDiscount CreateFreeOfChargeDiscount(ProductRef parentProduct, ProductRef freeOfChargeProduct, int parentProductQuantity, int freeOfChargeProductQuantity, DateTime effectiveDate)
 {
     if (effectiveDate > DateTime.Now)
         throw new ArgumentException("Invalid effective date, must be in the past");
     if (parentProduct.ProductId == 0)
         throw new ArgumentException("Invalid product");
     if (freeOfChargeProduct.ProductId == 0)
         throw new ArgumentException("Invalid product");
     FreeOfChargeDiscount foc = new FreeOfChargeDiscount(0)
     {
         ProductRef = new ProductRef { ProductId=parentProduct.ProductId }
     };
     foc.FreeOfChargeDiscountItems.Add(new FreeOfChargeDiscount.FreeOfChargeDiscountItem(0)
  {
      ParentProductQuantity = parentProductQuantity,
      FreeOfChargeQuantity = freeOfChargeProductQuantity,
      FreeOfChargeProduct = new ProductRef { ProductId=freeOfChargeProduct.ProductId},
       EffectiveDate=effectiveDate
  });
     return foc;
 }
 public FreeOfChargeDiscountDTO Map(FreeOfChargeDiscount focDiscount)
 {
     if (focDiscount == null) return null;
     return Mapper.Map<FreeOfChargeDiscount, FreeOfChargeDiscountDTO>(focDiscount);
 }
 private FreeOfChargeDiscountViewModel Map(FreeOfChargeDiscount item)
 {
     return new FreeOfChargeDiscountViewModel()
                {
                    Id = item.Id,
                    ProductDescription = _productRepository.GetById(item.ProductRef.ProductId).Description,
                    StartDate =  item.StartDate.ToShortDateString() ,
                    EndDate =item.EndDate.ToShortDateString(),
                    ProductId = item.ProductRef.ProductId,
                    IsActive = item._Status == EntityStatus.Active
                };
 }
        private void AssertFreeOfChargeDiscount(FreeOfChargeDiscount freeOfChargeDiscountX, FreeOfChargeDiscount freeOfChargeDiscountY)
        {

            Assert.IsNotNull(freeOfChargeDiscountX);
            Assert.AreEqual(freeOfChargeDiscountX.ProductRef.ProductId.ToString(), freeOfChargeDiscountY.ProductRef.ProductId.ToString());
            //Assert.AreEqual(freeOfChargeDiscountX.StartDate, freeOfChargeDiscountY.StartDate);
            Assert.AreEqual(freeOfChargeDiscountX._Status, freeOfChargeDiscountY._Status);
                
        }
Esempio n. 6
0
 protected Guid AddFreeOfChargeDiscountDiscount(ProductRef product, DateTime startDate, DateTime endDate)
 {
     var svd = new FreeOfChargeDiscount(Guid.NewGuid())
                                    {
                                        isChecked=true,
                                        StartDate = startDate,
                                        EndDate = endDate,
                                        ProductRef=product,
                                    };
     svd._SetStatus(EntityStatus.Active);
     return _freeOfChargeDiscountRepository.Save(svd);
 }