// VERIFICARE CHE L'ASSEGNAZIONE DELLA MONETA VADA A BUON FINE E CHE QUINDI LA TRANSAZIONE
        // ABBIA EFFETTO
        protected void AddBonus(DatabaseContext db, PERSONA persona, Guid tokenPortale, int punti, TipoTransazione tipo, string nomeTransazione, int?idAnnuncio = null)
        {
            TRANSAZIONE model = new TRANSAZIONE();

            model.ID_CONTO_MITTENTE     = db.ATTIVITA.Where(p => p.TOKEN == tokenPortale).SingleOrDefault().ID_CONTO_CORRENTE;
            model.ID_CONTO_DESTINATARIO = persona.ID_CONTO_CORRENTE;
            model.TIPO             = (int)tipo;
            model.NOME             = nomeTransazione;
            model.PUNTI            = punti;
            model.DATA_INSERIMENTO = DateTime.Now;
            model.STATO            = (int)StatoPagamento.ACCETTATO;
            model.ID_ANNUNCIO      = idAnnuncio;
            db.TRANSAZIONE.Add(model);
            db.SaveChanges();
            // genero la moneta ogni volta che offro un bonus, in modo da mantenere la concorrenza dei dati
            for (int i = 0; i < punti; i++)
            {
                MONETA moneta = db.MONETA.Create();
                moneta.VALORE           = 1;
                moneta.TOKEN            = Guid.NewGuid();
                moneta.DATA_INSERIMENTO = DateTime.Now;
                moneta.STATO            = (int)Stato.ATTIVO;
                db.MONETA.Add(moneta);
                db.SaveChanges();
                CONTO_CORRENTE_MONETA conto = new CONTO_CORRENTE_MONETA();
                conto.ID_CONTO_CORRENTE = persona.ID_CONTO_CORRENTE;
                conto.ID_MONETA         = moneta.ID;
                conto.ID_TRANSAZIONE    = model.ID;
                conto.DATA_INSERIMENTO  = DateTime.Now;
                conto.STATO             = (int)StatoMoneta.ASSEGNATA;
                db.CONTO_CORRENTE_MONETA.Add(conto);
                db.SaveChanges();
            }
        }
