public bool Save(CurriculumModel objCurriculum)
        {
            using (var con = new PortalEntities())
            {
                tb_curriculum objDbCurriculum = new tb_curriculum
                        {
                            idUsuario = objCurriculum.idUsuario,
                            xAtividadesComplementares = objCurriculum.xAtividadesComplementares,
                            xBairro = objCurriculum.xBairro,
                            xCelular = objCurriculum.xCelular,
                            xCidade = objCurriculum.xCidade,
                            xCompetencias = objCurriculum.xCompetencias,
                            xEmail = objCurriculum.xEmail,
                            xEndereco = objCurriculum.xEndereco,
                            xEstado = objCurriculum.xEstado,
                            xExperiencia = objCurriculum.xExperiencia,
                            xFormacao = objCurriculum.xFormacao,
                            xInformacoesComplementares = objCurriculum.xInformacoesComplementares,
                            xNome = objCurriculum.xNome,
                            xObjetivo = objCurriculum.xObjetivo,
                            xSobreMim = objCurriculum.xSobreMim,
                            xTelefone = objCurriculum.xTelefone
                        };

                if (objCurriculum.idCurriculumVitae == 0)
                {
                    con.tb_curriculum.Add(entity: objDbCurriculum);
                }
                else
                {
                    con.tb_curriculum.Attach(entity: objDbCurriculum);
                    con.Entry(entity: objDbCurriculum).State = System.Data.EntityState.Modified;
                }
                try
                {
                    con.SaveChanges();
                    objCurriculum.idCurriculumVitae = objDbCurriculum.idCurriculumVitae;
                    return true;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
        public bool Save(SoliciteContatoModel obj)
        {
            using (var con = new PortalEntities())
            {
                tb_solicitecontato objTbSolicitacao = new tb_solicitecontato
                    {
                        stObjetivo = obj.stObjetivo,
                        xCelular = obj.xCelular,
                        xEmail = obj.xEmail,
                        xMessage = obj.xMessage,
                        xTelefone = obj.xTelefone,
                        xNomeEmpresa = obj.xNomeEmpresa,
                        stContatoPreferencial = obj.stContatoPreferencial
                    };

                con.tb_solicitecontato.Add(entity:
                    objTbSolicitacao);

                try
                {
                    con.SaveChanges();
                    obj.idSolicitacao = objTbSolicitacao.idSoliciteContato;
                    return true;
                }
                catch (DbEntityValidationException e)
                {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                            eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                ve.PropertyName, ve.ErrorMessage);
                        }
                    }
                    throw;
                }
            }
        }
Esempio n. 3
0
        public bool Save(UserModel user)
        {
            try
            {
                using (var db = new PortalEntities())
                {
                    tb_usuario u = new tb_usuario();
                    if (user.idUsuario == null)
                    {
                        SetPassword(user, u);
                        u.xUserName = user.xUserName;
                        u.xFullName = user.xFullName;
                        db.tb_usuario.Add(u);

                        foreach (var prov in user.providers)
                        {
                            u.tb_providers.Add(new tb_providers
                            {
                                idUsuario = u.idUsuario,
                                Provider = prov.Provider,
                                ProviderUserId = prov.ProviderUserId
                            });
                        }

                    }
                    else
                    {
                        u = db.tb_usuario.FirstOrDefault(c => c.xUserName == user.xUserName);
                        SetPassword(user, u);
                        u.xUserName = user.xUserName;
                        u.xFullName = user.xFullName;

                        foreach (var prov in user.providers)
                        {
                            tb_providers provider = null;
                            if (u.tb_providers.Where(c => c.ProviderUserId == prov.ProviderUserId).Count() > 0)
                            {
                                provider = u.tb_providers.FirstOrDefault(c => c.ProviderUserId == prov.ProviderUserId);
                                provider.ProviderUserId = prov.ProviderUserId;
                                provider.Provider = prov.Provider;
                                provider.idUsuario = prov.idUsuario;
                            }
                            else
                            {
                                provider = new tb_providers();
                                provider.ProviderUserId = prov.ProviderUserId;
                                provider.Provider = prov.Provider;
                                provider.idUsuario = prov.idUsuario;
                                u.tb_providers.Add(provider);
                            }
                        }
                    }
                    db.SaveChanges();
                }
                return true;
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                        eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                            ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
        }