Пример #1
0
        public void Create(CreateVideoBindingModel model)
        {
            var videoUrl = this.GetYouTubeIdFromLink(model.VideoUrl);

            var video = new Video
            {
                Title    = model.Title,
                VideoUrl = videoUrl
            };

            this.Context.Videos.Add(video);
            this.Context.SaveChanges();
        }
Пример #2
0
        public IHttpActionResult PostVideo([FromBody] CreateVideoBindingModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var             userId = User.Identity.GetUserId();
            ApplicationUser user   = null;

            if (userId != null)
            {
                user = db.Users.Find(userId);
            }

            if (user == null && userId != null)
            {
                return(Unauthorized());
            }

            var video = new Video()
            {
                Title      = model.Title,
                LocationId = model.LocationId,
                OwnerId    = userId,
                Status     = VideoStatus.Pending,
                PostedOn   = DateTime.Now
            };

            db.Videos.Add(video);
            db.SaveChanges();

            return(this.Ok(new
            {
                Id = video.Id,
                Title = video.Title,
                status = video.Status,
                country = video.Location.Country,
                City = video.Location.City,
                Owner = video.Owner.UserName
            }));
        }