예제 #1
0
        public async Task <IActionResult> Create([Bind("Cost,Description,CategoryId,Date,Warranty,ApplicationUserId,PaymentTypeId,Tag,Earnings,Id")] Record recordIM)
        {
            if (recordIM == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid ||
                (ModelState.ErrorCount == 1 &&
                 ModelState.GetValidationState(nameof(Record.ApplicationUserId)) == Microsoft.AspNetCore.Mvc.ModelBinding.ModelValidationState.Invalid)
                )
            {
                var user = await userManager.GetUserAsync(User);

                recordIM.ApplicationUser = user;

                await dataLayer.AddAsync(recordIM);

                return(RedirectToAction(nameof(Index)));
            }
            //ViewData["ApplicationUserId"] = new SelectList(_context.Users, "Id", $"{nameof(ApplicationUser.UserName)}");

            ViewData["CategoryId"]    = new SelectList(dataLayer.GetUserCategories(ApplicationUser), "Id", $"{nameof(Category.Description)}", recordIM.Category);
            ViewData["PaymentTypeId"] = new SelectList(dataLayer.GetUserPaymentTypes(ApplicationUser), "Id", $"{nameof(PaymentType.Description)}");
            ViewBag.Date     = DateTime.Now;
            ViewBag.Warranty = 0;

            return(View(recordIM));
        }
예제 #2
0
        //public async Task<IActionResult> Create([Bind("Description,CategoryId,PaymentTypeId,ApplicationUserId,Cost,IntervalId,Earnings,Warranty,Tag,DateCreated,LastUpdate,IsActive,EndDate,Id")] RecurringPayment recurringPayment)
        public async Task <IActionResult> Create([Bind("Description,CategoryId,PaymentTypeId,Cost,IntervalId,Earnings,Warranty,Tag,IsActive,StartDate,EndDate")] RecurringPaymentViewModel recurringPaymentVM)
        {
            var categories   = dataLayer.GetUserCategories(ApplicationUser).OrderByDescending(c => c.IsDefault);
            var intervals    = dataLayer.GetIntervals().OrderByDescending(c => c.IsDefault);
            var paymentTypes = dataLayer.GetUserPaymentTypes(ApplicationUser).OrderByDescending(c => c.IsDefault);

            if (ModelState.IsValid)
            {
                var recurringPayment = new RecurringPayment();
                VmToModel(recurringPaymentVM, recurringPayment, intervals.ToList());

                await dataLayer.AddAsync(recurringPayment);

                return(RedirectToAction(nameof(Index)));
            }

            ViewBag.CategoryId    = new SelectList(categories, $"{nameof(Category.Id)}", $"{nameof(Category.Description)}", recurringPaymentVM.CategoryId);
            ViewBag.IntervalId    = new SelectList(intervals, $"{nameof(Interval.Id)}", $"{nameof(Interval.Description)}", recurringPaymentVM.IntervalId);
            ViewBag.PaymentTypeId = new SelectList(paymentTypes, $"{nameof(PaymentType.Id)}", $"{nameof(PaymentType.Description)}", recurringPaymentVM.PaymentTypeId);

            return(View(recurringPaymentVM));
        }