Ejemplo n.º 1
0
        public ActionResult CompletaOfferta(string token)
        {
            int idOfferta = Utility.DecodeToInt(token);

            using (DatabaseContext db = new DatabaseContext())
            {
                db.Database.Connection.Open();
                PersonaModel compratore = ((PersonaModel)System.Web.HttpContext.Current.Session["utente"]);
                // verifico:
                // se è stata accettata l'offerta
                // se l'offerta è stata fatta dall'utente in sessione
                // se l'annuncio sta aspettando il pagamento
                OFFERTA offerta = db.OFFERTA.Include(m => m.PERSONA)
                                  .Where(o => o.ID == idOfferta && o.ID_PERSONA == compratore.Persona.ID &&
                                         (o.STATO == (int)StatoOfferta.ACCETTATA) &&
                                         o.ANNUNCIO.STATO == (int)StatoVendita.BARATTOINCORSO).SingleOrDefault();

                if (offerta != null)
                {
                    offerta.ANNUNCIO.DATA_MODIFICA       = DateTime.Now;
                    offerta.ANNUNCIO.STATO               = (int)StatoVendita.SOSPESOPEROFFERTA;
                    offerta.ANNUNCIO.SESSIONE_COMPRATORE = Session.SessionID + "§" + Guid.NewGuid().ToString();
                    db.ANNUNCIO.Attach(offerta.ANNUNCIO);
                    db.Entry(offerta.ANNUNCIO).State = EntityState.Modified;
                    if (db.SaveChanges() <= 0)
                    {
                        Session["PayPalOfferta"] = new OffertaModel(offerta);
                        return(RedirectToAction("Payment", "PayPal", new { Id = offerta.ID, Token = token, Azione = AzionePayPal.OffertaOK }));
                    }
                }
            }
            ViewBag.Message = ErrorResource.BidComplete;
            return(Redirect(System.Web.HttpContext.Current.Request.UrlReferrer.ToString()));
        }
