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

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


                FluorophoreViewModel model = item.ToFluorophoreViewModel();

                return(Ok(model));
            }
            catch (Exception ex)
            {
                return(Ok(new ResponseModel()
                {
                    Result = ResultCode.ServerError, Description = ex.Message
                }));
            }
        }
Exemplo n.º 2
0
        public async Task <ResponseModel> SaveFluorophore(FluorophoreViewModel model)
        {
            string uri     = "api/fluorophore/Save";
            var    request = await _http.PostAsJsonAsync <FluorophoreViewModel>(uri, model);

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

            return(response);
        }
        public async Task <IActionResult> Save([FromBody] FluorophoreViewModel model)
        {
            try
            {
                FluorophoreEntity entity = null;
                if (!ModelState.IsValid)
                {
                    return(Ok(new ResponseModel()
                    {
                        Result = ResultCode.NotValidData
                    }));
                }
                var item = await _dm.FluorophoreAccessor.GetFluorophore(model.Name);

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

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

                await _dm.FluorophoreAccessor.SaveFluorophore(entityToSave);

                return(Ok(new ResponseModel()
                {
                    Result = ResultCode.Success
                }));
            }
            catch (Exception ex)
            {
                return(Ok(new ResponseModel()
                {
                    Result = ResultCode.ServerError, Description = ex.Message
                }));
            }
        }
Exemplo n.º 4
0
        public static FluorophoreViewModel ToFluorophoreViewModel(this FluorophoreEntity entity)
        {
            FluorophoreViewModel model = new FluorophoreViewModel();

            model.Id         = entity.Id;
            model.Class      = entity.Class;
            model.Emission   = entity.Emission;
            model.Absorption = entity.Absorption;
            model.Name       = entity.Name;
            return(model);
        }
Exemplo n.º 5
0
        public static FluorophoreEntity ToFluorophoreEntity(this FluorophoreViewModel model)
        {
            FluorophoreEntity entity = new FluorophoreEntity();

            if (model.Id > 0)
            {
                entity.Id = model.Id;
            }
            entity.Class      = model.Class;
            entity.Emission   = model.Emission;
            entity.Absorption = model.Absorption;
            entity.Name       = model.Name;
            return(entity);
        }