public IHttpActionResult CrearPerfil([FromBody] PerfilDto perfil)
        {
            try
            {
                usuariosNegocio = new UsuariosNegocio();
                string res = usuariosNegocio.CreaModificaPerfil("I", perfil);

                return(Content(HttpStatusCode.OK, new Mensaje()
                {
                    codigoRespuesta = Catalogo.OK, mensajeRespuesta = "", objetoRespuesta = res
                }));
            }
            catch (ExcepcionOperacion exOp)
            {
                return(Content(HttpStatusCode.InternalServerError, new Mensaje()
                {
                    codigoRespuesta = Catalogo.ERROR, mensajeRespuesta = Catalogo.FALLO_CONSULTA_MENU + exOp.Message
                }));
            }
            catch (Exception ex)
            {
                return(Content(HttpStatusCode.InternalServerError, new Mensaje()
                {
                    codigoRespuesta = Catalogo.ERROR, mensajeRespuesta = Catalogo.FALLO_CONSULTA_MENU + ex.Message
                }));
            }
        }
        public async Task <IActionResult> Post(PerfilDto perfilDto)
        {
            var perfil = _mapper.Map <Perfil>(perfilDto);
            await _perfilService.Agregar(perfil);

            perfilDto = _mapper.Map <PerfilDto>(perfil);
            var response = new ApiResponse <PerfilDto>(perfilDto);

            return(Ok(response));
        }
