Esempio n. 1
0
        public async Task Update(TipoPagos model)
        {
            try
            {
                var _model = await dbGI.DbSetTipoPagos.FirstOrDefaultAsync(e => e.TipoPagosId == model.TipoPagosId);

                if (_model != null)
                {
                    if (!model.ExisteEn(dbGI.DbSetTipoPagos.Where(e => e.TipoPagosId != model.TipoPagosId).Select(e => e.Descripcion).ToList()))
                    {
                        dbGI.Entry(_model).CurrentValues.SetValues(model);
                        await dbGI.SaveChangesAsync();
                    }
                    else
                    {
                        throw new ApplicationException("Ya existe un registro con ese nombre.");
                    }
                }
            }
            catch (ApplicationException e)
            {
                throw new ApplicationException(e.Message, e);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }
Esempio n. 2
0
 public async Task Create(TipoPagos model)
 {
     try
     {
         if (!model.ExisteEn(dbGI.DbSetTipoPagos.Where(e => e.TipoPagosId != model.TipoPagosId).Select(e => e.Descripcion).ToList()))
         {
             dbGI.DbSetTipoPagos.Add(model);
             await dbGI.SaveChangesAsync();
         }
         else
         {
             throw new ApplicationException("Ya existe un registro con ese nombre.");
         }
     }
     catch (ApplicationException e)
     {
         throw new ApplicationException(e.Message, e);
     }
     catch (Exception e)
     {
         throw new Exception(e.Message, e);
     }
 }