Exemple #1
0
 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);
 }
        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 void InsertOrUpdateFromList(List <CellonOptionDTO> cellonOption, Guid equipmentSerialId)
        {
            try
            {
                using (OpenNosContext context = DataAccessHelper.CreateContext())
                {
                    void insert(CellonOptionDTO cellonoption)
                    {
                        CellonOption _entity = new CellonOption();

                        Mapper.Mappers.CellonOptionMapper.ToCellonOption(cellonoption, _entity);
                        context.CellonOption.Add(_entity);
                        context.SaveChanges();
                        cellonoption.CellonOptionId = _entity.CellonOptionId;
                    }

                    void update(CellonOption _entity, CellonOptionDTO cellonoption)
                    {
                        if (_entity != null)
                        {
                            Mapper.Mappers.CellonOptionMapper.ToCellonOption(cellonoption, _entity);
                        }
                    }

                    foreach (CellonOptionDTO item in cellonOption)
                    {
                        item.EquipmentSerialId = equipmentSerialId;
                        CellonOption entity = context.CellonOption.FirstOrDefault(c => c.CellonOptionId == item.CellonOptionId);

                        if (entity == null)
                        {
                            insert(item);
                        }
                        else
                        {
                            update(entity, item);
                        }
                    }

                    context.SaveChanges();
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
            }
        }
        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);
            }
        }