public ActionResult DeleteConfirmed(Guid id)
        {
            StepDiscountDetail stepDiscountDetail = db.StepDiscountDetails.Find(id);

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

            db.SaveChanges();
            return(RedirectToAction("Index", new { id = id }));
        }
        // GET: StepDiscountDetails/Delete/5
        public ActionResult Delete(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            StepDiscountDetail stepDiscountDetail = db.StepDiscountDetails.Find(id);

            if (stepDiscountDetail == null)
            {
                return(HttpNotFound());
            }
            return(View(stepDiscountDetail));
        }
        public ActionResult Edit(StepDiscountDetail stepDiscountDetail)
        {
            if (ModelState.IsValid)
            {
                stepDiscountDetail.IsDeleted        = false;
                stepDiscountDetail.LastModifiedDate = DateTime.Now;

                db.Entry(stepDiscountDetail).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index", new { id = stepDiscountDetail.StepDiscountId }));
            }
            ViewBag.StepDiscountId = stepDiscountDetail.StepDiscountId;
            return(View(stepDiscountDetail));
        }
        public ActionResult Create(StepDiscountDetail stepDiscountDetail, Guid id)
        {
            if (ModelState.IsValid)
            {
                stepDiscountDetail.IsDeleted      = false;
                stepDiscountDetail.CreationDate   = DateTime.Now;
                stepDiscountDetail.StepDiscountId = id;
                stepDiscountDetail.Id             = Guid.NewGuid();

                db.StepDiscountDetails.Add(stepDiscountDetail);
                db.SaveChanges();
                return(RedirectToAction("Index", new { id = id }));
            }

            ViewBag.StepDiscountId = id;
            return(View(stepDiscountDetail));
        }
Ejemplo n.º 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);
        }