Пример #1
0
 public ActionResult Create()
 {
     var statuses = _ctx.TransactionStatuses;
     var cat = _ctx.TransactionCategories;
     var model = new CreateTransactionModel(cat.ToList(), statuses.ToList());
     return View(model);
 }
Пример #2
0
 public ActionResult Delete(CreateTransactionModel  model)
 {
     if (ModelState.IsValid)
     {
         var item =_ctx.Transactions.First(x => x.Id == model.Id);
         _ctx.Transactions.Remove(item);
         _ctx.SaveChanges();
         return RedirectToAction("Index","Home");
     }
     return View(model);
 }
Пример #3
0
 public ActionResult Create(CreateTransactionModel model)
 {
     var user = _ctx.Users.First(x => x.Email == User.Identity.Name);
     var cat = _ctx.TransactionCategories.First(x => x.Id == model.CategoriesId);
     var stat = _ctx.TransactionStatuses.First(x => x.Id == model.StatusesId);
     if (ModelState.IsValid)
     {
         var trans = new Transaction()
         {
             Amount = model.Amount,
             Created = model.Created,
             Owner = user,
             Category = cat,
             Status = stat
         };
         _ctx.Transactions.AddOrUpdate(trans);
         _ctx.SaveChanges();
         return RedirectToAction("Index", "Home");
     }
     return View(model);
 }
Пример #4
0
        public ActionResult Edit(string id)
        {
            var gid = Guid.Parse(id);
            var statuses = _ctx.TransactionStatuses;
            var cat = _ctx.TransactionCategories;
            var model = _ctx.Transactions.First(x => x.Id == gid);

            var edmod = new CreateTransactionModel(cat.ToList(), statuses.ToList())
            {
                Created = model.Created,
                CategoriesId = model.Category.Id,
                StatusesId = model.Status.Id,
                Amount = model.Amount,
                Id = model.Id,
                Description = model.Description
            };
            return View(edmod);
        }
Пример #5
0
 public ActionResult Delete(string id)
 {
     var gid = Guid.Parse(id);
     var user = _ctx.Users.First(x => x.Email == User.Identity.Name);
     var statuses = _ctx.TransactionStatuses;
     var cat = _ctx.TransactionCategories;
     var model = _ctx.Transactions.First(x => x.Id == gid);
     var edmod = new CreateTransactionModel(cat.ToList(), statuses.ToList())
     {
         Created = model.Created,
         CategoriesId = model.Category.Id,
         StatusesId = model.Status.Id,
         Amount = model.Amount
     };
     return View(edmod);
 }
Пример #6
0
        public ActionResult Edit(CreateTransactionModel model)
        {
            var user = _ctx.Users.First(x => x.Email == User.Identity.Name);
            var cat = _ctx.TransactionCategories.First(x => x.Id == model.CategoriesId);
            var stat = _ctx.TransactionStatuses.First(x => x.Id == model.StatusesId);
            if (ModelState.IsValid)
            {
                var transaction = _ctx.Transactions.First(x => x.Id == model.Id);

                transaction.Amount = model.Amount;
                transaction.Created = model.Created;
                transaction.Owner = user;
                transaction.Category = cat;
                transaction.Status = stat;
                transaction.Id = model.Id;
                transaction.Description = model.Description;

                _ctx.Transactions.AddOrUpdate(transaction);
                _ctx.SaveChanges();
                return RedirectToAction("Index", "Home");
            }
            return View(model);
        }