public static bool ToCellonOptionDTO(CellonOption input, CellonOptionDTO output) { if (input == null) { return(false); } output.CellonOptionId = input.CellonOptionId; output.EquipmentSerialId = input.EquipmentSerialId; output.Level = input.Level; output.Type = input.Type; output.Value = input.Value; return(true); }
public IEnumerable <CellonOptionDTO> GetOptionsByWearableInstanceId(Guid wearableInstanceId) { using (OpenNosContext context = DataAccessHelper.CreateContext()) { List <CellonOptionDTO> result = new List <CellonOptionDTO>(); foreach (CellonOption entity in context.CellonOption.Where(c => c.EquipmentSerialId == wearableInstanceId)) { CellonOptionDTO dto = new CellonOptionDTO(); Mapper.Mappers.CellonOptionMapper.ToCellonOptionDTO(entity, dto); result.Add(dto); } return(result); } }
private static CellonOptionDTO insert(CellonOptionDTO cellonOption, OpenNosContext context) { CellonOption entity = new CellonOption(); Mapper.Mappers.CellonOptionMapper.ToCellonOption(cellonOption, entity); context.CellonOption.Add(entity); context.SaveChanges(); if (Mapper.Mappers.CellonOptionMapper.ToCellonOptionDTO(entity, cellonOption)) { return(cellonOption); } return(null); }
private static CellonOptionDTO update(CellonOption entity, CellonOptionDTO cellonOption, OpenNosContext context) { if (entity != null) { Mapper.Mappers.CellonOptionMapper.ToCellonOption(cellonOption, entity); context.SaveChanges(); } if (Mapper.Mappers.CellonOptionMapper.ToCellonOptionDTO(entity, cellonOption)) { return(cellonOption); } return(null); }
public CellonOptionDTO InsertOrUpdate(CellonOptionDTO cellonOption) { try { using (OpenNosContext context = DataAccessHelper.CreateContext()) { long cellonOptionId = cellonOption.CellonOptionId; CellonOption entity = context.CellonOption.FirstOrDefault(c => c.CellonOptionId.Equals(cellonOptionId)); if (entity == null) { return(insert(cellonOption, context)); } return(update(entity, cellonOption, context)); } } catch (Exception e) { Logger.Error(string.Format(Language.Instance.GetMessageFromKey("INSERT_ERROR"), cellonOption, e.Message), e); return(cellonOption); } }