public async Task <IActionResult> DeleteRecord([FromHeader] int id)
        {
            var record = await _context.Records.FirstOrDefaultAsync(r => r.ID == id);

            if (record == null)
            {
                return(BadRequest());
            }

            _context.Records.Remove(record);
            await _context.SaveChangesAsync();

            return(Ok());
        }
Esempio n. 2
0
        public async Task <IActionResult> OnPostAddRecordAsync(string title, string year, string month, string day)
        {
            if (!ModelState.IsValid)
            {
                if (title == null || year == null || month == null || day == null)
                {
                    return(RedirectToPage("OnlineRecords"));
                }

                if (!CheckAll(title, year, month, day))
                {
                    return(RedirectToPage("OnlineRecords"));
                }

                if (IfTimeIsIndicated())
                {
                    ViewData["ErrorTime"] = "Время не указано";
                }

                WorkDay = new WorkDay(_context.Records.ToList(), DateTime);

                return(Page());
            }

            if (IfTimeIsIndicated())
            {
                ViewData["ErrorTime"] = "Время не указано";

                WorkDay = new WorkDay(_context.Records.ToList(), DateTime);

                return(Page());
            }

            Record.IsFree    = false;
            Record.ServiceID = Service.Id;

            _context.Records.Add(Record);
            await _context.SaveChangesAsync();

            return(RedirectToPage("OnlineRecords"));
        }