Пример #1
0
        public async Task <IActionResult> Post([FromBody] Video model)
        {
            // Check if user should be allowed access.
            string     userEmail  = User.GetEmail() ?? Constants.DefaultUserEmail;
            UserAccess userAccess = _progenyDbContext.UserAccessDb.SingleOrDefault(u =>
                                                                                   u.ProgenyId == model.ProgenyId && u.UserId.ToUpper() == userEmail.ToUpper());

            if (userAccess == null || userAccess.AccessLevel > 0)
            {
                return(Unauthorized());
            }

            Video vid = await _context.VideoDb.SingleOrDefaultAsync(v =>
                                                                    v.VideoLink == model.VideoLink && v.ProgenyId == model.ProgenyId);

            if (vid == null)
            {
                CommentThread commentThread = new CommentThread();
                await _context.CommentThreadsDb.AddAsync(commentThread);

                await _context.SaveChangesAsync();

                model.CommentThreadNumber = commentThread.Id;

                await _context.VideoDb.AddAsync(model);

                await _context.SaveChangesAsync();

                await _dataService.SetVideo(model.VideoId);

                Progeny prog = await _dataService.GetProgeny(model.ProgenyId);

                UserInfo userinfo = await _dataService.GetUserInfoByEmail(User.GetEmail());

                string       title   = "New Video added for " + prog.NickName;
                string       message = userinfo.FirstName + " " + userinfo.MiddleName + " " + userinfo.LastName + " added a new video for " + prog.NickName;
                TimeLineItem tItem   = new TimeLineItem();
                tItem.ProgenyId   = model.ProgenyId;
                tItem.ItemId      = model.VideoId.ToString();
                tItem.ItemType    = (int)KinaUnaTypes.TimeLineType.Video;
                tItem.AccessLevel = model.AccessLevel;
                await _azureNotifications.ProgenyUpdateNotification(title, message, tItem, userinfo.ProfilePicture);

                return(Ok(model));
            }

            model = vid;

            return(Ok(model));
        }
Пример #2
0
        public async Task MapPerson(int showId)
        {
            try
            {
                var casts = await MazeHelper.GetCasts(showId);

                using (var db = new MediaDbContext())
                {
                    foreach (var cast in casts)
                    {
                        if (await db.Persons.FindAsync(cast.Person.Id) == null)
                        {
                            await db.AddAsync(cast.Person);

                            await db.SaveChangesAsync();
                        }
                        await MapShowPerson(showId, cast.Person.Id);
                    }
                }
            }
            catch (Exception ex)
            {
                var message = ex.Message;
            }
        }
Пример #3
0
        public async Task MapShow()
        {
            try
            {
                var shows = await MazeHelper.GetShows();

                using (var db = new MediaDbContext())
                {
                    foreach (var show in shows)
                    {
                        if (db.Shows.Find(show.Id) == null)
                        {
                            await db.AddAsync(show);

                            await db.SaveChangesAsync();
                        }
                        await MapPerson(show.Id);
                    }
                }
            }
            catch (Exception ex)
            {
                var message = ex.Message;
            }
        }
