예제 #1
0
        public int Save(UsuarioDto entity)
        {
            var user = new Data.Models.Usuario()
            {
                Nome           = entity.Nome,
                Cpf            = entity.Cpf,
                Email          = entity.Email,
                Sexo           = entity.Sexo,
                Telefone       = entity.Telefone,
                DataNascimento = entity.DataNascimento
            };

            using (WevoDbContext ctx = new WevoDbContext())
            {
                try
                {
                    ctx.Usuarios.Add(user);
                    ctx.SaveChanges();

                    return(user.Id);
                }
                catch (Exception ex)
                {
                    throw new Exception(string.Format("Erro ao incluir o usuário. {0}.", ex.ToString()));
                }
            }
        }
예제 #2
0
        public void Update(UsuarioDto entity)
        {
            var user = new Data.Models.Usuario()
            {
                Id             = entity.Id,
                Nome           = entity.Nome,
                Cpf            = entity.Cpf,
                Email          = entity.Email,
                Sexo           = entity.Sexo,
                Telefone       = entity.Telefone,
                DataNascimento = entity.DataNascimento
            };

            using (WevoDbContext ctx = new WevoDbContext())
            {
                try
                {
                    ctx.Usuarios.Attach(user);
                    ctx.Entry(user).State = EntityState.Modified;
                    ctx.SaveChanges();
                }
                catch (Exception ex)
                {
                    throw new Exception(string.Format("Erro ao atualizar o usuário. {0}.", ex.ToString()));
                }
            }
        }