Ejemplo n.º 1
0
 public async Task <Rol> Post(Rol rol)
 {
     if (rol.Id == 0)
     {
         return(await _rolService.Create(rol));
     }
     else
     {
         return(await _rolService.Update(rol));
     }
 }
        public async Task <IActionResult> Create(RolDTO dto)
        {
            if (ModelState.IsValid)
            {
                dto = await _rolService.Create(dto, this.Usuario);

                return(Ok(dto));
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
Ejemplo n.º 3
0
        public IActionResult Agregar([FromBody] RolModel model)
        {
            // map model to entity
            var rol = _mapper.Map <Rol>(model);

            try
            {
                // create
                _rolService.Create(rol);
                return(Ok());
            }
            catch (AppException ex)
            {
                // return error message if there was an exception
                return(BadRequest(new { message = ex.Message }));
            }
        }
Ejemplo n.º 4
0
        public async Task <EmpresaDTO> Create(UsuarioDTO userLogged, EmpresaDTO dto)
        {
            //relleno el entity con los datos de la empresa
            var entity = _mapper.Map <Empresa>(dto);

            entity.Active         = true;
            entity.CreationDate   = DateTime.Now;
            entity.CreationUserId = userLogged.Id;
            entity.UpdateDate     = DateTime.Now;
            entity.UpdateUserId   = userLogged.Id;

            //creo la empresa
            entity = await _empresaRepository.Insert(entity);

            //genero un nuevo rol con permiso de manager
            int[] Permisos = { 2 };

            RolDTO rol = new RolDTO
            {
                Nombre      = "Manager",
                Descripcion = "Administrador de la Empresa",
                Permisos    = Permisos,
            };

            var userLoggedRol = userLogged;

            userLoggedRol.IdEmpresa = entity.Id;
            //creo el rol
            rol = await _rolService.Create(rol, userLoggedRol);

            //genero el usuario con los datos
            var usuarioDTO = new UsuarioDTO
            {
                Nombre    = dto.NombreManager,
                Apellido  = dto.ApellidoManager,
                Email     = dto.EmailManager,
                IdRol     = rol.Id,
                IdEmpresa = entity.Id
            };

            //creo el usuario
            await _usuarioService.Insert(userLogged, usuarioDTO);

            return(_mapper.Map <EmpresaDTO>(entity));
        }
Ejemplo n.º 5
0
 public ApiResultModel <ROL> Create([FromBody] ROL aux) => GetApiResultModel(() => _rolService.Create(aux));