Пример #1
0
        public IActionResult Insert([FromBody] ObjetoVM obj)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var result = _service.Insert(obj);

                if (result == null)
                {
                    return(NoContent());
                }

                return(Ok(result));
            }
            catch (Exception ex)
            {
                return(BadRequest(new
                {
                    errors = new string[] { "Falha ao inserir: " + ex.Message }
                }));
            }
        }
Пример #2
0
        public UsuarioVM Insert(ObjetoVM obj)
        {
            Usuario model = obj.ObjToModel();

            _repository.Insert(model);

            UsuarioVM view = obj.Login != " " ? FindUser(obj.Login) : null;

            return(view);
        }
Пример #3
0
        public UsuarioVM Update(ObjetoVM obj)
        {
            Usuario model = obj.ObjToModel();

            _repository.Update(model);

            UsuarioVM view = obj.Id > 0 ? Find(obj.Id) : null;

            return(view);
        }
Пример #4
0
        public static Usuario ObjToModel(this ObjetoVM obj)
        {
            if (obj == null)
            {
                return(null);
            }

            var model = new Usuario()
            {
                Id        = obj.Id,
                Nome      = obj.Nome,
                Fone      = obj.Fone,
                Email     = obj.Email,
                Login     = obj.Login,
                Senha     = obj.Senha,
                Ativo     = obj.Ativo,
                Id_funcao = obj.Id_funcao
            };

            return(model);
        }