コード例 #1
0
        public async Task Update(TipoPropiedadIndustrial pin)
        {
            try
            {
                if (!pin.ExisteEn(_db.TipoPropiedadIndustrial
                                  .Where(e => e.TipoPropiedadIndustrialId != pin.TipoPropiedadIndustrialId)
                                  .Select(e => e.Descripcion).ToList()))
                {
                    var _model = await _db.TipoPropiedadIndustrial.FirstOrDefaultAsync(e => e.TipoPropiedadIndustrialId == pin.TipoPropiedadIndustrialId);

                    if (_model != null)
                    {
                        _db.Entry(_model).CurrentValues.SetValues(pin);
                        await _db.SaveChangesAsync();
                    }
                }
                else
                {
                    throw new ApplicationException("Ya existe un registro con ese nombre.");
                }
            }
            catch (ApplicationException e)
            {
                throw new ApplicationException(e.Message);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }
コード例 #2
0
 public async Task Create(TipoPropiedadIndustrial pin)
 {
     try
     {
         if (!pin.ExisteEn(_db.TipoPropiedadIndustrial
                           .Where(e => e.TipoPropiedadIndustrialId != pin.TipoPropiedadIndustrialId)
                           .Select(e => e.Descripcion).ToList()))
         {
             pin.prioridadOrdenamiento = 9;
             _db.TipoPropiedadIndustrial.Add(pin);
             await _db.SaveChangesAsync();
         }
         else
         {
             throw new ApplicationException("Ya existe un registro con ese nombre.");
         }
     }
     catch (ApplicationException e)
     {
         throw new ApplicationException(e.Message);
     }
     catch (Exception e)
     {
         throw new Exception(e.Message, e);
     }
 }
コード例 #3
0
        public async Task <IHttpActionResult> Create(TipoPropiedadIndustrial tipopropiedad)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                log.Info(new MDCSet(this.ControllerContext.RouteData));
                await _tipoPInRepo.Create(tipopropiedad);

                return(Ok("Registro creado exitosamente."));
            }
            catch (ApplicationException e)
            {
                return(BadRequest(e.Message));
            }
            catch (Exception e)
            {
                log.Error(new MDCSet(this.ControllerContext.RouteData), e);
                return(InternalServerError(e));
            }
        }