Пример #4
0
        public async Task <IActionResult> Create(MediaCreateViewModel cvm)
        {
            Media newmedia = new Media()
            {
                Rating      = cvm.Rating,
                CategoryId  = cvm.CategoryId,
                Title       = cvm.Title,
                Description = cvm.Description,
                Creator     = cvm.Creator,
                Date        = cvm.Date,
                PhotoUrl    = cvm.PhotoUrl,
                Watched     = cvm.Watched
            };

            newmedia.Category = await _dbContext.Categories.FirstOrDefaultAsync(x => x.Id == newmedia.CategoryId);

            if (String.IsNullOrEmpty(newmedia.PhotoUrl))
            {
                _photoService.AssignPicTomedia(newmedia);
            }

            _dbContext.Add(newmedia);
            await _dbContext.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Пример #5
0
        public async Task <IActionResult> Edit(int id, PodCastEditViewmodel vm)
        {
            if (!TryValidateModel(vm))
            {
                return(View(vm));
            }

            PodCast domainFilm = await _mediaDbContext.PodCasts.FindAsync(id);

            domainFilm.Title       = vm.Title;
            domainFilm.Guest       = vm.Guest;
            domainFilm.ReleaseDate = vm.ReleaseDate;
            domainFilm.Url         = vm.Url;
            domainFilm.Host        = vm.Host;

            _mediaDbContext.Update(domainFilm);

            await _mediaDbContext.SaveChangesAsync();

            return(RedirectToAction("Detail", new { Id = id }));
        }
Пример #6
0
        public async Task <IActionResult> Edit(int id, FilmEditViewModel vm)
        {
            if (!TryValidateModel(vm))
            {
                return(View(vm));
            }

            Film domainFilm = await _mediaDbContext.Films.FindAsync(id);

            domainFilm.Title       = vm.Title;
            domainFilm.Description = vm.Description;
            domainFilm.ReleaseDate = vm.ReleaseDate;
            domainFilm.Url         = vm.Url;
            domainFilm.Producer    = vm.Producer;

            _mediaDbContext.Update(domainFilm);

            await _mediaDbContext.SaveChangesAsync();

            return(RedirectToAction("Detail", new { Id = id }));
        }
Пример #7
0
        public async Task <IActionResult> Edit(SerieEditViewModel vm)
        {
            if (!TryValidateModel(vm))
            {
                return(View(vm));
            }

            Serie domainSerie = await _mediaDbContext.Series.FindAsync(vm.Id);

            domainSerie.Title       = vm.Title;
            domainSerie.Episode     = vm.Episode;
            domainSerie.ReleaseDate = vm.ReleaseDate;
            domainSerie.Url         = vm.Url;
            domainSerie.Producer    = vm.Producer;

            _mediaDbContext.Update(domainSerie);

            await _mediaDbContext.SaveChangesAsync();

            return(RedirectToAction("Detail", new { Id = vm.Id }));
        }
Пример #8
0
        public async Task <IActionResult> Post([FromBody] Comment model)
        {
            Comment newComment = new Comment();

            newComment.Created             = DateTime.UtcNow;
            newComment.Author              = model.Author;
            newComment.CommentText         = model.CommentText;
            newComment.CommentThreadNumber = model.CommentThreadNumber;
            newComment.DisplayName         = model.DisplayName;

            await _context.CommentsDb.AddAsync(newComment);

            await _context.SaveChangesAsync();

            CommentThread cmntThread =
                await _context.CommentThreadsDb.SingleOrDefaultAsync(c => c.Id == model.CommentThreadNumber);

            cmntThread.CommentsCount = cmntThread.CommentsCount + 1;
            _context.CommentThreadsDb.Update(cmntThread);
            await _dataService.SetCommentsList(cmntThread.Id);

            await _context.SaveChangesAsync();

            await _dataService.SetComment(newComment.CommentId);

            string       title   = "New comment for " + model.Progeny.NickName;
            string       message = model.DisplayName + " added a new comment for " + model.Progeny.NickName;
            TimeLineItem tItem   = new TimeLineItem();

            tItem.ProgenyId   = model.Progeny.Id;
            tItem.ItemId      = model.ItemId;
            tItem.ItemType    = model.ItemType;
            tItem.AccessLevel = model.AccessLevel;
            UserInfo userinfo = await _dataService.GetUserInfoByUserId(model.Author);

            await _azureNotifications.ProgenyUpdateNotification(title, message, tItem, userinfo.ProfilePicture);

            return(Ok(newComment));
        }
        public async Task <int?> SaveApiToken(Token token)
        {
            try {
                await _dbContext.Tokens.AddAsync(token);

                var result = await _dbContext.SaveChangesAsync();

                return(result != 0 ? token.TokenId : -1);
            }
            catch (DbUpdateException e) {
                _logger.LogError("ApiAccessService.SaveApiToken - Error while inserting Token to MySQL DB: " + e.StackTrace);
                return(null);
            }
        }
Пример #10
0
        public async Task MapShowPerson(int showId, int personId)
        {
            try
            {
                using (var db = new MediaDbContext())
                {
                    if (await db.ShowPersons.FindAsync(showId, personId) == null)
                    {
                        await db.AddAsync(new ShowPerson()
                        {
                            ShowId = showId, PersonId = personId
                        });

                        await db.SaveChangesAsync();
                    }
                }
            }
            catch (Exception ex)
            {
                var message = ex.Message;
            }
        }
Пример #11
0
        public async Task <T> SaveAsync(T entity)
        {
            await _context.SaveChangesAsync();

            return(entity);
        }