public ActionResult Impostazioni() { PersonaModel utente = base.Session["utente"] as PersonaModel; UtenteImpostazioniViewModel model = new UtenteImpostazioniViewModel(); using (DatabaseContext db = new DatabaseContext()) { utente.Persona = db.PERSONA.FirstOrDefault(u => u.ID == utente.Persona.ID); model.Email = utente.Email.SingleOrDefault(item => item.ID_PERSONA == utente.Persona.ID && item.TIPO == (int)TipoEmail.Registrazione) .EMAIL; model.Nome = utente.Persona.NOME; model.Cognome = utente.Persona.COGNOME; PERSONA_TELEFONO modelTelefono = utente.Telefono.SingleOrDefault(item => item.ID_PERSONA == utente.Persona.ID && item.TIPO == (int)TipoTelefono.Privato); if (modelTelefono != null) { model.Telefono = modelTelefono.TELEFONO; } PERSONA_INDIRIZZO modelIndirizzo = utente.Indirizzo.SingleOrDefault(item => item.ID_PERSONA == utente.Persona.ID && item.TIPO == (int)TipoIndirizzo.Residenza); if (modelIndirizzo != null && modelIndirizzo.INDIRIZZO != null) { model.Citta = modelIndirizzo.INDIRIZZO.COMUNE.NOME; model.IDCitta = modelIndirizzo.INDIRIZZO.ID_COMUNE; model.Indirizzo = modelIndirizzo.INDIRIZZO.INDIRIZZO1; model.Civico = modelIndirizzo.INDIRIZZO.CIVICO; } } return(base.View(model)); }
public ActionResult Registrazione(UtenteRegistrazioneViewModel model) { if (base.ModelState.IsValid) { using (DatabaseContext db = new DatabaseContext()) { using (DbContextTransaction transazione = db.Database.BeginTransaction()) { try { CONTO_CORRENTE conto = db.CONTO_CORRENTE.Create(); conto.ID = Guid.NewGuid(); conto.TOKEN = Guid.NewGuid(); conto.DATA_INSERIMENTO = DateTime.Now; conto.STATO = (int)Stato.ATTIVO; db.CONTO_CORRENTE.Add(conto); db.SaveChanges(); PBKDF2 crypto = new PBKDF2(); PERSONA persona = db.PERSONA.Create(); persona.TOKEN = Guid.NewGuid(); persona.TOKEN_PASSWORD = crypto.GenerateSalt(1, 20); persona.PASSWORD = crypto.Compute(model.Password.Trim(), persona.TOKEN_PASSWORD); persona.NOME = model.Nome.Trim(); persona.COGNOME = model.Cognome.Trim(); persona.ID_CONTO_CORRENTE = conto.ID; persona.ID_ABBONAMENTO = db.ABBONAMENTO.SingleOrDefault(item => item.NOME == "BASE").ID; persona.DATA_INSERIMENTO = DateTime.Now; db.PERSONA.Add(persona); if (db.SaveChanges() > 0) { PERSONA_EMAIL personaEmail = db.PERSONA_EMAIL.Create(); personaEmail.ID_PERSONA = persona.ID; personaEmail.EMAIL = model.Email.Trim(); personaEmail.TIPO = (int)TipoEmail.Registrazione; personaEmail.DATA_INSERIMENTO = DateTime.Now; personaEmail.STATO = (int)Stato.ATTIVO; db.PERSONA_EMAIL.Add(personaEmail); if (!string.IsNullOrWhiteSpace(model.Telefono)) { PERSONA_TELEFONO personaTelefono = db.PERSONA_TELEFONO.Create(); personaTelefono.ID_PERSONA = persona.ID; personaTelefono.TELEFONO = model.Telefono; personaTelefono.TIPO = (int)TipoTelefono.Privato; personaTelefono.DATA_INSERIMENTO = DateTime.Now; personaTelefono.STATO = (int)Stato.ATTIVO; db.PERSONA_TELEFONO.Add(personaTelefono); } PERSONA_PRIVACY personaPrivacy = db.PERSONA_PRIVACY.Create(); personaPrivacy.ID_PERSONA = persona.ID; personaPrivacy.ACCETTA_CONDIZIONE = model.AccettaCondizioni; personaPrivacy.DATA_INSERIMENTO = DateTime.Now; personaPrivacy.STATO = (int)Stato.ATTIVO; db.PERSONA_PRIVACY.Add(personaPrivacy); db.SaveChanges(); base.TempData["salvato"] = true; // invio email registrazione EmailModel email = new EmailModel(ControllerContext); email.To.Add(new System.Net.Mail.MailAddress(personaEmail.EMAIL, persona.NOME + " " + persona.COGNOME)); email.Subject = Email.RegistrationSubject + " - " + WebConfigurationManager.AppSettings["nomeSito"]; email.Body = "RegistrazioneUtente"; email.DatiEmail = new RegistrazioneEmailModel(model) { PasswordCodificata = persona.PASSWORD }; new EmailController().SendEmail(email); transazione.Commit(); return(View()); } } catch (Exception exception) { transazione.Rollback(); Elmah.ErrorSignal.FromCurrentContext().Raise(exception); } } } } base.ModelState.AddModelError("Errore", Language.ErrorRegister); return(View(model)); }
public ActionResult Effettuate(int pagina = 1) { List <OffertaEffettuataViewModel> offerte = new List <OffertaEffettuataViewModel>(); try { using (DatabaseContext db = new DatabaseContext()) { int utente = ((PersonaModel)Session["utente"]).Persona.ID; // verifica stato offerta se attivo o non accettata, identità utente e stato di attivazione, presenza bene o servizio -- vechia // verifica identità utente e stato di attivazione, presenza bene o servizio var query = db.OFFERTA.Where(item => item.PERSONA.ID == utente && item.PERSONA.STATO == (int)Stato.ATTIVO && (item.ANNUNCIO.ID_OGGETTO != null || item.ANNUNCIO.ID_SERVIZIO != null)); int numeroElementi = Convert.ToInt32(WebConfigurationManager.AppSettings["numeroElementi"]); ViewData["TotalePagine"] = (int)Math.Ceiling((decimal)query.Count() / (decimal)numeroElementi); ViewData["Pagina"] = pagina; pagina -= 1; string randomString = Utils.RandomString(3); List <OFFERTA> lista = query .OrderByDescending(item => item.DATA_INSERIMENTO) .Skip(pagina * numeroElementi) .Take(numeroElementi).ToList(); foreach (OFFERTA item in lista) { OffertaEffettuataViewModel offertaEffettuata = new OffertaEffettuataViewModel(); offertaEffettuata.Id = item.ID.ToString(); offertaEffettuata.Nome = item.ANNUNCIO.NOME; offertaEffettuata.Venditore = (item.ANNUNCIO.ID_ATTIVITA != null) ? item.ANNUNCIO.ATTIVITA.NOME : item.ANNUNCIO.PERSONA.NOME + ' ' + item.ANNUNCIO.PERSONA.COGNOME; offertaEffettuata.Email = (item.ANNUNCIO.ID_ATTIVITA != null) ? item.ANNUNCIO.ATTIVITA.ATTIVITA_EMAIL.SingleOrDefault(e => e.TIPO == (int)TipoEmail.Registrazione).EMAIL : item.ANNUNCIO.PERSONA.PERSONA_EMAIL.SingleOrDefault(e => e.TIPO == (int)TipoEmail.Registrazione).EMAIL; offertaEffettuata.VenditoreToken = item.ANNUNCIO.PERSONA.TOKEN; if (item.ANNUNCIO.ID_ATTIVITA != null) { ATTIVITA_TELEFONO telefono = item.ANNUNCIO.ATTIVITA.ATTIVITA_TELEFONO.SingleOrDefault(t => t.TIPO == (int)TipoTelefono.Privato); if (telefono != null) { offertaEffettuata.Telefono = telefono.TELEFONO; } } else { PERSONA_TELEFONO telefono = item.ANNUNCIO.PERSONA.PERSONA_TELEFONO.SingleOrDefault(t => t.TIPO == (int)TipoTelefono.Privato); if (telefono != null) { offertaEffettuata.Telefono = telefono.TELEFONO; } } offertaEffettuata.Punti = (int)item.PUNTI; offertaEffettuata.Soldi = (int)item.SOLDI; offertaEffettuata.Categoria = item.ANNUNCIO.CATEGORIA.NOME; offertaEffettuata.Foto = db.ANNUNCIO_FOTO .Where(f => f.ID_ANNUNCIO == item.ANNUNCIO.ID) .Select(f => f.FOTO.FOTO1 ).ToList(); offertaEffettuata.Baratti = db.OFFERTA_BARATTO .Where(b => b.ID_OFFERTA == item.ID && b.ANNUNCIO != null) .Select(b => new VenditaViewModel() { Token = randomString + b.ANNUNCIO.TOKEN.ToString() + randomString, TipoAcquisto = b.ANNUNCIO.SERVIZIO != null ? TipoAcquisto.Servizio : TipoAcquisto.Oggetto, Nome = b.ANNUNCIO.NOME, Punti = b.ANNUNCIO.PUNTI, Soldi = b.ANNUNCIO.SOLDI, }).ToList(); offertaEffettuata.Token = item.ANNUNCIO.TOKEN.ToString(); offertaEffettuata.TipoOfferta = (TipoOfferta)item.TIPO_OFFERTA; offertaEffettuata.TipoTrattativa = (TipoTrattativa)item.TIPO_TRATTATIVA; offertaEffettuata.TipoPagamento = (TipoPagamento)item.ANNUNCIO.TIPO_PAGAMENTO; offertaEffettuata.StatoOfferta = (StatoOfferta)item.STATO; offertaEffettuata.StatoVendita = (StatoVendita)item.ANNUNCIO.STATO; offertaEffettuata.DataInserimento = (DateTime)item.DATA_INSERIMENTO; offerte.Add(offertaEffettuata); } if (offerte.Count > 0) { RefreshPunteggioUtente(db); } } } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); } return(View(offerte)); }