Beispiel #1
0
        public async Task <IActionResult> GetVideoFragment([FromRoute] int id)
        {
            try
            {
                var item = await _dm.VideoFragmentAccessor.GetVideoFragment(id);

                if (item == null)
                {
                    return(Ok(new ResponseModel()
                    {
                        Result = ResultCode.NotFound
                    }));
                }


                VideoFragmentViewModel model = item.ToVideoFragmentViewModel();

                return(Ok(model));
            }
            catch (Exception ex)
            {
                return(Ok(new ResponseModel()
                {
                    Result = ResultCode.ServerError, Description = ex.Message
                }));
            }
        }
Beispiel #2
0
        public async Task <ResponseModel> SaveVideoFragment(VideoFragmentViewModel model)
        {
            string uri     = "api/videofragment/Save";
            var    request = await _http.PostAsJsonAsync <VideoFragmentViewModel>(uri, model);

            var response = await request.Content.ReadFromJsonAsync <ResponseModel>();

            return(response);
        }
Beispiel #3
0
        public static VideoFragmentViewModel ToVideoFragmentViewModel(this VideoFragmentEntity entity)
        {
            VideoFragmentViewModel model = new VideoFragmentViewModel();

            model.Id             = entity.Id;
            model.InitialVideoId = entity.InitialVideoId;
            model.FrameTime      = entity.FrameTime;
            model.Frame          = entity.Frame;

            return(model);
        }
Beispiel #4
0
        public async Task <IActionResult> Save([FromBody] VideoFragmentViewModel model)
        {
            try
            {
                VideoFragmentEntity entity = null;
                if (!ModelState.IsValid)
                {
                    return(Ok(new ResponseModel()
                    {
                        Result = ResultCode.NotValidData
                    }));
                }
                var item = await _dm.VideoFragmentAccessor.GetVideoFragment(model.InitialVideoId, model.FrameTime);

                if (item != null && item.Id != model.Id)
                {
                    return(Ok(new ResponseModel()
                    {
                        Result = ResultCode.AlreadyExists
                    }));
                }
                if (model.Id <= 0)
                {
                    entity = new VideoFragmentEntity();
                }
                else
                {
                    entity = await _dm.VideoFragmentAccessor.GetVideoFragment(model.Id);

                    if (entity == null)
                    {
                        return(Ok(new ResponseModel()
                        {
                            Result = ResultCode.AlreadyExists
                        }));
                    }
                }
                var entityToSave = model.ToVideoFragmentEntity();

                var savedItem = await _dm.VideoFragmentAccessor.SaveVideoFragment(entityToSave);

                return(Ok(new ResponseModel()
                {
                    Result = ResultCode.Success, Description = savedItem.Id.ToString()
                }));
            }
            catch (Exception ex)
            {
                return(Ok(new ResponseModel()
                {
                    Result = ResultCode.ServerError, Description = ex.Message
                }));
            }
        }
Beispiel #5
0
        public static VideoFragmentEntity ToVideoFragmentEntity(this VideoFragmentViewModel model)
        {
            VideoFragmentEntity entity = new VideoFragmentEntity();

            if (model.Id > 0)
            {
                entity.Id = model.Id;
            }
            entity.InitialVideoId = model.InitialVideoId;
            entity.FrameTime      = model.FrameTime;
            entity.Frame          = model.Frame;

            return(entity);
        }