Exemplo n.º 1
0
        public async Task <IActionResult> Create(CreateViewModel model)
        {
            var user = await GetCurrentUserAsync();

            if (!ModelState.IsValid)
            {
                model.ModelStateValid = false;
                return(View(model));
            }
            var course = new Course
            {
                Description      = _scriptsFilter.Filt(model.Description),
                CourseImage      = $"{_serviceLocation.CDN}/images/thumbnail.svg",
                DisplayOwnerInfo = model.DisplayOwnerInfo,
                WhatYouWillLearn = model.WhatYouWillLearn,
                Name             = model.Name,
                Price            = model.Price,
                OwnerId          = user.Id
            };

            _dbContext.Courses.Add(course);
            await _dbContext.SaveChangesAsync();

            return(RedirectToAction(nameof(Detail), new { id = course.Id }));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Follow(string id)//Target user id
        {
            var currentUser = await GetCurrentUserAsync();

            var user = await _dbContext.Users.SingleOrDefaultAsync(t => t.Id == id);

            if (user == null)
            {
                return(this.Protocol(ErrorType.NotFound, $"The target user with id:{id} was not found!"));
            }
            var follow = await _dbContext.Follows.SingleOrDefaultAsync(t => t.TriggerId == currentUser.Id && t.ReceiverId == user.Id);

            if (follow == null)
            {
                _dbContext.Follows.Add(new Follow
                {
                    TriggerId  = currentUser.Id,
                    ReceiverId = user.Id
                });
                await _dbContext.SaveChangesAsync();

                return(this.Protocol(ErrorType.Success, "You have successfully followed the target user!"));
            }
            return(this.Protocol(ErrorType.HasDoneAlready, "You have already followed the target user!"));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create(CreateViewModel model)//Course Id
        {
            var course = await _dbContext
                         .Courses
                         .SingleOrDefaultAsync(t => t.Id == model.CourseId);

            if (course == null)
            {
                return(NotFound());
            }

            var user = await GetCurrentUserAsync();

            if (course.OwnerId != user.Id)
            {
                return(NotFound());
            }
            var newSection = new Section
            {
                SectionName = model.NewSectionName,
                CourseId    = model.CourseId
            };

            _dbContext.Sections.Add(newSection);
            await _dbContext.SaveChangesAsync();

            return(RedirectToAction(nameof(CourseController.Detail), "Course", new { id = course.Id }));
        }
        public async Task <IActionResult> UnSubscribe(int id) // sub Id
        {
            var user = await GetCurrentUserAsync();

            var sub = await _dbContext.Subscriptions.SingleOrDefaultAsync(t => t.Id == id && t.UserId == user.Id);

            if (sub != null)
            {
                _dbContext.Subscriptions.Remove(sub);
                await _dbContext.SaveChangesAsync();
            }
            return(RedirectToAction(nameof(Subscriptions), new { id = user.UserName }));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Create(CreateViewModel model)
        {
            var user = await GetCurrentUserAsync();

            if (!ModelState.IsValid)
            {
                model.ModelStateValid = false;
                return(View(model));
            }
            var course = new Course
            {
                Description = model.Description,
                Name        = model.Name,
                Price       = model.Price,
                OwnerId     = user.Id
            };

            _dbContext.Courses.Add(course);
            await _dbContext.SaveChangesAsync();

            return(RedirectToAction(nameof(Detail), new { id = course.Id }));
        }
        public async Task <IActionResult> Create(CreateViewModel model)
        {
            var course = await _dbContext.Courses.SingleOrDefaultAsync(t => t.Id == model.CourseId);

            if (course == null)
            {
                return(NotFound());
            }
            _dbContext.Chapters.Add(new Chapter
            {
                Name     = model.NewChapterTitle,
                CourseId = model.CourseId
            });
            await _dbContext.SaveChangesAsync();

            return(RedirectToAction(nameof(CourseController.Detail), "Course", new { id = model.CourseId }));
        }