public static SetupViewModel ToSetupViewModel(this SetupEntity entity) { SetupViewModel model = new SetupViewModel(); model.Id = entity.Id; if (entity.AOTFilter != null) { model.AOTFilterId = entity.AOTFilter.Id; model.AOTFilter = entity.AOTFilter.ToAOTFilterViewModel(); } if (entity.Camera != null) { model.CameraId = entity.Camera.Id; model.Camera = entity.Camera.ToCameraViewModel(); } if (entity.Objective != null) { model.ObjectiveId = entity.Objective.Id; model.Objective = entity.Objective.ToObjectiveViewModel(); } if (entity.Laser != null) { model.LaserId = entity.Laser.Id; model.Laser = entity.Laser.ToLaserViewModel(); } if (entity.Microscope != null) { model.MicroscopeId = entity.Microscope.Id; model.Microscope = entity.Microscope.ToMicroscopeViewModel(); } model.Name = "AOTFilter: " + model.AOTFilter.Name + ", Camera: " + model.Camera.Producer + ", Objective: " + model.Objective.Name + ", Laser: " + model.Laser.Producer + ", Microscope: " + model.Microscope.Producer; return(model); }
public static SetupEntity ToSetupEntity(this Setup model) { if (model == null) { return(null); } SetupEntity entity = new SetupEntity(); entity.Id = model.Id; if (model.AOTFilter != null) { entity.AOTFilter = model.AOTFilter.ToAOTFilterEntity(); } if (model.Camera != null) { entity.Camera = model.Camera.ToCameraEntity(); } if (model.Objective != null) { entity.Objective = model.Objective.ToObjectiveEntity(); } if (model.Laser != null) { entity.Laser = model.Laser.ToLaserEntity(); } if (model.Microscope != null) { entity.Microscope = model.Microscope.ToMicroscopeEntity(); } return(entity); }
public static Setup ToSetup(this SetupEntity newEntity, Setup oldEntity = null) { Setup entity = oldEntity; if (entity == null) { entity = new Setup(); } entity.AOTFilterId = newEntity.AOTFilterId; entity.CameraId = newEntity.CameraId; entity.ObjectiveId = newEntity.ObjectiveId; entity.LaserId = newEntity.LaserId; entity.MicroscopeId = newEntity.MicroscopeId; // if(newEntity.AOTFilter != null) // entity.AOTFilterId = newEntity.AOTFilter.Id; // if (newEntity.Camera != null) // entity.CameraId = newEntity.Camera.Id; // if (newEntity.Objective != null) // entity.ObjectiveId = newEntity.Objective.Id; // if (newEntity.Laser != null) // entity.LaserId = newEntity.Laser.Id; // if (newEntity.Microscope != null) // entity.MicroscopeId = newEntity.Microscope.Id; return(entity); }
public async Task <IActionResult> Save([FromBody] SetupViewModel model) { try { SetupEntity entity = null; if (!ModelState.IsValid) { return(Ok(new ResponseModel() { Result = ResultCode.NotValidData })); } var item = await _dm.SetupAccessor.GetSetup(model.AOTFilterId, model.CameraId, model.LaserId, model.MicroscopeId, model.ObjectiveId); if (item != null && item.Id != model.Id) { return(Ok(new ResponseModel() { Result = ResultCode.AlreadyExists })); } if (model.Id <= 0) { entity = new SetupEntity(); } else { entity = await _dm.SetupAccessor.GetSetup(model.Id); if (entity == null) { return(Ok(new ResponseModel() { Result = ResultCode.AlreadyExists })); } } var entityToSave = model.ToSetupEntity(); await _dm.SetupAccessor.SaveSetup(entityToSave); return(Ok(new ResponseModel() { Result = ResultCode.Success })); } catch (Exception ex) { return(Ok(new ResponseModel() { Result = ResultCode.ServerError, Description = ex.Message })); } }
public async Task <SetupEntity> SaveSetup(SetupEntity entity) { var _item = await Query.Where(e => e.Id == entity.Id).FirstOrDefaultAsync(); if (_item == null) { _item = (await SaveEntity(entity.ToSetup(null))); } else { _item = (await SaveEntity(entity.ToSetup(_item))); } return(await GetSetup(_item.Id)); }
public static SetupEntity ToSetupEntity(this SetupViewModel model) { SetupEntity entity = new SetupEntity(); if (model.Id > 0) { entity.Id = model.Id; } entity.AOTFilterId = model.AOTFilterId; entity.CameraId = model.CameraId; entity.ObjectiveId = model.ObjectiveId; entity.LaserId = model.LaserId; entity.MicroscopeId = model.MicroscopeId; return(entity); }
public static async Task <string> GenerateIdAsync(this INoSQLTableStorage <SetupEntity> tableStorage, string partitionKey, string rowKey, int fromId) { while (true) { try { var result = await tableStorage.ReplaceAsync(partitionKey, rowKey, itm => { int i; try { i = int.Parse(itm.Value); } catch (Exception) { i = fromId; } itm.Value = (i + 1).ToString(CultureInfo.InvariantCulture); return(itm); }); if (result != null) { return(result.Value); } var idEntity = SetupEntity.Create(partitionKey, rowKey, fromId.ToString(CultureInfo.InvariantCulture)); await tableStorage.InsertAsync(idEntity, Conflict); } catch (StorageException e) { if (e.RequestInformation.HttpStatusCode != Conflict) { throw; } } } }