Beispiel #1
0
        public async Task <ResponseModel> SaveDSTORM(dSTORMInfoViewModel model)
        {
            string uri     = "api/dstorminfo/Save";
            var    request = await _http.PostAsJsonAsync <dSTORMInfoViewModel>(uri, model);

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

            return(response);
        }
        public static dSTORMInfoViewModel TodSTORMInfoViewModel(this dSTORMInfoEntity entity)
        {
            dSTORMInfoViewModel model = new dSTORMInfoViewModel();

            model.Id              = entity.Id;
            model.XCoord          = entity.XCoord;
            model.YCoord          = entity.YCoord;
            model.VideoFragmentId = entity.VideoFragmentId;
            return(model);
        }
        public async Task <IActionResult> Save([FromBody] dSTORMInfoViewModel model)
        {
            try
            {
                dSTORMInfoEntity entity = null;
                if (!ModelState.IsValid)
                {
                    return(Ok(new ResponseModel()
                    {
                        Result = ResultCode.NotValidData
                    }));
                }
                var item = await _dm.dSTORMInfoAccessor.GetdSTORMInfo(model.XCoord, model.YCoord, model.VideoFragmentId);

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

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

                var savedItem = await _dm.dSTORMInfoAccessor.SavedSTORMInfo(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 dSTORMInfoEntity TodSTORMInfoEntity(this dSTORMInfoViewModel model)
        {
            dSTORMInfoEntity entity = new dSTORMInfoEntity();

            if (model.Id > 0)
            {
                entity.Id = model.Id;
            }
            entity.XCoord          = model.XCoord;
            entity.YCoord          = model.YCoord;
            entity.VideoFragmentId = model.VideoFragmentId;
            return(entity);
        }