public ActionResult Store() { if (Request["Code"] == "") { TempData["Error"] = "کد را وارد کنید"; return(Redirect("/Admin/DiscountCode/Create")); } if (Request["Price"] == "") { TempData["Error"] = "مبلغ را وارد کنید"; return(Redirect("/Admin/DiscountCode/Create")); } if (Request["ExpireDate"] == "") { TempData["Error"] = "تاریخ را وارد کنید"; return(Redirect("/Admin/DiscountCode/Create")); } DiscountCode d = new Models.DiscountCode(); d.Status = true; d.Code = Request["Code"]; d.Price = Convert.ToInt32(Request["Price"]); string date = Request["ExpireDate"]; string[] array = date.Split('/'); PersianCalendar p = new PersianCalendar(); d.ExpireDate = new DateTime(Convert.ToInt32(array[0]), Convert.ToInt32(array[1]), Convert.ToInt32(array[2]), p); db.DiscountCode.Add(d); db.SaveChanges(); return(Redirect("/Admin/DiscountCode/Index")); }
public decimal CalculateDiscountAmount(Models.DiscountCode discountCode, decimal totalAmount) { if (discountCode.IsPercent) { return(totalAmount * discountCode.Amount / 100); } else { return(discountCode.Amount); } }