private TRANSAZIONE SaveTransazionePerVenditore(DatabaseContext db, PERSONA venditore, CORRIERE_SERVIZIO_SPEDIZIONE spedizione)
        {
            // compratore paga venditore
            TRANSAZIONE transazione = new TRANSAZIONE();

            transazione.ID_CONTO_MITTENTE     = this.PERSONA.ID_CONTO_CORRENTE;
            transazione.ID_CONTO_DESTINATARIO = venditore.ID_CONTO_CORRENTE;
            transazione.NOME = Language.BuyTransaction + " " + this.ANNUNCIO.NOME;
            if (transazione.NOME.Length > 100)
            {
                transazione.NOME = transazione.NOME.Substring(0, 99);
            }
            transazione.PUNTI            = this.PUNTI;
            transazione.SOLDI            = Utility.cambioValuta(this.PUNTI);
            transazione.TIPO             = (int)TipoPagamento.HAPPY;
            transazione.DATA_INSERIMENTO = DateTime.Now;
            transazione.TEST             = 0;
            transazione.STATO            = (int)StatoPagamento.ACCETTATO;
            db.TRANSAZIONE.Add(transazione);
            if (db.SaveChanges() <= 0)
            {
                throw new Exception(string.Format(ExceptionMessage.NotSavedBidTransaction, this.ID));
            }

            TRANSAZIONE_ANNUNCIO transazioneAnnuncio = new Models.TRANSAZIONE_ANNUNCIO();

            transazioneAnnuncio.ID_TRANSAZIONE = transazione.ID;
            transazioneAnnuncio.ID_ANNUNCIO    = this.ID_ANNUNCIO;
            transazioneAnnuncio.PUNTI          = (decimal)transazione.PUNTI;
            transazioneAnnuncio.SOLDI          = (decimal)transazione.SOLDI;
            if (spedizione != null)
            {
                transazioneAnnuncio.PUNTI_SPEDIZIONE = (decimal)spedizione.PUNTI;
                transazioneAnnuncio.SOLDI_SPEDIZIONE = (decimal)spedizione.SOLDI;
            }
            transazioneAnnuncio.DATA_INSERIMENTO = DateTime.Now;
            transazioneAnnuncio.STATO            = (int)StatoPagamento.ACCETTATO;
            db.TRANSAZIONE_ANNUNCIO.Add(transazioneAnnuncio);
            if (db.SaveChanges() <= 0)
            {
                throw new Exception(string.Format(ExceptionMessage.NotSavedBidTransaction, this.ID));
            }

            return(transazione);
        }
