Example #1
0
        public Video CreateVideo(CreateVideoOptions options)
        {
            if (options == null)
            {
                return(null);
            }

            var project = projectService_.Search(new SearchProjectOptions
            {
                ProjectId = options.ProjectId
            }).SingleOrDefault();

            if (project == null)
            {
                return(null);
            }

            var video = new Video()
            {
                Name = options.Name,
                Path = options.Path,
            };

            project.Videos.Add(video);
            context_.Update(project);
            context_.Add(video);

            if (context_.SaveChanges() > 0)
            {
                return(video);
            }

            return(null);
        }
        public Result <Video> CreateVideo(int projectId,
                                          CreateVideoOptions options)
        {
            if (options == null)
            {
                return(Result <Video> .ActionFailed(
                           StatusCode.BadRequest, "Null options"));
            }

            if (string.IsNullOrWhiteSpace(options.Url))
            {
                return(Result <Video> .ActionFailed(
                           StatusCode.BadRequest, "Null or empty Url"));
            }

            var project = context_
                          .Set <Project>()
                          .Where(p => p.ProjectId == projectId)
                          .SingleOrDefault();

            if (project == null)
            {
                return(Result <Video> .ActionFailed(
                           StatusCode.BadRequest, "Invalid projectId"));
            }

            var video = new Video()
            {
                Url = options.Url,
            };

            project.Videos.Add(video);

            var rows = 0;

            try
            {
                rows = context_.SaveChanges();
            }
            catch (Exception ex)
            {
                return(Result <Video> .ActionFailed(
                           StatusCode.InternalServerError, ex.ToString()));
            }

            if (rows <= 0)
            {
                return(Result <Video> .ActionFailed(
                           StatusCode.InternalServerError,
                           "Video could not be added"));
            }

            return(Result <Video> .ActionSuccessful(video));
        }
        public IActionResult Create(int id, [FromBody] CreateVideoOptions options)
        {
            var result = videoService.CreateVideo(id, options);

            if (!result.Success)
            {
                return(StatusCode((int)result.ErrorCode,
                                  result.ErrorText));
            }

            return(Json(result.Data));
        }