Exemple #1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (ModelState.IsValid)
            {
                if (Entry.EntryTime > DateTime.Now)
                {
                    ModelState.AddModelError("", "Entry time can't be greater than today!");
                }
                else
                {
                    if (CheckLeavingTime(Entry))
                    {
                        _context.Entries.Add(Entry);
                        await _context.SaveChangesAsync();

                        return(RedirectToPage("./Index"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Leaving time can't be less than entry time!");
                    }
                }
            }
            Cars = CarsList();
            return(Page());
        }
Exemple #2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (ModelState.IsValid)
            {
                if (Balance.Time <= DateTime.Now)
                {
                    _context.Balances.Add(Balance);
                    await _context.SaveChangesAsync();

                    return(RedirectToPage("./Index", new { id = Balance.EntryId }));
                }
                ModelState.AddModelError("", "Date and time can't be greater than today!");
            }
            return(Page());
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (ModelState.IsValid)
            {
                if (await _context.Cars.AnyAsync(x => x.PlateNumber == Car.PlateNumber))
                {
                    ModelState.AddModelError("", "This plate number is used!");
                    return(Page());
                }
                if (await _context.Cars.AnyAsync(x => x.PhoneNumber == Car.PhoneNumber))
                {
                    ModelState.AddModelError("", "This phone number is used!");
                    return(Page());
                }
                _context.Cars.Add(Car);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            return(Page());
        }