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 })); } }
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); }
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); }
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 })); } }
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); }