예제 #1
0
        public ActionResult DeleteConfirmed(Guid id)
        {
            StepDiscount stepDiscount = db.StepDiscounts.Find(id);

            stepDiscount.IsDeleted    = true;
            stepDiscount.DeletionDate = DateTime.Now;

            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #2
0
 public ActionResult Edit([Bind(Include = "Id,Title,IsActive,CreationDate,CreateUserId,LastModifiedDate,IsDeleted,DeletionDate,DeleteUserId,Description")] StepDiscount stepDiscount)
 {
     if (ModelState.IsValid)
     {
         stepDiscount.IsDeleted       = false;
         db.Entry(stepDiscount).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(stepDiscount));
 }
예제 #3
0
        // GET: StepDiscounts/Delete/5
        public ActionResult Delete(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            StepDiscount stepDiscount = db.StepDiscounts.Find(id);

            if (stepDiscount == null)
            {
                return(HttpNotFound());
            }
            return(View(stepDiscount));
        }
예제 #4
0
        public ActionResult Create([Bind(Include = "Id,Title,IsActive,CreationDate,CreateUserId,LastModifiedDate,IsDeleted,DeletionDate,DeleteUserId,Description")] StepDiscount stepDiscount)
        {
            if (ModelState.IsValid)
            {
                stepDiscount.IsDeleted    = false;
                stepDiscount.CreationDate = DateTime.Now;
                stepDiscount.Id           = Guid.NewGuid();
                db.StepDiscounts.Add(stepDiscount);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(stepDiscount));
        }
예제 #5
0
        public decimal GetStepDiscountAmount(decimal income)
        {
            StepDiscount stepDiscount = db.StepDiscounts.FirstOrDefault(c => c.IsDeleted == false && c.IsActive);

            if (stepDiscount == null)
            {
                return(0);
            }

            List <StepDiscountDetail> stepDiscountDetails =
                db.StepDiscountDetails.Where(c => c.StepDiscountId == stepDiscount.Id).OrderBy(c => c.TargetValue).ToList();

            decimal discount             = 0;
            bool    isBiggetThanLastStep = true;

            foreach (StepDiscountDetail stepDiscountDetail in stepDiscountDetails)
            {
                if (income < stepDiscountDetail.TargetValue)
                {
                    discount             = (income * stepDiscountDetail.DiscountPercent) / 100;
                    isBiggetThanLastStep = false;
                    break;
                }
            }

            if (isBiggetThanLastStep)
            {
                StepDiscountDetail lastStep = stepDiscountDetails.LastOrDefault();

                if (lastStep != null)
                {
                    discount = (income * lastStep.DiscountPercent) / 100;
                }
            }

            return(discount);
        }