Example #1
0
        public ActionResult Create(Payee data)
        {
            if (db.GetAll().Select(e => e.Name).Contains(data.Name))
            {
                ModelState.AddModelError(nameof(data.Name), $"An entry with the Name {data.Name} exists already. Please use a diffrent Name");
            }

            if (!ModelState.IsValid)
            {
                var categorylist = new SqlDataServices <Data.Models.Category>().GetAll().OrderBy(e => e.Type).ThenBy(e => e.Name);
                ViewBag.Category = categorylist;
                return(View());
            }

            try
            {
                // TODO: Add insert logic here
                db.Add(data.ReverseMapper());

                return(RedirectToAction("Index"));
            }
            catch
            {
                ViewBag.Message = "An Error occured your entry hasn't been saved";
                return(RedirectToAction("Index"));
            }
        }
Example #2
0
        // GET: Payee/Delete/5
        public ActionResult Delete(int id)
        {
            var data  = db.Get(id);
            var model = new Payee(data);

            return(View(model));
        }
Example #3
0
        // GET: Payee/Edit/5
        public ActionResult Edit(int id)
        {
            var data         = db.Get(id);
            var model        = new Payee(data);
            var categorylist = new SqlDataServices <Data.Models.Category>().GetAll().OrderBy(e => e.Type).ThenBy(e => e.Name);

            ViewBag.Category     = categorylist;
            ViewBag.Selected     = categorylist.FirstOrDefault(e => e.ID == model.CategoryID);
            ViewBag.SelectedList = new SelectList(ViewBag.Category, "ID", "Name", ViewBag.Selected);
            return(View(model));
        }
Example #4
0
        // GET: Payee/Details/5
        public ActionResult Details(int id)
        {
            var data             = db.Get(id);
            var model            = new Payee(data);
            var transactionsData = new SqlDataServices <Data.Models.Transactions>().GetAll(id, typeof(Data.Models.Payee)).OrderBy(e => e.Date);

            foreach (var item in transactionsData)
            {
                model.Transactions.Add(new Transactions(item));
            }
            return(View(model));
        }
Example #5
0
        public ActionResult Details(int id, TimeSelector timeSelector)
        {
            var      data  = db.Get(id);
            var      model = new Payee(data);
            DateTime startDate;
            DateTime endDate;

            HelperLibary.EvaluateTimeSelector.Evaluate(timeSelector, out startDate, out endDate);
            var transactionsData = new SqlDataServices <Data.Models.Transactions>().GetAll(id, typeof(Data.Models.Category)).Where(e => e.Date > startDate && e.Date < endDate).OrderBy(e => e.Date);

            foreach (var item in transactionsData)
            {
                model.Transactions.Add(new Transactions(item));
            }
            return(View(model));
        }