Ejemplo n.º 2
0
        private bool SaveOffertaCompleta(PayPalIndexViewModel paypal, Payment payment)
        {
            AcquistoViewModel viewModel = Session["PayPalCompra"] as AcquistoViewModel;
            AnnuncioModel     model     = Session["PayPalAnnuncio"] as AnnuncioModel;

            using (DatabaseContext db = new DatabaseContext())
            {
                // AGGIUNGERE TRANSAZIONE NELLA TABELLA LOG_PAGAMENTO
                LOG_PAGAMENTO log      = new LOG_PAGAMENTO();
                ANNUNCIO      annuncio = db.ANNUNCIO.SingleOrDefault(m => m.TOKEN.ToString() == viewModel.Token &&
                                                                     m.SESSIONE_COMPRATORE == model.SESSIONE_COMPRATORE);
                log.ID_ANNUNCIO         = annuncio.ID;
                log.ID_COMPRATORE       = (Session["utente"] as PersonaModel).Persona.ID;
                log.SESSIONE_COMPRATORE = paypal.Guid;
                log.ID_PAGAMENTO        = payment.id;
                //log.ID_PAGAMENTO = "TEST";
                log.ISTITUTO_PAGAMENTO = "PAYPAL";
                log.NOME_ANNUNCIO      = "Pagamento spedizione per " + annuncio.NOME;
                log.DATA_INSERIMENTO   = DateTime.Now;
                db.LOG_PAGAMENTO.Add(log);
                db.SaveChanges();
                int idPayPal = SavePayPal(db, payment);

                using (DbContextTransaction transaction = db.Database.BeginTransaction())
                {
                    viewModel.PagamentoFatto = true;
                    AnnuncioModel annuncioModel = new AnnuncioModel(annuncio);
                    Models.Enumerators.VerificaAcquisto verifica = annuncioModel.Acquisto(db, viewModel, true);
                    if (verifica == Models.Enumerators.VerificaAcquisto.Ok)
                    {
                        OFFERTA offerta = db.OFFERTA.SingleOrDefault(m => m.ID == paypal.Id);
                        if (model.CompletaAcquistoOfferta(db, offerta, idPayPal))
                        {
                            transaction.Commit();
                            this.RefreshPunteggioUtente(db);
                            Models.ViewModels.Email.PagamentoOffertaViewModel pagamentoOfferta = new Models.ViewModels.Email.PagamentoOffertaViewModel();
                            pagamentoOfferta.NominativoDestinatario = offerta.ANNUNCIO.PERSONA.NOME + " " + offerta.ANNUNCIO.PERSONA.COGNOME;
                            pagamentoOfferta.NomeAnnuncio           = offerta.ANNUNCIO.NOME;
                            pagamentoOfferta.Moneta          = offerta.PUNTI;
                            pagamentoOfferta.SoldiSpedizione = offerta.SOLDI;
                            pagamentoOfferta.Baratti         = offerta.OFFERTA_BARATTO.Select(m => m.ANNUNCIO.NOME).ToList();
                            this.SendNotifica((Session["utente"] as PersonaModel).Persona, offerta.ANNUNCIO.PERSONA, TipoNotifica.OffertaPagata, ControllerContext, "pagamentoOfferta", pagamentoOfferta);
                            System.Web.Routing.RouteValueDictionary data = new System.Web.Routing.RouteValueDictionary(new { token = viewModel.Token });
                            _UrlFinePagamento = Url.Action("Index", "Annuncio", data, this.Request.Url.Scheme, this.Request.Url.Host);
                            return(true);
                        }
                        // altrimenti acquisto fallito
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 3
0
        private bool CanPagamento(AzionePayPal azione)
        {
            switch (azione)
            {
            case AzionePayPal.Acquisto:
                using (DatabaseContext db = new DatabaseContext())
                {
                    AnnuncioModel annuncio = Session["PayPalAnnuncio"] as AnnuncioModel;
                    ANNUNCIO      model    = db.ANNUNCIO.SingleOrDefault(m => m.ID == annuncio.ID &&
                                                                         m.SESSIONE_COMPRATORE == annuncio.SESSIONE_COMPRATORE);
                    if (model != null)
                    {
                        annuncio = new AnnuncioModel(model);
                        return(true);
                    }
                }
                break;

            case AzionePayPal.Offerta:
                using (DatabaseContext db = new DatabaseContext())
                {
                    OffertaModel offerta = Session["PayPalOfferta"] as OffertaModel;
                    OFFERTA      model   = db.OFFERTA.SingleOrDefault(m => m.ID == offerta.ID &&
                                                                      m.SESSIONE_COMPRATORE == offerta.SESSIONE_COMPRATORE);
                    if (model != null)
                    {
                        //offerta = new OffertaModel(model);
                        return(true);
                    }
                }
                break;

            case AzionePayPal.OffertaOK:
                using (DatabaseContext db = new DatabaseContext())
                {
                    AnnuncioModel annuncio = Session["PayPalAnnuncio"] as AnnuncioModel;
                    ANNUNCIO      model    = db.ANNUNCIO.SingleOrDefault(m => m.ID == annuncio.ID &&
                                                                         m.SESSIONE_COMPRATORE == annuncio.SESSIONE_COMPRATORE);
                    if (model != null)
                    {
                        annuncio = new AnnuncioModel(model);
                        return(true);
                    }
                }
                break;
            }
            //AnnullaPagamento(azione);
            return(false);
        }
Ejemplo n.º 4
0
        public ActionResult Conclusi(int pagina = 1)
        {
            List <AnnuncioViewModel> acquistiConclusi = new List <AnnuncioViewModel>();

            try
            {
                using (DatabaseContext db = new DatabaseContext())
                {
                    int utente = ((PersonaModel)Session["utente"]).Persona.ID;
                    var query  = db.ANNUNCIO.Where(item => item.ID_PERSONA != utente && item.ID_COMPRATORE == utente &&
                                                   (item.STATO == (int)StatoVendita.VENDUTO || item.STATO == (int)StatoVendita.ELIMINATO || item.STATO == (int)StatoVendita.BARATTATO) &&
                                                   (item.ID_OGGETTO != null || item.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 = Utility.RandomString(3);
                    List <ANNUNCIO> lista        = query
                                                   .OrderByDescending(item => item.DATA_VENDITA)
                                                   .Skip(pagina * numeroElementi)
                                                   .Take(numeroElementi).ToList();
                    foreach (ANNUNCIO m in lista)
                    {
                        AnnuncioModel     annuncioModel = new AnnuncioModel();
                        AnnuncioViewModel viewModel     = annuncioModel.GetViewModel(db, m);
                        OFFERTA           offerta       = m.OFFERTA.SingleOrDefault(o => o.STATO == (int)StatoOfferta.ACCETTATA);
                        if (offerta != null)
                        {
                            viewModel.Offerta = new OffertaViewModel(db, offerta);
                        }
                        acquistiConclusi.Add(viewModel);
                    }

                    if (acquistiConclusi.Count > 0)
                    {
                        RefreshPunteggioUtente(db);
                    }
                }
            }
            catch (Exception eccezione)
            {
                //Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                LoggatoreModel.Errore(eccezione);
            }
            return(View(acquistiConclusi));
        }
Ejemplo n.º 5
0
        public ActionResult Acquisto(string acquisto = null, string baratto = null)
        {
            if (String.IsNullOrEmpty(acquisto) && String.IsNullOrEmpty(baratto))
            {
                return(RedirectToAction("", "Home"));
            }

            OffertaViewModel viewModel = new OffertaViewModel();

            try
            {
                using (DatabaseContext db = new DatabaseContext())
                {
                    int     numeroElementi = Convert.ToInt32(WebConfigurationManager.AppSettings["numeroElementi"]);
                    OFFERTA offerta        = new OFFERTA();
                    int     idUtente       = (Session["utente"] as PersonaModel).Persona.ID;
                    // fare un if e fare ricerca o per acquisto direttamente o per baratto
                    if (!String.IsNullOrEmpty(acquisto))
                    {
                        //Guid tokenAcquisto = Guid.Parse(Utility.DecodeToString(acquisto.Trim().Substring(3, acquisto.Trim().Length - 6)));
                        Guid tokenAcquisto = Guid.Parse(acquisto);
                        offerta = db.OFFERTA.SingleOrDefault(c => c.ANNUNCIO.TOKEN == tokenAcquisto && c.ANNUNCIO.ID_PERSONA == idUtente && c.PERSONA.STATO == (int)Stato.ATTIVO);
                    }
                    else
                    {
                        //Guid tokenBaratto = Guid.Parse(Utility.DecodeToString(baratto.Trim().Substring(3, baratto.Trim().Length - 6)));
                        Guid tokenBaratto = Guid.Parse(baratto);
                        offerta = db.OFFERTA.SingleOrDefault(c => c.OFFERTA_BARATTO.Count(b => b.ANNUNCIO.TOKEN == tokenBaratto && b.ANNUNCIO.ID_PERSONA == idUtente) > 0);
                    }
                    viewModel = new OffertaViewModel(db, offerta);
                }
            }
            catch (Exception eccezione)
            {
                //Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                LoggatoreModel.Errore(eccezione);
            }

            return(View(viewModel));
        }
Ejemplo n.º 6
0
        private bool SaveOfferta(Payment payment)
        {
            OffertaModel offerta = Session["PayPalOfferta"] as OffertaModel;

            using (DatabaseContext db = new DatabaseContext())
            {
                db.Database.Connection.Open();
                // AGGIUNGERE TRANSAZIONE NELLA TABELLA DEI LOG
                LOG_PAGAMENTO log   = new LOG_PAGAMENTO();
                OFFERTA       model = db.OFFERTA.Include(m => m.PERSONA)
                                      .Include(m => m.ANNUNCIO.ANNUNCIO_TIPO_SCAMBIO)
                                      .SingleOrDefault(m => m.ID == offerta.ID);
                log.ID_ANNUNCIO        = model.ID_ANNUNCIO;
                log.ID_COMPRATORE      = model.ID_PERSONA;
                log.ID_PAGAMENTO       = model.ID.ToString();
                log.ISTITUTO_PAGAMENTO = "PAYPAL";
                log.NOME_ANNUNCIO      = "Offerta per l'annuncio " + model.ANNUNCIO.NOME;
                log.DATA_INSERIMENTO   = DateTime.Now;
                db.LOG_PAGAMENTO.Add(log);
                db.SaveChanges();
                // cambia stato spedizione in pagata
                OFFERTA_SPEDIZIONE spedizione = model.OFFERTA_SPEDIZIONE.FirstOrDefault();
                spedizione.DATA_MODIFICA = DateTime.Now;
                spedizione.STATO         = (int)StatoSpedizione.PAGATA;
                db.OFFERTA_SPEDIZIONE.Attach(spedizione);
                db.Entry(spedizione).State = EntityState.Modified;
                db.SaveChanges();
                int idPayPal = SavePayPal(db, payment);
                using (DbContextTransaction transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        var    utente    = (Session["utente"] as PersonaModel);
                        string messaggio = string.Empty;
                        // ripopolo classe offerta per calcoli nella funzione ACCETTA
                        offerta.OffertaOriginale = model;
                        offerta.ANNUNCIO.ANNUNCIO_TIPO_SCAMBIO = db.ANNUNCIO_TIPO_SCAMBIO
                                                                 .Include(m => m.ANNUNCIO_TIPO_SCAMBIO_SPEDIZIONE)
                                                                 .Where(m => m.ID_ANNUNCIO == offerta.ID_ANNUNCIO).ToList();
                        offerta.AnnuncioModel.ANNUNCIO_TIPO_SCAMBIO = offerta.ANNUNCIO.ANNUNCIO_TIPO_SCAMBIO;

                        //if (offerta.Accetta(db, utente.Persona, utente.Credito, ref messaggio)) => non passa compratore nell'offerta
                        if (offerta.Accetta(db, utente.Persona, idPayPal, ref messaggio))
                        {
                            transaction.Commit();
                            Models.ViewModels.Email.PagamentoOffertaViewModel offertaAccettata = new Models.ViewModels.Email.PagamentoOffertaViewModel();
                            offertaAccettata.NominativoDestinatario = offerta.PERSONA.NOME + " " + offerta.PERSONA.COGNOME;
                            offertaAccettata.NomeAnnuncio           = offerta.ANNUNCIO.NOME;
                            offertaAccettata.Moneta          = offerta.PUNTI;
                            offertaAccettata.SoldiSpedizione = offerta.SOLDI;
                            offertaAccettata.Baratti         = offerta.OFFERTA_BARATTO.Select(m => m.ANNUNCIO.NOME).ToList();
                            this.SendNotifica(utente.Persona, offerta.PERSONA, TipoNotifica.OffertaAccettata, ControllerContext, "offertaAccettata", offertaAccettata);
                            //System.Web.Routing.RouteValueDictionary data = new System.Web.Routing.RouteValueDictionary(new { token = offerta.ID });
                            _UrlFinePagamento = Url.Action("OfferteRicevute", "Vendite", null, this.Request.Url.Scheme, this.Request.Url.Host);
                            //return (db.SaveChanges() > 0);
                            return(true);
                        }
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        LoggatoreModel.Errore(ex);
                        throw ex;
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 7
0
        private void AnnullaPagamento(AzionePayPal azione, int id)
        {
            try
            {
                switch (azione)
                {
                case AzionePayPal.Acquisto:
                    using (DatabaseContext db = new DatabaseContext())
                    {
                        // se non metto la sessione_compratore torno indietro dall'acquisto e annullo tutto.
                        ANNUNCIO model = db.ANNUNCIO.SingleOrDefault(m => m.ID == id && m.SESSIONE_COMPRATORE != null);
                        if (model != null)
                        {
                            if (model.STATO == (int)StatoVendita.SOSPESOPEROFFERTA)
                            {
                                model.STATO = (int)StatoVendita.BARATTOINCORSO;
                            }
                            else
                            {
                                model.STATO = (int)StatoVendita.ATTIVO;
                            }
                            model.SESSIONE_COMPRATORE = null;
                            model.DATA_MODIFICA       = DateTime.Now;
                            db.SaveChanges();
                        }
                    }
                    break;

                case AzionePayPal.Offerta:
                    using (DatabaseContext db = new DatabaseContext())
                    {
                        OFFERTA model = db.OFFERTA.SingleOrDefault(m => m.ID == id && m.SESSIONE_COMPRATORE != null);
                        if (model != null)
                        {
                            model.ANNUNCIO.STATO      = (int)StatoVendita.ATTIVO;
                            model.SESSIONE_COMPRATORE = null;
                            model.STATO = (int)StatoOfferta.ATTIVA;
                            db.SaveChanges();
                        }
                    }
                    break;

                case AzionePayPal.OffertaOK:
                    using (DatabaseContext db = new DatabaseContext())
                    {
                        ANNUNCIO model = db.ANNUNCIO.SingleOrDefault(m => m.ID == id && m.SESSIONE_COMPRATORE != null);
                        if (model != null)
                        {
                            model.STATO = (int)StatoVendita.BARATTOINCORSO;
                            model.SESSIONE_COMPRATORE = null;
                            model.DATA_MODIFICA       = DateTime.Now;
                            db.SaveChanges();
                        }
                    }
                    break;
                }
            }
            catch (Exception eccezione)
            {
                LoggatoreModel.Errore(eccezione);
            }
        }
Ejemplo n.º 8
0
        public ActionResult AccettaOfferta(string token)
        {
            int    idOfferta = Utility.DecodeToInt(token);
            string messaggio = "";

            //OffertaModel offerta = new OffertaModel(idOfferta, (Session["utente"] as PersonaModel).Persona);
            using (DatabaseContext db = new DatabaseContext())
            {
                using (var transazioneDb = db.Database.BeginTransaction())
                {
                    try
                    {
                        PersonaModel utente  = ((PersonaModel)System.Web.HttpContext.Current.Session["utente"]);
                        OFFERTA      offerta = db.OFFERTA.Include(m => m.PERSONA)
                                               .Where(o => o.ID == idOfferta && o.ANNUNCIO.ID_PERSONA == utente.Persona.ID &&
                                                      (o.STATO == (int)StatoOfferta.ATTIVA ||
                                                       o.STATO == (int)StatoOfferta.ACCETTATA_ATTESO_PAGAMENTO)).SingleOrDefault();

                        OffertaModel offertaModel = new OffertaModel(offerta);
                        Models.Enumerators.VerificaOfferta verifica = offertaModel.CheckAccettaOfferta(utente, offerta);
                        // se bisogna pagare la spedizione reindirizzo su paypal
                        if (verifica == Models.Enumerators.VerificaOfferta.VerificaCartaDiCredito)
                        {
                            // prima setto la sessione per il pagamento
                            offerta.STATO = (int)StatoOfferta.ACCETTATA_ATTESO_PAGAMENTO;
                            offerta.SESSIONE_COMPRATORE = HttpContext.Session.SessionID + "§" + Guid.NewGuid().ToString();
                            db.OFFERTA.Attach(offerta);
                            db.Entry(offerta).State = EntityState.Modified;
                            if (db.SaveChanges() > 0)
                            {
                                // metto l'annuncio dell'offerta come baratto in corso
                                offertaModel.ANNUNCIO.STATO = (int)StatoVendita.BARATTOINCORSO;
                                db.ANNUNCIO.Attach(offertaModel.ANNUNCIO);
                                db.Entry(offertaModel.ANNUNCIO).State = EntityState.Modified;
                                if (db.SaveChanges() > 0)
                                {
                                    transazioneDb.Commit();
                                    //Session["PayPalCompra"] = viewModel;
                                    Session["PayPalOfferta"] = new OffertaModel(offertaModel.OffertaOriginale);
                                    return(RedirectToAction("Payment", "PayPal", new { Id = offerta.ID, Token = token, Azione = AzionePayPal.Offerta }));
                                }
                            }
                        }
                        else if (verifica == Models.Enumerators.VerificaOfferta.Ok)
                        {
                            if (offertaModel.Accetta(db, utente.Persona, null, ref messaggio))
                            {
                                // se offerta dev'essere pagata, invio notifica e reindirizzo a pagina pagamento
                                // se venditore annulla pagamento, potrà sempre pagare più avanti, sennò feedback negativo e annullo transazioni
                                if (offertaModel.ANNUNCIO.STATO == (int)StatoVendita.BARATTOINCORSO)
                                {
                                    Models.ViewModels.Email.PagamentoOffertaViewModel offertaAccettata = new Models.ViewModels.Email.PagamentoOffertaViewModel();
                                    offertaAccettata.NominativoDestinatario = offertaModel.PERSONA.NOME + " " + offertaModel.PERSONA.COGNOME;
                                    offertaAccettata.NomeAnnuncio           = offertaModel.ANNUNCIO.NOME;
                                    offertaAccettata.Moneta          = offertaModel.PUNTI;
                                    offertaAccettata.SoldiSpedizione = offertaModel.SOLDI;
                                    offertaAccettata.Baratti         = offertaModel.OFFERTA_BARATTO.Select(m => m.ANNUNCIO.NOME).ToList();
                                    this.SendNotifica(utente.Persona, offertaModel.PERSONA, TipoNotifica.OffertaAccettata, ControllerContext, "offertaAccettata", offertaAccettata);
                                }
                                transazioneDb.Commit();
                                ViewBag.Message = Language.AcceptedBid;
                                return(Redirect(System.Web.HttpContext.Current.Request.UrlReferrer.ToString()));
                            }
                        }
                    }
                    catch (Exception eccezione)
                    {
                        //Elmah.ErrorSignal.FromCurrentContext().Raise(eccezione);
                        LoggatoreModel.Errore(eccezione);
                    }
                    transazioneDb.Rollback();
                }
            }

            TempData["MESSAGGIO"] = Language.ErrorAcceptBid;
            return(Redirect(System.Web.HttpContext.Current.Request.UrlReferrer.ToString()));
        }
Ejemplo n.º 9
0
        public ActionResult Index(string token, int pagina = 1)
        {
            AnnuncioModel model = null;

            using (DatabaseContext db = new DatabaseContext())
            {
                using (System.Data.Entity.DbContextTransaction transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        int     id      = Utility.DecodeToInt(token);
                        OFFERTA offerta = db.OFFERTA.SingleOrDefault(m => m.ID == id);
                        if (offerta == null)
                        {
                            throw new HttpException(404, ExceptionMessage.AdNotFound);
                        }
                        model = new AnnuncioModel(offerta.ANNUNCIO);
                        if (model.TOKEN == null)
                        {
                            throw new HttpException(404, ExceptionMessage.AdNotFound);
                        }

                        AcquistoViewModel viewModel = new AcquistoViewModel(offerta);
                        if (ModelState.IsValid)
                        {
                            if (!Utility.IsUtenteAttivo(1, TempData))
                            {
                                ModelState.AddModelError("", ErrorResource.UserEnabled);
                            }
                            else
                            {
                                Models.Enumerators.VerificaAcquisto verifica = model.Acquisto(db, viewModel, true);
                                if (verifica == Models.Enumerators.VerificaAcquisto.Ok)
                                {
                                    // PENSO CHE QUESTA ACTION SIA USATA SOLO PER OFFERTA E QUINDI CAMBIO CHIAMATA
                                    //if (model.CompletaAcquisto(db, viewModel))
                                    if (model.CompletaAcquistoOfferta(db, offerta))
                                    {
                                        TempData["Esito"] = Language.JsonBuyAd;
                                        TempData["pagamentoEffettuato"] = true;
                                        transaction.Commit();
                                        this.RefreshPunteggioUtente(db);
                                        return(RedirectToAction("Index", "Annuncio", new { token = viewModel.Token }));
                                    }
                                    // altrimenti pagamento fallito!
                                }
                                else if (verifica == Models.Enumerators.VerificaAcquisto.VerificaCartaCredito)
                                {
                                    string actionPagamento = "Payment";
                                    if (viewModel.TipoCarta != TipoCartaCredito.PayPal)
                                    {
                                        actionPagamento = "PaymentWithCreditCard";
                                    }
                                    transaction.Commit();
                                    Session["PayPalCompra"]   = viewModel;
                                    Session["PayPalAnnuncio"] = model;
                                    return(RedirectToAction(actionPagamento, "PayPal", new { Id = offerta.ID, Token = viewModel.Token, Azione = AzionePayPal.OffertaOK }));
                                }
                                else
                                {
                                    Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception(string.Format("Messaggio {0} per l'errore {1}", ErrorResource.AdBuyFailed, verifica.ToString())));
                                    ModelState.AddModelError("", ErrorResource.AdBuyFailed);
                                }
                            }
                        }
                        //transaction.Rollback();
                    }
                    catch (HttpException eccezione)
                    {
                        //Elmah.ErrorSignal.FromCurrentContext().Raise(eccezione);
                        LoggatoreModel.Errore(eccezione);
                        throw new HttpException(404, eccezione.Message);
                    }
                    catch (Exception eccezione)
                    {
                        ModelState.AddModelError("", eccezione.Message);
                        //Elmah.ErrorSignal.FromCurrentContext().Raise(eccezione);
                        LoggatoreModel.Errore(eccezione);
                    }
                    finally
                    {
                        if (db.Database.CurrentTransaction != null)
                        {
                            transaction.Rollback();
                        }
                    }
                }
                int utente = ((PersonaModel)Session["utente"]).Persona.ID;
                return(View(GetListaOfferte(db, utente, pagina)));
            }
        }
Ejemplo n.º 10
0
        public ActionResult Acquisto(string acquisto = null, string baratto = null)
        {
            if (String.IsNullOrEmpty(acquisto) && String.IsNullOrEmpty(baratto))
            {
                return(RedirectToAction("", "Home"));
            }

            OffertaEffettuataViewModel viewModel = new OffertaEffettuataViewModel();

            try
            {
                using (DatabaseContext db = new DatabaseContext())
                {
                    int     numeroElementi = Convert.ToInt32(WebConfigurationManager.AppSettings["numeroElementi"]);
                    OFFERTA offerta        = new OFFERTA();
                    int     idUtente       = (Session["utente"] as PersonaModel).Persona.ID;
                    // fare un if e fare ricerca o per acquisto direttamente o per baratto
                    if (!String.IsNullOrEmpty(acquisto))
                    {
                        Guid tokenAcquisto = Guid.Parse(Utils.DecodeToString(acquisto.Trim().Substring(3, acquisto.Trim().Length - 6)));
                        offerta = db.OFFERTA.SingleOrDefault(c => c.ANNUNCIO.TOKEN == tokenAcquisto && c.ANNUNCIO.ID_PERSONA == idUtente && c.PERSONA.STATO == (int)Stato.ATTIVO);
                    }
                    else
                    {
                        Guid tokenBaratto = Guid.Parse(Utils.DecodeToString(baratto.Trim().Substring(3, baratto.Trim().Length - 6)));
                        offerta = db.OFFERTA.SingleOrDefault(c => c.OFFERTA_BARATTO.Count(b => b.ANNUNCIO.TOKEN == tokenBaratto && b.ANNUNCIO.ID_PERSONA == idUtente) > 0);
                    }

                    viewModel = new OffertaEffettuataViewModel()
                    {
                        Id             = offerta.ID.ToString(),
                        Nome           = offerta.ANNUNCIO.NOME,
                        Venditore      = (offerta.ANNUNCIO.ID_ATTIVITA != null) ? offerta.ANNUNCIO.ATTIVITA.NOME : offerta.ANNUNCIO.PERSONA.NOME + ' ' + offerta.ANNUNCIO.PERSONA.COGNOME,
                        Email          = (offerta.ANNUNCIO.ID_ATTIVITA != null) ? offerta.ANNUNCIO.ATTIVITA.ATTIVITA_EMAIL.SingleOrDefault(e => e.TIPO == (int)TipoEmail.Registrazione).EMAIL : offerta.ANNUNCIO.PERSONA.PERSONA_EMAIL.SingleOrDefault(e => e.TIPO == (int)TipoEmail.Registrazione).EMAIL,
                        VenditoreToken = offerta.ANNUNCIO.PERSONA.TOKEN,
                        Telefono       = (offerta.ANNUNCIO.ID_ATTIVITA != null) ? offerta.ANNUNCIO.ATTIVITA.ATTIVITA_TELEFONO.SingleOrDefault(t => t.TIPO == (int)TipoTelefono.Privato).TELEFONO : offerta.ANNUNCIO.PERSONA.PERSONA_TELEFONO.SingleOrDefault(t => t.TIPO == (int)TipoTelefono.Privato).TELEFONO,
                        Punti          = (int)offerta.PUNTI,
                        Soldi          = (int)offerta.SOLDI,
                        Categoria      = offerta.ANNUNCIO.CATEGORIA.NOME,
                        Foto           = db.ANNUNCIO_FOTO.Where(f => f.ID_ANNUNCIO == offerta.ANNUNCIO.ID).Select(f =>
                                                                                                                  f.FOTO.FOTO1
                                                                                                                  ).ToList(),
                        Baratti = db.OFFERTA_BARATTO.Where(b => b.ID_OFFERTA == offerta.ID && b.ANNUNCIO != null).Select(b =>
                                                                                                                         new VenditaViewModel()
                        {
                            Token        = b.ANNUNCIO.TOKEN.ToString(),
                            TipoAcquisto = b.ANNUNCIO.SERVIZIO != null ? TipoAcquisto.Servizio : TipoAcquisto.Oggetto,
                            Nome         = b.ANNUNCIO.NOME,
                            Punti        = b.ANNUNCIO.PUNTI,
                            Soldi        = b.ANNUNCIO.SOLDI,
                        }).ToList(),
                        Token           = offerta.ANNUNCIO.TOKEN.ToString(),
                        TipoOfferta     = (TipoOfferta)offerta.TIPO_OFFERTA,
                        TipoTrattativa  = (TipoTrattativa)offerta.TIPO_TRATTATIVA,
                        TipoPagamento   = (TipoPagamento)offerta.ANNUNCIO.TIPO_PAGAMENTO,
                        StatoOfferta    = (StatoOfferta)offerta.STATO,
                        StatoVendita    = (StatoVendita)offerta.ANNUNCIO.STATO,
                        DataInserimento = (DateTime)offerta.DATA_INSERIMENTO,
                        //PuntiCompratore = offerta.PERSONA.CONTO_CORRENTE.CONTO_CORRENTE_MONETA.Count(m => m.STATO == (int)StatoMoneta.ASSEGNATA),
                        //PuntiSospesiCompratore = offerta.PERSONA.CONTO_CORRENTE.CONTO_CORRENTE_MONETA.Count(m => m.STATO == (int)StatoMoneta.SOSPESA)
                    };
                }
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
            }

            return(View(viewModel));
        }