Beispiel #1
0
        public IActionResult Course(string name, CourseAction courseAction)
        {
            var course = _courses.FirstOrDefault(c => c.Name == name);

            if (course == null)
            {
                return(RedirectToRoute(new { controller = "Home", action = "Index" }));
            }
            if (CurrentUser == null)
            {
                return(View(course));
            }
            switch (courseAction)
            {
            case CourseAction.Add:
                CurrentUser.Courses.Add(name);
                break;

            case CourseAction.Remove:
                if (CurrentUser.Courses.Contains(name))
                {
                    CurrentUser.Courses.Remove(name);
                }
                break;

            case CourseAction.None:
                return(View(course));
            }

            _dbContext.Users.Update(CurrentUser.ToDto());
            _dbContext.SaveChanges();
            return(View(course));
        }
Beispiel #2
0
        public virtual async Task <CourseAction> Update(CourseAction courseAction)
        {
            if (courseAction == null)
            {
                throw new ArgumentNullException("courseAction");
            }

            await _courseActionRepository.UpdateAsync(courseAction);

            //event notification
            await _mediator.EntityUpdated(courseAction);

            return(courseAction);
        }
        public virtual async Task <CourseAction> InsertAsync(CourseAction courseAction)
        {
            if (courseAction == null)
            {
                throw new ArgumentNullException(nameof(courseAction));
            }

            await _courseActionRepository.InsertAsync(courseAction);

            //event notification
            await _mediator.EntityInserted(courseAction);

            return(courseAction);
        }