Beispiel #2
0
        public bool SalvaRegistrazione(ControllerContext controller, DatabaseContext db)
        {
            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(this.Password.Trim(), persona.TOKEN_PASSWORD);
            //persona.NOME = this.Nome.Trim();
            //persona.COGNOME = this.Cognome.Trim();
            persona.ID_CONTO_CORRENTE = conto.ID;
            persona.ID_ABBONAMENTO    = db.ABBONAMENTO.SingleOrDefault(item => item.NOME == "BASE").ID;
            persona.DATA_INSERIMENTO  = DateTime.Now;
            persona.STATO             = (int)Stato.INATTIVO;
            db.PERSONA.Add(persona);
            if (db.SaveChanges() > 0)
            {
                PERSONA_EMAIL personaEmail = db.PERSONA_EMAIL.Create();
                personaEmail.ID_PERSONA       = persona.ID;
                personaEmail.EMAIL            = this.Email.Trim();
                personaEmail.TIPO             = (int)TipoEmail.Registrazione;
                personaEmail.DATA_INSERIMENTO = DateTime.Now;
                personaEmail.STATO            = (int)Stato.INATTIVO;
                db.PERSONA_EMAIL.Add(personaEmail);

                if (db.SaveChanges() > 0)
                {
                    InvioEmail(controller, persona, personaEmail);
                    return(true);
                }
            }
            return(false);
        }
        public void SendEmail(System.Web.Mvc.ControllerContext controller, TRANSAZIONE pagamento, PersonaModel utente)
        {
            PERSONA venditore = pagamento.CONTO_CORRENTE.PERSONA.SingleOrDefault();

            // impostare invio email pagamento effettuato
            EmailModel email = new EmailModel(controller);

            email.To.Add(new System.Net.Mail.MailAddress(venditore.PERSONA_EMAIL.SingleOrDefault(e => e.TIPO == (int)TipoEmail.Registrazione).EMAIL));
            string nominativo = utente.Persona.NOME + " " + utente.Persona.COGNOME;

            email.Subject   = String.Format(Email.PaymentSubject, pagamento.NOME, nominativo) + " - " + WebConfigurationManager.AppSettings["nomeSito"];
            email.Body      = "Pagamento";
            email.DatiEmail = new SchedaPagamentoViewModel()
            {
                Nome       = pagamento.NOME,
                Compratore = nominativo,
                Venditore  = venditore.NOME + " " + venditore.COGNOME,
                Punti      = (int)pagamento.PUNTI,
                Soldi      = (int)pagamento.SOLDI,
                Data       = pagamento.DATA_INSERIMENTO,
            };
            new EmailController().SendEmail(email);
        }
 public UtenteVenditaViewModel(PERSONA model)
 {
     LoadPersona(model);
     Tipo = TipoVenditore.Persona;
 }
        public bool SalvaRegistrazione(ControllerContext controller, DatabaseContext db)
        {
            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(this.Password.Trim(), persona.TOKEN_PASSWORD);
            persona.ID_CONTO_CORRENTE = conto.ID;
            persona.ID_ABBONAMENTO    = db.ABBONAMENTO.SingleOrDefault(item => item.NOME == "BASE").ID;
            persona.DATA_INSERIMENTO  = DateTime.Now;
            persona.STATO             = (int)Stato.INATTIVO;

            // solo in caso di accesso con FB
            persona.FACEBOOK_TOKEN_SESSIONE   = FacebookToken;
            persona.FACEBOOK_TOKEN_PERMANENTE = FacebookTokenPermanente;
            if (!string.IsNullOrWhiteSpace(this.Nome))
            {
                persona.NOME = this.Nome.Trim();
            }
            if (!string.IsNullOrWhiteSpace(this.Cognome))
            {
                persona.COGNOME = this.Cognome.Trim();
            }

            db.PERSONA.Add(persona);
            if (db.SaveChanges() > 0)
            {
                PERSONA_EMAIL personaEmail = db.PERSONA_EMAIL.Create();
                personaEmail.ID_PERSONA       = persona.ID;
                personaEmail.EMAIL            = this.Email.Trim();
                personaEmail.TIPO             = (int)TipoEmail.Registrazione;
                personaEmail.DATA_INSERIMENTO = DateTime.Now;
                personaEmail.STATO            = (int)Stato.INATTIVO;
                db.PERSONA_EMAIL.Add(personaEmail);

                if (db.SaveChanges() > 0)
                {
                    PersonaModel utente = new PersonaModel(persona);
                    // assegna bonus canale pubblicitario
                    if (HttpContext.Current.Request.Cookies.Get("GXG_promo") != null)
                    {
                        string promo = HttpContext.Current.Request.Cookies.Get("GXG_promo").Value;
                        utente.AddBonusCanalePubblicitario(db, promo);
                        // reset cookie
                        HttpCookie currentUserCookie = HttpContext.Current.Request.Cookies["GXG_promo"];
                        if (currentUserCookie != null)
                        {
                            HttpContext.Current.Response.Cookies.Remove("GXG_promo");
                            currentUserCookie.Expires = DateTime.Now.AddDays(-10);
                            currentUserCookie.Value   = null;
                            HttpContext.Current.Response.SetCookie(currentUserCookie);
                        }
                    }

                    InvioEmail(controller, persona, personaEmail);
                    return(true);
                }
            }
            return(false);
        }
        public UtenteProfiloViewModel(DatabaseContext db, int id)
        {
            PERSONA persona = persona = db.PERSONA.FirstOrDefault(u => u.ID == id);

            Load(db, persona);
        }
        public UtenteProfiloViewModel(DatabaseContext db, string token)
        {
            PERSONA persona = db.PERSONA.FirstOrDefault(u => u.TOKEN.ToString() == token);

            Load(db, persona);
        }
