public async Task UpdateEstado(PersonaPartInt model)
        {
            try
            {
                var _model = await _db.PersonaPartInt.FirstOrDefaultAsync(e => e.PersonaPartIntId == model.PersonaPartIntId);

                if (_model != null)
                {
                    _model.Estado = model.Estado;

                    var infoAgregada = await _dbGEN.dbSetNuevoOC.Where(e => e.descripcion.Equals(_model.Contacto.NombreCompleto) && e.OcsId == "PARTINTPERS").FirstOrDefaultAsync();

                    if (infoAgregada != null && model.Estado == false)
                    {
                        NuevoOCRepository repo = new NuevoOCRepository();
                        await repo.Delete(infoAgregada.NuevoOCId);
                    }
                    else
                    {
                        var _contacto = await _db.Contacto.FirstOrDefaultAsync(e => e.ContactoId == model.ContactoId);

                        if (_contacto != null)
                        {
                            await new NuevoOCRepository(_dbGEN).Create(new NuevoOC("CR", "PARTINTPERS", _contacto.NombreCompleto, "IndexCR.html#/detallesPersonaPartInt/" + model.PersonaPartIntId));
                        }
                    }
                    await _db.SaveChangesAsync();
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }
        public async Task Update(PersonaPartInt model)
        {
            try
            {
                var _model = await _db.PersonaPartInt.FirstOrDefaultAsync(e => e.PersonaPartIntId == model.PersonaPartIntId);

                if (_model != null)
                {
                    _db.Entry(_model).CurrentValues.SetValues(model);
                    await _db.SaveChangesAsync();
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }
        public async Task Create(PersonaPartInt model)
        {
            try
            {
                _db.PersonaPartInt.Add(model);
                await _db.SaveChangesAsync();

                var _contacto = await _db.Contacto.FirstOrDefaultAsync(e => e.ContactoId == model.ContactoId);

                if (_contacto != null)
                {
                    // await new NuevoOCRepository(_dbGEN).Create(new NuevoOC("CR", "PARTINTPERSC", _contacto.NombreCompleto, "IndexCR.html#/detallesPersonaPartIntC/" + model.PersonaPartIntId));
                    await new NuevoOCRepository(_dbGEN).Create(new NuevoOC("CR", "PARTINTPERS", _contacto.NombreCompleto, "IndexCR.html#/detallesPersonaPartInt/" + model.PersonaPartIntId));
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }
Exemple #4
0
                                                            public async Task <IHttpActionResult> Update([FromBody] PersonaPartInt model)
                                                            {
                                                                if (!ModelState.IsValid)
                                                                {
                                                                    return(BadRequest(ModelState));
                                                                }

                                                                try { log.Info(new MDCSet(this.ControllerContext.RouteData));
                                                                      await _entityRepo.Update(model);

                                                                      return(Ok("Registro actualizado exitosamente!")); }
                                                                catch (Exception e) { log.Error(new MDCSet(this.ControllerContext.RouteData), e);
                                                                                      return(InternalServerError(e)); }
                                                            }
Exemple #5
0
                                                            [Authorize] public async Task <IHttpActionResult> Create([FromBody] PersonaPartInt model)
                                                            {
                                                                if (!ModelState.IsValid)
                                                                {
                                                                    return(BadRequest(ModelState));
                                                                }

                                                                try { log.Info(new MDCSet(this.ControllerContext.RouteData));
                                                                      await _entityRepo.Create(model);

                                                                      return(Ok("Registro creado exitosamente!")); }
                                                                catch (Exception e) { log.Error(new MDCSet(this.ControllerContext.RouteData), e);
                                                                                      if (e.Message.Substring(0, 44) == "An error occurred while updating the entries")
                                                                                      {
                                                                                          return(BadRequest("Ya existe un registro con ese nombre"));
                                                                                      }
                                                                                      return(InternalServerError(e)); }
                                                            }
Exemple #6
0
                                                            public async Task <IHttpActionResult> UpdateEstado([FromBody] PersonaPartInt model)
                                                            {
                                                                try { log.Info(new MDCSet(this.ControllerContext.RouteData));
                                                                      await _entityRepo.UpdateEstado(model);

                                                                      return(Ok()); }
                                                                catch (Exception e) { log.Error(new MDCSet(this.ControllerContext.RouteData), e);

                                                                                      return(InternalServerError(e)); }
                                                            }