public async Task <IActionResult> GetFinalImage([FromRoute] int id)
        {
            try
            {
                var item = await _dm.FinalImageAccessor.GetFinalImage(id);

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


                FinalImageViewModel model = item.ToFinalImageViewModel();

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

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

            return(response);
        }
        public async Task <IActionResult> Save([FromBody] FinalImageViewModel model)
        {
            try
            {
                FinalImageEntity entity = null;
                if (!ModelState.IsValid)
                {
                    return(Ok(new ResponseModel()
                    {
                        Result = ResultCode.NotValidData
                    }));
                }
                var item = await _dm.FinalImageAccessor.GetFinalImageS(model.InitialVideoId);

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

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

                var savedItem = await _dm.FinalImageAccessor.SaveFinalImage(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 FinalImageViewModel ToFinalImageViewModel(this FinalImageEntity entity)
        {
            FinalImageViewModel model = new FinalImageViewModel();

            model.Id             = entity.Id;
            model.Format         = entity.Format;
            model.Resolution     = entity.Resolution;
            model.FinalImageBlob = entity.FinalImageBlob;
            if (entity.InitialVideo != null)
            {
                model.InitialVideoId = entity.InitialVideo.Id;
                model.InitialVideo   = entity.InitialVideo.ToInitialVideoViewModel();
            }
            return(model);
        }
        public static FinalImageEntity ToFinalImageEntity(this FinalImageViewModel model)
        {
            FinalImageEntity entity = new FinalImageEntity();

            if (model.Id > 0)
            {
                entity.Id = model.Id;
            }
            entity.Format         = model.Format;
            entity.Resolution     = model.Resolution;
            entity.FinalImageBlob = model.FinalImageBlob;
            entity.InitialVideoId = model.InitialVideoId;

            return(entity);
        }