Beispiel #8
0
 public OffertaModel(int id, PERSONA venditore)
 {
     this.ID = id;
     this.ANNUNCIO.ID_PERSONA = venditore.ID;
 }
        public bool Accetta(DatabaseContext db, PERSONA venditore, int?idPayPal, ref string messaggio)
        {
            DateTime dataModifica = DateTime.Now;

            TipoScambio tipoScambio = TipoScambio.AMano;

            if (this.OFFERTA_SPEDIZIONE.Count() > 0)
            {
                tipoScambio = TipoScambio.Spedizione;
            }

            // verifico la possibilità di acquisto del compratore
            VerificaAcquisto statoAcquisto = AnnuncioModel.CheckAcquisto(this.PERSONA, this.PERSONA.CONTO_CORRENTE.CONTO_CORRENTE_CREDITO.ToList(), tipoScambio, false, true);

            if (statoAcquisto == VerificaAcquisto.Ok)
            {
                this.ANNUNCIO.DATA_VENDITA = dataModifica;
                this.ANNUNCIO.STATO        = (int)StatoVendita.VENDUTO;
            }
            else if (statoAcquisto == VerificaAcquisto.VerificaCartaCredito)
            {
                this.ANNUNCIO.DATA_VENDITA = dataModifica;
                this.ANNUNCIO.STATO        = (int)StatoVendita.BARATTOINCORSO;
            }
            else if (statoAcquisto != VerificaAcquisto.VerificaCartaCredito && statoAcquisto != VerificaAcquisto.SpedizioneDaPagare)
            {
                // se il compratore non può acquistare annuncio
                return(false);
            }

            this.ANNUNCIO.DATA_MODIFICA = dataModifica;
            this.ANNUNCIO.ID_COMPRATORE = this.PERSONA.ID;
            db.ANNUNCIO.Attach(this.OffertaOriginale.ANNUNCIO);
            db.Entry(this.OffertaOriginale.ANNUNCIO).State = System.Data.Entity.EntityState.Modified;

            // salvataggio offerta
            this.SESSIONE_COMPRATORE = null;
            this.DATA_MODIFICA       = dataModifica;
            this.STATO = (int)StatoOfferta.ACCETTATA;
            this.OffertaOriginale.STATO               = this.STATO;
            this.OffertaOriginale.DATA_MODIFICA       = this.DATA_MODIFICA;
            this.OffertaOriginale.SESSIONE_COMPRATORE = this.SESSIONE_COMPRATORE;
            db.OFFERTA.Attach(this.OffertaOriginale);
            db.Entry(this.OffertaOriginale).State = System.Data.Entity.EntityState.Modified;

            int salvataggi = db.SaveChanges();

            if (salvataggi > 1)
            {
                CORRIERE_SERVIZIO_SPEDIZIONE spedizioneVenditore  = null;
                ANNUNCIO_TIPO_SCAMBIO        tipoScambioVenditore = this.ANNUNCIO.ANNUNCIO_TIPO_SCAMBIO
                                                                    .FirstOrDefault(m => m.TIPO_SCAMBIO == (int)tipoScambio);
                tipoScambioVenditore.DATA_MODIFICA = DateTime.Now;
                tipoScambioVenditore.STATO         = (int)StatoScambio.SELEZIONATO;
                db.ANNUNCIO_TIPO_SCAMBIO.Attach(tipoScambioVenditore);
                db.Entry(tipoScambioVenditore).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
                // salvataggio spedizione
                if (tipoScambio == TipoScambio.Spedizione)
                {
                    var tipoScambioSpedizioneVenditore = tipoScambioVenditore.ANNUNCIO_TIPO_SCAMBIO_SPEDIZIONE.FirstOrDefault();

                    spedizioneVenditore = db.CORRIERE_SERVIZIO_SPEDIZIONE.FirstOrDefault(m => m.ID == tipoScambioSpedizioneVenditore.ID_CORRIERE_SERVIZIO_SPEDIZIONE);
                    var offertaSpedizione = this.OFFERTA_SPEDIZIONE.FirstOrDefault();
                    spedizioneVenditore.ID_INDIRIZZO_DESTINATARIO = offertaSpedizione.ID_INDIRIZZO_DESTINATARIO;
                    spedizioneVenditore.NOMINATIVO_DESTINATARIO   = offertaSpedizione.NOMINATIVO_DESTINATARIO;
                    spedizioneVenditore.TELEFONO_DESTINATARIO     = offertaSpedizione.TELEFONO_DESTINATARIO;
                    spedizioneVenditore.INFO_EXTRA_DESTINATARIO   = offertaSpedizione.INFO_EXTRA;
                    spedizioneVenditore.STATO = (int)StatoSpedizione.SOSPESA;
                    //db.CORRIERE_SERVIZIO_SPEDIZIONE.Attach(spedizioneVenditore);
                    db.SaveChanges();
                }

                TRANSAZIONE transazione = SaveTransazionePerVenditore(db, venditore, spedizioneVenditore);
                // tolgo i punti al mittente
                DoPagamento(db, transazione);
                int?idTransazionePerAcquirente = SaveTransazionePerAcquirente(db, venditore, idPayPal);
                // cambio stato dei baratti offerti
                for (int i = 0; i < this.OffertaOriginale.OFFERTA_BARATTO.Count(); i++)
                {
                    var baratto = this.OffertaOriginale.OFFERTA_BARATTO.ToList()[i];
                    DoBaratto(db, ref baratto, dataModifica, idTransazionePerAcquirente);
                }
                AnnullaOfferteEffettuate(db, this.ID_ANNUNCIO);
                AnnullaOfferteRicevute(db, this.ID_ANNUNCIO, this.ID);

                this.STATO = this.STATO;
                return(true);
            }
            return(false);
        }
Beispiel #10
0
 public PersonaModel(PERSONA model)
 {
     this.Persona = model;
     this.SetValoriBase();
 }