Ejemplo n.º 1
0
        public ActionResult AddBill(UtilityBillsModelView collection)
        {
            string      userId = User.Identity.GetUserId();
            DB_Entities db     = new DB_Entities();
            var         count  = db.Bills.Where(x => x.UserId == userId && x.Title == collection.Title && x.InstituteId == collection.InstituteId).Count();

            if (!(count > 0))
            {
                string filename = Path.GetFileNameWithoutExtension(collection.Image.FileName);
                string ext      = Path.GetExtension(collection.Image.FileName);
                filename = filename + DateTime.Now.Millisecond.ToString();
                filename = filename + ext;
                string filetodb = "/Bills/" + filename;
                filename = Path.Combine(Server.MapPath("~/Files/Bills/"), filename);
                collection.Image.SaveAs(filename);
                collection.Photo = filetodb;
                Bill ub = new Bill()
                {
                    Title       = collection.Title,
                    InstituteId = collection.InstituteId,
                    Date        = collection.Date,
                    DateAdded   = DateTime.Now,
                    Image       = collection.Photo,
                    Amount      = collection.Amount,
                    UserId      = userId
                };
                db.Bills.Add(ub);
                db.SaveChanges();
                Alerts.BillsAdded = true;
                return(RedirectToAction("ViewUtilityBills", "DashBoard"));
            }
            Alerts.Exist = true;
            return(RedirectToAction("AddBill", "DashBoard"));
        }
Ejemplo n.º 2
0
        public ActionResult ViewUtilityBills(DateViewModel date)
        {
            List <double> amountlist = new List <double>();
            DB_Entities   db         = new DB_Entities();
            string        userId     = User.Identity.GetUserId();
            var           bills      = db.Bills.Where(x => x.UserId == userId).Where(y => y.Date > date.startDate && y.Date < date.endDate).ToList <Bill>();
            List <UtilityBillsModelView> billsview = new List <UtilityBillsModelView>();

            foreach (var i in bills as List <Bill> )
            {
                UtilityBillsModelView ub = new UtilityBillsModelView()
                {
                    Id            = i.Id,
                    InstituteName = GetInstituteName(i.InstituteId),
                    Title         = i.Title,
                    Amount        = Convert.ToDouble(i.Amount),
                    Photo         = i.Image,
                    Date          = Convert.ToDateTime(i.Date)
                };
                billsview.Add(ub);
                amountlist.Add(Convert.ToDouble(i.Amount));
            }
            ViewData["totalamount"] = amountlist.Sum();
            ViewData["bills"]       = billsview;
            return(View());
        }
Ejemplo n.º 3
0
        public ActionResult ViewBill(int?id)
        {
            DB_Entities           db   = new DB_Entities();
            var                   bill = db.Bills.Where(x => x.Id == id).FirstOrDefault();
            UtilityBillsModelView Bill = new UtilityBillsModelView()
            {
                Title         = bill.Title,
                InstituteName = GetInstituteName(bill.InstituteId),
                Amount        = Convert.ToDouble(bill.Amount),
                Date          = Convert.ToDateTime(bill.Date),
                Photo         = bill.Image
            };

            ViewData["bill"] = Bill;
            return(View());
        }