public async Task <IActionResult> Create(LessonHourCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                LessonHour hour = new LessonHour()
                {
                    Name         = model.Name,
                    BeginHour    = (byte)model.BeginTime.Hour,
                    BeginMinute  = (byte)model.BeginTime.Minute,
                    EndHour      = (byte)model.EndTime.Hour,
                    EndMinute    = (byte)model.EndTime.Minute,
                    Monday       = model.Monday,
                    Friday       = model.Friday,
                    Saturday     = model.Saturday,
                    Sunday       = model.Sunday,
                    Thursday     = model.Thursday,
                    Tuesday      = model.Tuesday,
                    Wednesday    = model.Wednesday,
                    CreationDate = DateTime.Now
                };

                if (await _dbContext.LessonHours.AddAsync(hour) != null)
                {
                    if (await _dbContext.SaveChangesAsync() > 0)
                    {
                        return(RedirectToAction("Index", "LessonHours"));
                    }
                }
            }
            else
            {
                ModelState.AddModelError("", "Model is invalid...");
            }
            return(RedirectToAction("Index", "LessonHours"));
        }
Пример #2
0
        public void Remove(Guid id)
        {
            LessonHour lessonHour = GetById(id);

            lessonHour.Status = DAL.Entity.Enum.Status.Deleted;
            Update(lessonHour);
        }
Пример #3
0
        // GET: LessonHour/Edit/5
        public ActionResult Edit(Guid id)
        {
            LessonHour hour = lessonHourService.GetById(id);

            ViewBag.MainHour = lessonHourService.GetActiveHour().Select(x => new SelectListItem()
            {
                Text = x.LesHour, Value = x.ID.ToString()
            });
            return(View(hour));
        }
Пример #4
0
 public ActionResult Delete(LessonHour hour)
 {
     try
     {
         lessonHourService.Remove(hour.ID);
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View());
     }
 }
Пример #5
0
 public ActionResult Edit(LessonHour model)
 {
     if (ModelState.IsValid)
     {
         lessonHourService.Update(model);
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View());
     }
 }
        public async Task <IActionResult> Update([FromForm] LessonHourModel model)
        {
            try
            {
                if (this.ValidRoleForAction(_context, _auth, new string[] { "Admin" }))
                {
                    bool saved;
                    if (ModelState.IsValid)
                    {
                        LessonHour item = await _context.GetByIdAsync <LessonHour>(x => x.Id == model.Id);

                        item.Name        = model.Name;
                        item.Wednesday   = model.Wednesday;
                        item.Monday      = model.Monday;
                        item.Saturday    = model.Saturday;
                        item.Sunday      = model.Sunday;
                        item.Thursday    = model.Thursday;
                        item.Tuesday     = model.Tuesday;
                        item.Friday      = model.Friday;
                        item.BeginMinute = model.BeginMinute;
                        item.BeginHour   = model.BeginHour;
                        item.EndHour     = model.EndHour;
                        item.EndMinute   = model.EndMinute;

                        _context.Update(item);
                        saved = await _context.SaveAll();

                        if (saved == true)
                        {
                            return(Ok(item));
                        }
                        else
                        {
                            return(BadRequest("Item cannot be updated"));
                        }
                    }
                    return(BadRequest("Model is not valid"));
                }
                return(Forbid());
            }
            catch (Exception ex)
            {
                var arguments = this.GetBaseData(_context, _auth);
                _logger.LogException(ex, arguments.Email, arguments.Path);
                return(BadRequest($"{ex.GetType().Name} was thrown."));
            }
        }
        public async Task <IActionResult> Add([FromForm] LessonHourModel model)
        {
            try
            {
                if (this.ValidRoleForAction(_context, _auth, new string[] { "Admin" }))
                {
                    bool saved;
                    if (ModelState.IsValid)
                    {
                        LessonHour item = new LessonHour
                        {
                            Name        = model.Name,
                            BeginHour   = model.BeginHour,
                            BeginMinute = model.BeginMinute,
                            EndHour     = model.EndHour,
                            EndMinute   = model.EndMinute,
                            Friday      = model.Friday,
                            Monday      = model.Monday,
                            Saturday    = model.Saturday,
                            Sunday      = model.Sunday,
                            Thursday    = model.Thursday,
                            Tuesday     = model.Tuesday,
                            Wednesday   = model.Wednesday
                        };

                        await _context.Add(item);

                        saved = await _context.SaveAll();

                        if (saved == true)
                        {
                            return(Ok(item));
                        }
                    }
                    return(BadRequest("Model is not valid"));
                }
                return(Forbid());
            }
            catch (Exception ex)
            {
                var arguments = this.GetBaseData(_context, _auth);
                _logger.LogException(ex, arguments.Email, arguments.Path);
                return(BadRequest($"{ex.GetType().Name} was thrown."));
            }
        }
        public async Task <IActionResult> Delete([FromForm] int id)
        {
            try
            {
                if (this.ValidRoleForAction(_context, _auth, new string[] { "Admin" }))
                {
                    LessonHour item = await _context.GetByIdAsync <LessonHour>(x => x.Id == id);

                    if (item != null)
                    {
                        _context.Delete(item);
                        bool result = await _context.SaveAll();

                        if (result == true)
                        {
                            return(Ok(item));
                        }
                        else
                        {
                            return(BadRequest("Model cannot be  deleted"));
                        }
                    }
                    else
                    {
                        return(NotFound("Model not found"));
                    }
                }
                return(Forbid());
            }
            catch (Exception ex)
            {
                var arguments = this.GetBaseData(_context, _auth);
                _logger.LogException(ex, arguments.Email, arguments.Path);
                return(BadRequest($"{ex.GetType().Name} was thrown."));
            }
        }
Пример #9
0
 public void Update(LessonHour lessonHour)
 {
     context.Entry(lessonHour).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
     context.SaveChanges();
 }
Пример #10
0
 public void Add(LessonHour lessonHour)
 {
     context.LessonHours.Add(lessonHour);
     context.SaveChanges();
 }