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 })); } }
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); }
public async Task <FluorophoreEntity> SaveFluorophore(FluorophoreEntity entity) { var _item = await Query.Where(e => e.Id == entity.Id).FirstOrDefaultAsync(); if (_item == null) { _item = (await SaveEntity(entity.ToFluorophore(null))); } else { _item = (await SaveEntity(entity.ToFluorophore(_item))); } return(await GetFluorophore(_item.Id)); }
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); }
public static Fluorophore ToFluorophore(this FluorophoreEntity newEntity, Fluorophore oldEntity = null) { Fluorophore entity = oldEntity; if (entity == null) { entity = new Fluorophore(); } entity.Name = newEntity.Name; entity.Emission = newEntity.Emission; entity.Absorption = newEntity.Absorption; entity.Class = newEntity.Class; return(entity); }
public static FluorophoreEntity ToFluorophoreEntity(this Fluorophore model) { if (model == null) { return(null); } FluorophoreEntity entity = new FluorophoreEntity(); entity.Id = model.Id; entity.Name = model.Name; entity.Emission = model.Emission; entity.Absorption = model.Absorption; entity.Class = model.Class; return(entity); }