Ejemplo n.º 1
0
 public ActionResult DeleteConfirmed(int id)
 {
     if (Session["UserType"].ToString() == "Admin")
     {
         CustomerPaidMoney customerPaidMoney = db.CustomerPaidMoneys.Find(id);
         db.CustomerPaidMoneys.Remove(customerPaidMoney);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         return(RedirectToAction("../Home/LogIn"));
     }
 }
Ejemplo n.º 2
0
 public ActionResult Edit(CustomerPaidMoney customerPaidMoney)
 {
     if (Session["UserType"].ToString() == "Admin")
     {
         if (ModelState.IsValid)
         {
             db.Entry(customerPaidMoney).State = EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         ViewBag.Month      = new SelectList(db.MonthTbls, "MonthId", "Name", customerPaidMoney.Month);
         ViewBag.CustomerId = new SelectList(db.Customers, "CustomerId", "Name", customerPaidMoney.CustomerId);
         return(View(customerPaidMoney));
     }
     else
     {
         return(RedirectToAction("../Home/LogIn"));
     }
 }
Ejemplo n.º 3
0
 // GET: CustomerPaidMoneys/Details/5
 public ActionResult Details(int?id)
 {
     if (Session["UserType"].ToString() == "Customer" || Session["UserType"].ToString() == "Admin")
     {
         if (id == null)
         {
             return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
         }
         CustomerPaidMoney customerPaidMoney = db.CustomerPaidMoneys.Find(id);
         if (customerPaidMoney == null)
         {
             return(HttpNotFound());
         }
         return(View(customerPaidMoney));
     }
     else
     {
         return(RedirectToAction("../Home/LogIn"));
     }
 }
Ejemplo n.º 4
0
 // GET: CustomerPaidMoneys/Edit/5
 public ActionResult Edit(int?id)
 {
     if (Session["UserType"].ToString() == "Admin")
     {
         if (id == null)
         {
             return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
         }
         CustomerPaidMoney customerPaidMoney = db.CustomerPaidMoneys.Find(id);
         if (customerPaidMoney == null)
         {
             return(HttpNotFound());
         }
         ViewBag.Month      = new SelectList(db.MonthTbls, "MonthId", "Name", customerPaidMoney.Month);
         ViewBag.CustomerId = new SelectList(db.Customers, "CustomerId", "Name", customerPaidMoney.CustomerId);
         return(View(customerPaidMoney));
     }
     else
     {
         return(RedirectToAction("../Home/LogIn"));
     }
 }
Ejemplo n.º 5
0
        public ActionResult Create(CustomerPaidMoney customerPaidMoney)
        {
            if (Session["UserType"].ToString() == "Customer")
            {
                if (ModelState.IsValid)
                {
                    ViewBag.Month      = new SelectList(db.MonthTbls, "MonthId", "Name", customerPaidMoney.Month);
                    ViewBag.CustomerId = new SelectList(db.Customers, "CustomerId", "Name", customerPaidMoney.CustomerId);

                    CustomerConsumingMoney CCM = new CustomerConsumingMoney();
                    var customerMoneyInfoList  = db.CustomerMonthlyPaids.Where(x => x.Month == customerPaidMoney.Month && x.CustomerId == customerPaidMoney.CustomerId).FirstOrDefault();

                    if (customerMoneyInfoList.ConsumeMoney > 0)
                    {
                        var cashBack        = 0.0;
                        var consumeMoney    = 0.0;
                        var serviceCharge   = 0.0;
                        var totalNeedToPaid = 0.0;
                        var totalPaid       = 0.0;

                        consumeMoney    = (double)customerMoneyInfoList.ConsumeMoney;
                        cashBack        = (double)customerMoneyInfoList.CashBack;
                        serviceCharge   = (double)customerMoneyInfoList.ServiceCharge;
                        totalNeedToPaid = (consumeMoney + ((consumeMoney * serviceCharge) / 100)) - cashBack;

                        var paidInfo = db.CustomerPaidMoneys.Where(x => x.Month == customerPaidMoney.Month && x.CustomerId == customerPaidMoney.CustomerId).ToList();
                        totalPaid = paidInfo.Select(x => x.PaidMoney).Sum();
                        var TotalwithcurrentPaid = customerPaidMoney.PaidMoney + totalPaid;

                        if (customerMoneyInfoList.PaidStatus == "Paid")
                        {
                            ViewBag.error = "Dear Sir, you already Paid the bills";
                            return(View());
                        }
                        else
                        {
                            if (TotalwithcurrentPaid > totalNeedToPaid)
                            {
                                ViewBag.error = "Dear Sir, you already Paid +" + TotalwithcurrentPaid + " taka. Now your available bill is " + (totalNeedToPaid - TotalwithcurrentPaid) + " taka.";
                                return(View());
                            }
                            else
                            {
                                db.CustomerPaidMoneys.Add(customerPaidMoney);
                                db.SaveChanges();

                                //monthly paid table
                                customerMoneyInfoList.PaidMoney = TotalwithcurrentPaid;
                                if (TotalwithcurrentPaid == totalNeedToPaid)
                                {
                                    customerMoneyInfoList.PaidStatus = "Paid";
                                }
                                else
                                {
                                    customerMoneyInfoList.PaidStatus = "Running";
                                }
                                db.Entry(customerMoneyInfoList).State = EntityState.Modified;
                                db.SaveChanges();

                                return(RedirectToAction("Index"));
                            }
                        }
                    }
                    else
                    {
                        ViewBag.error = "Dear Sir, You have no bills";
                        return(View());
                    }
                }


                return(View(customerPaidMoney));
            }
            else
            {
                return(RedirectToAction("../Home/LogIn"));
            }
        }