예제 #2
0
        // VERIFICARE CHE L'ASSEGNAZIONE DELLA MONETA VADA A BUON FINE E CHE QUINDI LA TRANSAZIONE
        // ABBIA EFFETTO
        public void AddBonus(DatabaseContext db, ControllerContext controller, PERSONA persona, Guid tokenPortale, decimal punti, TipoTransazione tipo, string nomeTransazione, int?idAnnuncio = null)
        {
            ATTIVITA         attivita     = db.ATTIVITA.Where(p => p.TOKEN == tokenPortale).SingleOrDefault();
            PERSONA_ATTIVITA proprietario = attivita.PERSONA_ATTIVITA.SingleOrDefault(m => m.RUOLO == (int)RuoloProfilo.Proprietario && m.STATO == (int)Stato.ATTIVO);
            PERSONA          mittente     = null;

            if (proprietario != null)
            {
                mittente = proprietario.PERSONA;
            }
            TRANSAZIONE model = new TRANSAZIONE();

            model.ID_CONTO_MITTENTE     = attivita.ID_CONTO_CORRENTE;
            model.ID_CONTO_DESTINATARIO = persona.ID_CONTO_CORRENTE;
            model.TIPO             = (int)tipo;
            model.NOME             = nomeTransazione;
            model.PUNTI            = punti;
            model.DATA_INSERIMENTO = DateTime.Now;
            model.STATO            = (int)StatoPagamento.ACCETTATO;
            db.TRANSAZIONE.Add(model);
            db.SaveChanges();

            if (idAnnuncio != null)
            {
                TRANSAZIONE_ANNUNCIO transazioneAnnuncio = new Models.TRANSAZIONE_ANNUNCIO();
                transazioneAnnuncio.ID_TRANSAZIONE   = model.ID;
                transazioneAnnuncio.ID_ANNUNCIO      = (int)idAnnuncio;
                transazioneAnnuncio.PUNTI            = punti;
                transazioneAnnuncio.SOLDI            = Utility.cambioValuta(transazioneAnnuncio.PUNTI);
                transazioneAnnuncio.DATA_INSERIMENTO = DateTime.Now;
                transazioneAnnuncio.STATO            = (int)StatoPagamento.ACCETTATO;
                db.TRANSAZIONE_ANNUNCIO.Add(transazioneAnnuncio);
                db.SaveChanges();
            }

            // aggiunta credito
            ContoCorrenteCreditoModel credito = new ContoCorrenteCreditoModel(db, persona.ID_CONTO_CORRENTE);

            credito.Earn(model.ID, punti);

            BonusRicevutoViewModel modelEmail = new BonusRicevutoViewModel();

            modelEmail.Nome = model.NOME;
            modelEmail.NominativoDestinatario = persona.NOME + " " + persona.COGNOME;
            modelEmail.Bonus = Convert.ToDecimal(model.PUNTI).ToHappyCoin();

            SendNotifica(mittente, persona, TipoNotifica.Bonus, controller, "bonusRicevuto", modelEmail, attivita, db);
            TempData["BONUS"] = string.Format(Bonus.YouWin, punti, Language.Moneta);

            if (tipo != TipoTransazione.BonusLogin)
            {
                RefreshPunteggioUtente(db);
            }
        }
        public ActionResult Inviato(int id, bool nuovo = false)
        {
            FeedbackViewModel viewModel = new FeedbackViewModel();

            using (DatabaseContext db = new DatabaseContext())
            {
                try
                {
                    db.Database.Connection.Open();
                    PersonaModel      utente = (Session["utente"] as PersonaModel);
                    ANNUNCIO_FEEDBACK model  = db.ANNUNCIO_FEEDBACK.Include("Annuncio.Persona").Where(f => f.ID == id && f.ID_VOTANTE == utente.Persona.ID).SingleOrDefault();
                    viewModel.Ricevente = model.ANNUNCIO.PERSONA.NOME + ' ' + model.ANNUNCIO.PERSONA.COGNOME;
                    // AGGIUNGERE SALVATAGGIO ATTIVITà IN CASO SIA UN'AZIENDA A RILASCIARE IL FEEDBACK
                    viewModel.Voto      = model.VOTO;
                    viewModel.Opinione  = model.COMMENTO;
                    viewModel.Nome      = model.ANNUNCIO.NOME;
                    viewModel.DataInvio = model.DATA_INSERIMENTO;
                    if (nuovo)
                    {
                        ViewBag.Title = string.Format(Language.TitleSendFeedback, viewModel.Ricevente);
                    }
                    else
                    {
                        ViewBag.Title = string.Format(Language.TitleSendFeedback2, viewModel.Ricevente);
                    }
                    TRANSAZIONE bonusRicevuti = db.TRANSAZIONE.SingleOrDefault(item =>
                                                                               item.ID_CONTO_MITTENTE == utente.Persona.ID_CONTO_CORRENTE &&
                                                                               item.TRANSAZIONE_ANNUNCIO.Count(m => m.ID_ANNUNCIO == model.ID_ANNUNCIO) > 0 &&
                                                                               item.TIPO == (int)TipoTransazione.BonusFeedback);
                    if (bonusRicevuti != null)
                    {
                        viewModel.PuntiBonus = (int)bonusRicevuti.PUNTI;
                    }
                }
                catch (Exception eccezione)
                {
                    //Elmah.ErrorSignal.FromCurrentContext().Raise(eccezione);
                    LoggatoreModel.Errore(eccezione);
                    // se ha un errore generico o semplicemente sta cercando di fare un feedback
                    return(Redirect(System.Web.Security.FormsAuthentication.DefaultUrl));
                }
                finally
                {
                    if (db.Database.Connection.State != System.Data.ConnectionState.Closed)
                    {
                        db.Database.Connection.Close();
                        db.Database.Connection.Dispose();
                    }
                }
            }
            return(View(viewModel));
        }
 public ActionResult Definitivo(List <string> acquisti)
 {
     using (DatabaseContext db = new DatabaseContext())
     {
         try
         {
             db.Database.Connection.Open();
             foreach (string acquisto in acquisti)
             {
                 PagamentoModel model       = new PagamentoModel();
                 PersonaModel   utente      = Session["utente"] as PersonaModel;
                 int?           idPagamento = model.eseguiFromStoredProcedure(acquisto, utente);
                 if (idPagamento != null)
                 {
                     TRANSAZIONE pagamento = db.TRANSAZIONE.Include("CONTO_CORRENTE.PERSONA.PERSONA_EMAIL").Where(p => p.ID == idPagamento).SingleOrDefault();
                     // aggiorno punti attuali utente
                     Session["utente"] = new PersonaModel(db.PERSONA.Where(u => u.ID == utente.Persona.ID).FirstOrDefault());
                     model.SendEmail(ControllerContext, pagamento, utente);
                     return(Json(new { Messaggio = Language.CompletedPurchase }));
                 }
                 else
                 {
                     return(Json(model.Errore.ToString()));
                 }
             }
         }
         catch (Exception ex)
         {
             //Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
             LoggatoreModel.Errore(ex);
             // log errore, invio mail
             Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest;
             return(Json(ex.ToString()));
         }
         finally
         {
             if (db.Database.Connection.State != System.Data.ConnectionState.Closed)
             {
                 db.Database.Connection.Close();
             }
         }
     }
     Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest;
     return(Json(Language.ErrorPayment));
 }