Ejemplo n.º 3
0
        private void AgregarButton_Click(object sender, EventArgs e)
        {
            if (DescripcionText.Text == "" || ValorHoraNumeric.Value == 0)
            {
                MessageBox.Show("Por favor complete la descripción de su perfil y el valor horario");
                return;
            }
            PerfilDto perfilDto = new PerfilDto();

            perfilDto.Descripcion  = DescripcionText.Text;
            perfilDto.ValorHorario = ValorHoraNumeric.Value;
            if (ID != 0)
            {
                var perfilAeditar = container.GetInstance <IPerfilService>().GetByIdAsNoTracking(ID);
                perfilAeditar.Descripcion  = DescripcionText.Text;
                perfilAeditar.ValorHorario = ValorHoraNumeric.Value;
                try
                {
                    var respuesta = container.GetInstance <IPerfilService>().Update(perfilAeditar);

                    if (respuesta != null)
                    {
                        MessageBox.Show("Perfil editado");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("No se ha podido editar el perfil. " + ex.Message);
                }

                ID = 0;
                ElejirPerfilcomboBox.ResetText();
                ElejirPerfilcomboBox.Items.Clear();
                CargarListaPerfiles();
                container.GetInstance <IPerfilService>().Limpiar();
            }
            else
            {
                try
                {
                    var respuesta = container.GetInstance <IPerfilService>().Update(perfilDto);
                    if (respuesta != null)
                    {
                        MessageBox.Show("Perfil creado");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("No se ha podido crear el perfil. " + ex.Message);
                }
                container.GetInstance <IPerfilService>().Limpiar();
            }
            DescripcionText.Text   = "";
            ValorHoraNumeric.Value = 0;
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> AdicionarPerfil([FromBody] PerfilDto perfil)
        {
            if (!ModelState.IsValid)
            {
                return(CustomResponse(ModelState));
            }

            await _usuarioService.AdicionarPerfil(new Perfil(perfil.Nome));

            return(CustomResponse());
        }
        public async Task <IActionResult> Put(int id, PerfilDto perfilDto)
        {
            var perfil = _mapper.Map <Perfil>(perfilDto);

            perfil.Id = id;
            var result = await _perfilService.Actualizar(perfil);

            var response = new ApiResponse <bool>(result);

            return(Ok(response));
        }
Ejemplo n.º 6
0
 public string CreaModificaPerfil(string trans, PerfilDto perfil)
 {
     using (UnitOfWork uow = new UnitOfWork())
     {
         DataTable tblPerfil = uow.UsuariosRepositorio.CrudPerfil(trans, perfil);
         if (tblPerfil.Rows[0]["ID"].ToString() != "1")
         {
             throw new Exception(tblPerfil.Rows[0]["Mensaje"].ToString());
         }
         return(tblPerfil.Rows[0]["Mensaje"].ToString());
     }
 }
Ejemplo n.º 7
0
 public ActionResult AtualizarSenha(PerfilDto perfilDto)
 {
     try
     {
         _usuarioService.AtualizarSenha(perfilDto);
         return(Json("Atualização realizada com suceso!"));
     }
     catch (Exception ex)
     {
         throw new HttpException(ex.Message);
     }
 }
Ejemplo n.º 8
0
 public ActionResult AtualizarFotoPerfil(PerfilDto perfilDto)
 {
     try
     {
         _usuarioService.SalvarNovaFotoPerfil(perfilDto.Arquivo);
         return(Json("Atualização de foto realizada com suceso!"));
     }
     catch (Exception ex)
     {
         throw new HttpException(ex.Message);
     }
 }
Ejemplo n.º 9
0
        /*Métodos del Perfil*/
        #region Perfil
        public DataTable CrudPerfil(string tipoTrans, PerfilDto perfil)
        {
            using (SqlConnection conn = new SqlConnection(Util.ObtenerCadenaConexion("POS_DB")))
            {
                try
                {
                    string     spName = @"[dbo].[prcSegPerfil]";
                    SqlCommand cmd    = new SqlCommand(spName, conn);

                    SqlParameter transaccion = new SqlParameter("@p_transaccion", SqlDbType.VarChar);
                    transaccion.Value = tipoTrans;
                    SqlParameter idperfil = new SqlParameter("@p_id_perfil", SqlDbType.Int);
                    idperfil.Value = perfil.id;
                    SqlParameter nombre = new SqlParameter("@p_nombre", SqlDbType.VarChar);
                    nombre.Value = perfil.nombre;
                    SqlParameter descripcion = new SqlParameter("@p_descripcion", SqlDbType.VarChar);
                    descripcion.Value = perfil.descripcion;
                    SqlParameter idcliente = new SqlParameter("@p_id_cliente", SqlDbType.VarChar);
                    idcliente.Value = perfil.idCliente;
                    SqlParameter activo = new SqlParameter("@p_activo", SqlDbType.Int);
                    activo.Value = Convert.ToInt16(perfil.activo);
                    SqlParameter usuario = new SqlParameter("@p_usuario", SqlDbType.VarChar);
                    usuario.Value = "POS";

                    cmd.Parameters.Add(transaccion);
                    cmd.Parameters.Add(idperfil);
                    cmd.Parameters.Add(nombre);
                    cmd.Parameters.Add(descripcion);
                    cmd.Parameters.Add(idcliente);
                    cmd.Parameters.Add(activo);
                    cmd.Parameters.Add(usuario);

                    DataTable tblMenu = new DataTable();

                    conn.Open();

                    cmd.CommandType = CommandType.StoredProcedure;
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    da.ReturnProviderSpecificTypes = true;
                    da.Fill(tblMenu);
                    da.Dispose();

                    conn.Close();

                    return(tblMenu);
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
        public bool AddNew(PerfilDto pPerfil)
        {
            List <PerfilDto> listaPerfil = this.GetAll();

            if (listaPerfil != null && listaPerfil.FirstOrDefault(x => x.Nombre.Trim().ToLower() == pPerfil.Nombre.Trim().ToLower()) != null)
            {
                return(false);
            }

            pPerfil.Id = this.GetNextId();
            Save(pPerfil);
            return(true);
        }
Ejemplo n.º 11
0
        public PerfilDto Add(PerfilDto dto)
        {
            var obj = new Domain.Entity.Entity.Perfil()
            {
                Descripcion = dto.Descripcion,
                Eliminado   = dto.Eliminado
            };

            _perfilRepository.Add(obj);
            Save();

            dto.Id = obj.Id;

            return(dto);
        }
Ejemplo n.º 12
0
        public async Task <ActionResult <PerfilDto> > Put(int id, [FromBody] PerfilDto perfilDto)
        {
            if (perfilDto == null)
            {
                return(NotFound());
            }

            var perfil    = _mapper.Map <Perfil>(perfilDto);
            var resultado = await _perfilRepositorio.Actualizar(perfil);

            if (!resultado)
            {
                return(BadRequest());
            }
            return(perfilDto);
        }
Ejemplo n.º 13
0
        public HttpResponseMessage Update(HttpRequestMessage request, [FromBody] PerfilDto dto)
        {
            HttpResponseMessage response = null;

            if (!ModelState.IsValid)
            {
                response = request.CreateResponse(HttpStatusCode.BadRequest);
            }
            else
            {
                var dtoUpdated = perfilService.Update(dto);
                response = request.CreateResponse(HttpStatusCode.OK, dtoUpdated);
            }

            return(response);
        }
Ejemplo n.º 14
0
 public List <PerfilDto> ConsultarPerfil()
 {
     using (UnitOfWork uow = new UnitOfWork())
     {
         PerfilDto        perfil     = new PerfilDto(-1, "", "", -1, true);
         DataTable        tblPerfil  = uow.UsuariosRepositorio.CrudPerfil("C", perfil);
         List <PerfilDto> listPerfil = new List <PerfilDto>();
         PerfilDto        PerfilTemp;
         foreach (DataRow dr in tblPerfil.Rows)
         {
             PerfilTemp = new PerfilDto(dr);
             listPerfil.Add(PerfilTemp);
         }
         return(listPerfil);
     }
 }
        public bool Modify(PerfilDto pPerfil)
        {
            List <PerfilDto> listaPerfil = this.GetAll();

            if (pPerfil != null && listaPerfil.FirstOrDefault(x => x.Id == pPerfil.Id) != null)
            {
                listaPerfil.FirstOrDefault(x => x.Id == pPerfil.Id).Nombre      = pPerfil.Nombre;
                listaPerfil.FirstOrDefault(x => x.Id == pPerfil.Id).Descripcion = pPerfil.Descripcion;
                listaPerfil.FirstOrDefault(x => x.Id == pPerfil.Id).Activo      = pPerfil.Activo;

                File.Delete(_path);
                this.Save(listaPerfil);
                return(true);
            }

            return(false);
        }
Ejemplo n.º 16
0
        public PerfilDto Update(PerfilDto dto)
        {
            var obj = _perfilRepository.GetById(dto.Id);

            if (obj != null)
            {
                obj.Descripcion = dto.Descripcion;

                _perfilRepository.Update(obj);
                Save();

                return(dto);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 17
0
        public async Task <ActionResult <PerfilDto> > Post(PerfilDto perfilDto)
        {
            try
            {
                var perfil      = _mapper.Map <Perfil>(perfilDto);
                var nuevoPerfil = await _perfilesRepository.Agregar(perfil);

                if (nuevoPerfil == null)
                {
                    return(BadRequest());
                }
                var nuevoPefilDto = _mapper.Map <PerfilDto>(nuevoPerfil);
                return(CreatedAtAction(nameof(Post), new { id = nuevoPefilDto.Id }, nuevoPefilDto));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error en {nameof(Post)}: " + ex.Message);
                return(BadRequest());
            }
        }
        public void Save(PerfilDto pPerfil)
        {
            string json = JsonConvert.SerializeObject(pPerfil);

            if (File.Exists(_path))
            {
                using (var writer = new StreamWriter(_path, true))
                {
                    writer.WriteLine(json);
                    writer.Close();
                }
            }
            else
            {
                File.WriteAllText(_path, json);
                using (var writer = new StreamWriter(_path, true))
                {
                    writer.WriteLine(string.Empty);
                    writer.Close();
                }
            }
        }
Ejemplo n.º 19
0
 /// <summary>
 /// Salva um objeto<T>
 /// </summary>
 public virtual void Save(PerfilDto model)
 {
     _unitOfWork.GetRepository <PerfilDto>().Add(model);
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Salva a edição de um objeto<T>
 /// </summary>
 public virtual void Update(PerfilDto model)
 {
     _unitOfWork.GetRepository <PerfilDto>().Update(model);
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Salva e retorna o objeto<T> salvo
 /// </summary>
 public virtual PerfilDto SaveGetItem(PerfilDto model)
 {
     _unitOfWork.GetRepository <PerfilDto>().Add(model);
     return(model);
 }
 public int Save([FromBody] PerfilDto perfil)
 {
     _service.AddNew(perfil);
     return(perfil.Id);
 }
 public void Modify(PerfilDto perfil)
 {
     _service.Modify(perfil);
 }