Beispiel #1
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 #2
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 #3
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);
        }
Beispiel #4
0
        public async Task <VideoFragmentEntity> SaveVideoFragment(VideoFragmentEntity entity)
        {
            var _item = await Query.Where(e => e.Id == entity.Id).FirstOrDefaultAsync();

            if (_item == null)
            {
                _item = (await SaveEntity(entity.ToVideoFragment(null)));
            }
            else
            {
                _item = (await SaveEntity(entity.ToVideoFragment(_item)));
            }
            return(await GetVideoFragment(_item.Id));
        }
        public static VideoFragment ToVideoFragment(this VideoFragmentEntity newEntity, VideoFragment oldEntity = null)
        {
            VideoFragment entity = oldEntity;

            if (entity == null)
            {
                entity = new VideoFragment();
            }
            entity.Frame          = newEntity.Frame;
            entity.FrameTime      = newEntity.FrameTime;
            entity.InitialVideoId = newEntity.InitialVideoId;


            return(entity);
        }
        public static VideoFragmentEntity ToVideoFragmentEntity(this VideoFragment model)
        {
            if (model == null)
            {
                return(null);
            }

            VideoFragmentEntity entity = new VideoFragmentEntity();

            entity.Id             = model.Id;
            entity.Frame          = model.Frame;
            entity.FrameTime      = model.FrameTime;
            entity.InitialVideoId = model.InitialVideoId;
            return(entity);
        }