예제 #5
0
        private decimal AddBonus(DatabaseContext db, PersonaModel utente, PubblicazioneViewModel viewModel)
        {
            bool    risultato             = false;
            decimal numeroPuntiGuadagnati = 0;

            // verifico se dare un bonus dopo un certo numero di pubblicazioni
            Guid portale         = Guid.Parse(ConfigurationManager.AppSettings["portaleweb"]);
            Guid idContoCorrente = db.ATTIVITA.SingleOrDefault(p => p.TOKEN == portale).ID_CONTO_CORRENTE;
            int  numeroVendite   = db.ANNUNCIO.Where(v => v.ID_PERSONA == utente.Persona.ID).GroupBy(v => v.ID_CATEGORIA).Count();

            // aggiunge il bonus sui primi tot. annunci iniziali
            TRANSAZIONE bonus = db.TRANSAZIONE.Where(b => b.ID_CONTO_MITTENTE == idContoCorrente &&
                                                     b.ID_CONTO_DESTINATARIO == utente.Persona.ID_CONTO_CORRENTE && b.TIPO == (int)TipoTransazione.BonusPubblicazioneIniziale).FirstOrDefault();

            if (numeroVendite == Convert.ToInt32(ConfigurationManager.AppSettings["numeroPubblicazioniBonus"]) &&
                bonus == null)
            {
                decimal puntiBonusIniziali = Convert.ToInt32(ConfigurationManager.AppSettings["bonusPubblicazioniIniziali"]);
                this.AddBonus(db, ControllerContext, utente.Persona, portale, puntiBonusIniziali,
                              TipoTransazione.BonusPubblicazioneIniziale, Bonus.InitialPubblication);
                numeroPuntiGuadagnati += (decimal)puntiBonusIniziali;
                risultato              = risultato | true;
            }

            // aggiunge bonus se l'annuncio è completo di tutti i dati
            if (viewModel.IsAnnuncioCompleto())
            {
                decimal puntiAnnuncioCompleto = Convert.ToInt32(ConfigurationManager.AppSettings["bonusAnnuncioCompleto"]);
                this.AddBonus(db, ControllerContext, utente.Persona, portale, puntiAnnuncioCompleto,
                              TipoTransazione.BonusAnnuncioCompleto, Bonus.FullAnnouncement);
                numeroPuntiGuadagnati += puntiAnnuncioCompleto;
                risultato              = risultato | true;
            }

            return((risultato) ? numeroPuntiGuadagnati : 0);
            //return ((risultato) ? (int)bonus.PUNTI : 0);
        }
        public ActionResult Definitivo_OLD(List <string> acquisti)
        {
            try
            {
                foreach (string acquisto in acquisti)
                {
                    //string token = acquisto.Trim().Substring(3, acquisto.Trim().Length - 6);
                    int idOfferta = Utility.DecodeToInt(acquisto.Trim().Substring(3, acquisto.Trim().Length - 6));
                    using (DatabaseContext db = new DatabaseContext())
                    {
                        PersonaModel utente = Session["utente"] as PersonaModel;
                        System.Data.Entity.Core.Objects.ObjectParameter errore = new System.Data.Entity.Core.Objects.ObjectParameter("Errore", typeof(ErrorePagamento));
                        errore.Value = ErrorePagamento.Nessuno;
                        Guid portaleWeb = Guid.Parse(System.Configuration.ConfigurationManager.AppSettings["portaleweb"]);

                        // DEVO CAMBIARE E FARMI TORNARE IL TRANSAZIONE EFFETTUATO
                        int?idPagamento = db.BENE_SAVE_PAGAMENTO(idOfferta, utente.Persona.ID_CONTO_CORRENTE, errore).FirstOrDefault();
                        if ((ErrorePagamento)errore.Value != ErrorePagamento.Nessuno)
                        {
                            return(Json(errore.Value.ToString()));
                        }
                        if (idPagamento == null)
                        {
                            return(Json(Language.ErrorPayment));
                        }

                        TRANSAZIONE pagamento = db.TRANSAZIONE.Include("CONTO_CORRENTE.PERSONA.PERSONA_EMAIL").Where(p => p.ID == idPagamento).SingleOrDefault();
                        // aggiorno punti attuali utente
                        Session["utente"] = new PersonaModel(db.PERSONA.Where(u => u.ID == utente.Persona.ID).FirstOrDefault());
                        PERSONA venditore = pagamento.CONTO_CORRENTE.PERSONA.SingleOrDefault();
                        // impostare invio email pagamento effettuato
                        EmailModel email = new EmailModel(ControllerContext);
                        email.To.Add(new System.Net.Mail.MailAddress(venditore.PERSONA_EMAIL.SingleOrDefault(e => e.TIPO == (int)TipoEmail.Registrazione).EMAIL));
                        string nominativo = (Session["utente"] as PersonaModel).Persona.NOME + " " + (Session["utente"] as PersonaModel).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);

                        return(Json(new { Messaggio = Language.CompletedPurchase }));
                    }
                }
            }
            catch (Exception ex)
            {
                //Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                LoggatoreModel.Errore(ex);
                // log errore, invio mail
                Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest;
                return(Json(ex.ToString()));
            }
            Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest;
            return(Json(Language.ErrorPayment));
        }
        public ActionResult SavePayment()
        {
            try
            {
                using (DatabaseContext db = new DatabaseContext())
                {
                    SalvataggioPagamentoViewModel datiPagamento = (SalvataggioPagamentoViewModel)Session["pagamento"];
                    if (!ModelState.IsValid)
                    {
                        return(View("Payment", datiPagamento));
                    }

                    // se esiste una sessione pagamento aperta e la mail ricevente dei soldi corrisponde a quella della login,
                    // allora blocco la login e scatta l'errore

                    if (Session["pagamento"] != null && datiPagamento.EmailReceivent.Equals(((PersonaModel)Session["utente"]).Email.FirstOrDefault(item => item.TIPO == (int)TipoEmail.Registrazione)))
                    {
                        ModelState.AddModelError("Error", string.Format(App_GlobalResources.Language.ErrorPaymentUser, datiPagamento.EmailReceivent));
                        return(View("Payment", datiPagamento));
                    }

                    // effettuare il salvataggio
                    TRANSAZIONE pagamento = new TRANSAZIONE();
                    pagamento.NOME = datiPagamento.DescriptionPayment;
                    //pagamento.ID_ATTIVITA = datiPagamento.PortaleWebID;
                    pagamento.SOLDI = (int)datiPagamento.TotalPrice;
                    pagamento.TIPO  = datiPagamento.TypePayment;
                    pagamento.ID_CONTO_DESTINATARIO = (datiPagamento.PortaleWebID != null)? ((ATTIVITA)Session["utente"]).ID_CONTO_CORRENTE : ((PersonaModel)Session["utente"]).Persona.ID_CONTO_CORRENTE;
                    pagamento.ID_CONTO_MITTENTE     = datiPagamento.UtentePagatoID;
                    pagamento.TEST = datiPagamento.Test;

                    db.TRANSAZIONE.Add(pagamento);
                    db.SaveChanges();
                    // impostare invio email pagamento effettuato
                    EmailModel email = new EmailModel(ControllerContext);
                    email.To.Add(new System.Net.Mail.MailAddress(datiPagamento.EmailReceivent, pagamento.CONTO_CORRENTE1.PERSONA.Select(item => item.NOME + ' ' + item.COGNOME).SingleOrDefault()));
                    email.Subject   = string.Format(Email.PaymentFromPartnersSubject, pagamento.NOME, (Session["utente"] as PersonaModel).Persona.NOME + ' ' + (Session["utente"] as PersonaModel).Persona.COGNOME, datiPagamento.Nominativo) + " - " + WebConfigurationManager.AppSettings["nomeSito"];
                    email.Body      = "PagamentoDaPartners";
                    email.DatiEmail = new SchedaPagamentoViewModel()
                    {
                        Nome       = pagamento.NOME,
                        Compratore = (Session["utente"] as PersonaModel).Persona.NOME + ' ' + (Session["utente"] as PersonaModel).Persona.COGNOME,
                        Venditore  = pagamento.CONTO_CORRENTE1.PERSONA.Select(item => item.NOME + ' ' + item.COGNOME).SingleOrDefault(),
                        Punti      = (int)pagamento.PUNTI,
                        Soldi      = (int)pagamento.SOLDI,
                        Data       = pagamento.DATA_INSERIMENTO,
                        Portale    = datiPagamento.Nominativo,
                    };
                    new EmailController().SendEmail(email);
                    RemoveSessionPayment();
                    if (String.IsNullOrEmpty(datiPagamento.ReturnUrlForSuccess))
                    {
                        return(Redirect(datiPagamento.UrlRequest));
                    }
                    else
                    {
                        return(Redirect(datiPagamento.ReturnUrlForSuccess));
                    }
                }
            }
            catch (Exception ex)
            {
                //Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                LoggatoreModel.Errore(ex);
                ModelState.AddModelError("Error", ex);
            }

            return(View("Payment", new PagamentoViewModel((PagamentoAbstractModel)Session["pagamento"])));
        }
        public ActionResult Index(BonificoViewModel viewModel)
        {
            PersonaModel sessioneUtente = Session["utente"] as PersonaModel;

            try
            {
                using (DatabaseContext db = new DatabaseContext())
                {
                    // se esiste una sessione pagamento aperta e la mail ricevente dei soldi corrisponde a quella della login,
                    // allora blocco la login e scatta l'errore
                    CONTO_CORRENTE conto = db.CONTO_CORRENTE.Include("Persona").Include("Attivita").SingleOrDefault(m => m.TOKEN.ToString() == viewModel.Destinatario);

                    if (conto == null)
                    {
                        ModelState.AddModelError("Error", string.Format(Language.ErrorPaymentUser, viewModel.Destinatario));
                        return(View(viewModel));
                    }

                    ContoCorrenteMonetaModel model = new ContoCorrenteMonetaModel();
                    TRANSAZIONE pagamento          = model.Pay(db, sessioneUtente.Persona.ID_CONTO_CORRENTE, conto.ID, viewModel.DescrizionePagamento, viewModel.TipoTransazione, (int)viewModel.Punti);

                    this.RefreshPunteggioUtente(db);

                    // impostare invio email pagamento effettuato
                    try {
                        EmailModel email         = new EmailModel(ControllerContext);
                        string     indirizzoMail = string.Empty;
                        string     nominativo    = string.Empty;
                        // verifico se il destinatario è una persona o attività
                        if (conto.PERSONA.Count > 0)
                        {
                            PERSONA persona = conto.PERSONA.SingleOrDefault(p => p.ID_CONTO_CORRENTE == conto.ID);
                            if (persona != null)
                            {
                                indirizzoMail = db.PERSONA_EMAIL
                                                .SingleOrDefault(m => m.ID_PERSONA == persona.ID &&
                                                                 m.TIPO == (int)TipoEmail.Registrazione).EMAIL;
                            }
                        }
                        else
                        {
                            ATTIVITA attivita = conto.ATTIVITA.SingleOrDefault(p => p.ID_CONTO_CORRENTE == conto.ID);
                            if (attivita != null)
                            {
                                indirizzoMail = db.ATTIVITA_EMAIL
                                                .SingleOrDefault(m => m.ID_ATTIVITA == attivita.ID &&
                                                                 m.TIPO == (int)TipoEmail.Registrazione).EMAIL;
                            }
                        }
                        // se ho trovato l'indirizzo mail
                        if (!string.IsNullOrWhiteSpace(indirizzoMail))
                        {
                            email.To.Add(new System.Net.Mail.MailAddress(indirizzoMail, nominativo));
                            email.Subject   = string.Format(Email.PaymentFromPartnersSubject, pagamento.NOME, (Session["utente"] as PersonaModel).Persona.NOME + ' ' + (Session["utente"] as PersonaModel).Persona.COGNOME, nominativo) + " - " + WebConfigurationManager.AppSettings["nomeSito"];
                            email.Body      = "PagamentoDaPartners";
                            email.DatiEmail = new SchedaPagamentoViewModel()
                            {
                                Nome       = pagamento.NOME,
                                Compratore = (Session["utente"] as PersonaModel).Persona.NOME + ' ' + (Session["utente"] as PersonaModel).Persona.COGNOME,
                                Venditore  = pagamento.CONTO_CORRENTE1.PERSONA.Select(item => item.NOME + ' ' + item.COGNOME).SingleOrDefault(),
                                Punti      = (int)pagamento.PUNTI,
                                //Soldi = (int)pagamento.SOLDI,
                                Data    = pagamento.DATA_INSERIMENTO,
                                Portale = nominativo,
                            };
                            new EmailController().SendEmail(email);
                        }
                    }
                    catch (Exception ex)
                    {
                        Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                    }
                    //RemoveSessionPayment();
                    if (!String.IsNullOrEmpty(viewModel.UrlOk))
                    {
                        return(Redirect(Request.Url.PathAndQuery));
                    }
                    else if (!String.IsNullOrEmpty(viewModel.UrlKo))
                    {
                        return(Redirect(viewModel.UrlKo));
                    }
                    ViewData["messaggio"] = Language.TransactionOK;
                    return(View(new BonificoViewModel()));
                }
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                ModelState.AddModelError("Error", ex);
            }

            return(View(viewModel));
        }