Пример #1
0
        // GET: PaymentMade/Create
        public ActionResult Create()
        {
            var categoryService   = CreateCategoryService();
            var categoryNames     = categoryService.GetCategoryNames();
            var paymentMadeCreate = new PaymentMadeCreate()
            {
                CategoryEntityNames = categoryNames
            };

            return(View(paymentMadeCreate));
        }
Пример #2
0
 public bool CreatePaymentMade(PaymentMadeCreate model)
 {
     using (var context = new ApplicationDbContext())
     {
         var paymentMadeEntity = new PaymentMade()
         {
             CategoryId  = context.Categories.SingleOrDefault(c => c.Name == model.CategoryName && c.UserId == _userId).Id,
             MonthId     = context.Months.SingleOrDefault(m => m.BeginDate.Month == DateTime.Now.Month && m.BeginDate.Year == DateTime.Now.Year && m.UserId == _userId).Id,
             Amount      = model.Amount,
             PaymentDate = DateTime.Now,
             UserId      = _userId
         };
         context.PaymentsMade.Add(paymentMadeEntity);
         return(context.SaveChanges() == 1);
     }
 }
Пример #3
0
        public ActionResult Create(PaymentMadeCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreatePaymentMadeService();

            if (service.CreatePaymentMade(model))
            {
                TempData["SaveResult"] = "Your payment was created.";
                return(RedirectToAction("CurrentBudget", "Month"));
            }

            ModelState.AddModelError("", "Payment could not be created.");
            return(View(model));
        }