예제 #1
0
 public ActionResult GetFormCopiaAnnuncio(string token)
 {
     using (DatabaseContext db = new DatabaseContext())
     {
         int    idUtente          = (Session["utente"] as PersonaModel).Persona.ID;
         string tokenDecodificato = Server.UrlDecode(token);
         //string tokenPulito = tokenDecodificato.Substring(3).Substring(0, tokenDecodificato.Length - 6);
         //Guid tokenGuid = Guid.Parse(tokenPulito);
         Guid     tokenGuid = Guid.Parse(tokenDecodificato);
         ANNUNCIO annuncio  = db.ANNUNCIO.SingleOrDefault(m => m.TOKEN == tokenGuid && m.ID_PERSONA != idUtente);
         if (annuncio != null)
         {
             PubblicaCopiaViewModel copia = null;
             if (annuncio.ID_OGGETTO != null)
             {
                 copia = new PubblicaOggettoCopiaViewModel(annuncio);
                 return(PartialView("PartialPages/_CopiaOggetto", copia));
             }
             else
             {
                 copia = new PubblicaServizioCopiaViewModel(annuncio);
                 return(PartialView("PartialPages/_CopiaServizio", copia));
             }
         }
     }
     throw new Exception(ExceptionMessage.OpenCopyForm);
 }
예제 #2
0
 public JsonResult AttivaVendita(string token)
 {
     try
     {
         Guid tokenDecriptato = getTokenDecodificato(token);
         int  idUtente        = (Session["utente"] as PersonaModel).Persona.ID;
         using (DatabaseContext db = new DatabaseContext())
         {
             ANNUNCIO model = db.ANNUNCIO.Where(v => v.TOKEN == tokenDecriptato && v.ID_PERSONA == idUtente &&
                                                (v.STATO == (int)StatoVendita.INATTIVO || v.STATO != (int)StatoVendita.ATTIVO)).SingleOrDefault();
             if (model != null)
             {
                 model.STATO         = (int)StatoVendita.ATTIVO;
                 model.DATA_MODIFICA = DateTime.Now;
                 if (db.SaveChanges() > 0)
                 {
                     return(Json(true));
                 }
             }
         }
     }
     catch (Exception ex)
     {
         //Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
         LoggatoreModel.Errore(ex);
     }
     Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest;
     return(Json(App_GlobalResources.Language.EnableSellFailed));
 }
예제 #3
0
 public string NonPossiedo(string tokenAnnuncio, string tokenAnnuncioUtente)
 {
     try
     {
         using (DatabaseContext db = new DatabaseContext())
         {
             db.Database.Connection.Open();
             using (var transazione = db.Database.BeginTransaction())
             {
                 if (annullaVenditaSuDatabase(db, tokenAnnuncioUtente))
                 {
                     transazione.Commit();
                     int               idUtente          = (Session["utente"] as PersonaModel).Persona.ID;
                     Guid              tokenGuid         = getTokenDecodificato(tokenAnnuncio);
                     ANNUNCIO          model             = db.ANNUNCIO.FirstOrDefault(m => m.TOKEN == tokenGuid);
                     AnnuncioViewModel viewModelAnnuncio = new AnnuncioViewModel(db, model);
                     return(RenderRazorViewToString("PartialPages/_Possiedo", viewModelAnnuncio));
                 }
             }
         }
     }
     catch (Exception ex)
     {
         //Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
         LoggatoreModel.Errore(ex);
     }
     // annuncio non in possesso
     throw new Exception(ExceptionMessage.YouDontHaveThisAd);
 }
예제 #4
0
        private ActionResult SaveAnnuncio(PubblicazioneViewModel viewModel)
        {
            ANNUNCIO annuncio = new ANNUNCIO();

            using (DatabaseContext db = new DatabaseContext())
            {
                db.Database.Connection.Open();
                using (DbContextTransaction transaction = db.Database.BeginTransaction())
                {
                    try {
                        viewModel.DbContext = db;
                        // verificare come aprire la transazione sul salvataggio, effettuare commit o rollback
                        if (ModelState.IsValid && viewModel.SalvaAnnuncio(ControllerContext, annuncio))
                        {
                            int?idAnnuncio = annuncio.ID;
                            if (idAnnuncio != null)
                            {
                                PersonaModel utente = ((PersonaModel)Session["utente"]);
                                viewModel.InviaEmail(ControllerContext, annuncio, utente);

                                decimal numeroCreditiBonus = AddBonus(db, utente, viewModel);
                                if (numeroCreditiBonus > 0)
                                {
                                    TempData["BONUS"] = string.Format(Bonus.YouWin, numeroCreditiBonus, Language.Moneta);
                                }

                                transaction.Commit();
                                return(RedirectToAction("Completato", new { id = idAnnuncio }));
                            }
                        }
                        transaction.Rollback();
                    }
                    catch (Exception eccezione)
                    {
                        transaction.Rollback();
                        viewModel.CancelUploadFoto(annuncio);
                        ModelState.AddModelError("Error", eccezione.Message);
                        //ErrorSignal.FromCurrentContext().Raise(eccezione);
                        LoggatoreModel.Errore(eccezione);
                    }
                }
            }
            // se ha già scelto una categoria ricarico i campi
            string nomeVistaDettaglio = GetNomeVistaDettagliAnnuncio(viewModel.CategoriaId);

            if (!string.IsNullOrWhiteSpace(nomeVistaDettaglio))
            {
                ViewData["infoAggiuntive"] = RenderRazorViewToString(nomeVistaDettaglio, viewModel);
            }
            else
            {
                string nomeTipologiaDettaglio = GetNomeVistaTipologia(viewModel.CategoriaId);
                if (!string.IsNullOrWhiteSpace(nomeTipologiaDettaglio))
                {
                    ViewData["infoAggiuntive"] = RenderRazorViewToString(nomeTipologiaDettaglio, viewModel);
                }
            }
            return(View("Index", viewModel));
        }
예제 #5
0
 public JsonResult Sblocca(string token)
 {
     try
     {
         Guid tokenDecriptato = getTokenDecodificato(token);
         int  idUtente        = (Session["utente"] as PersonaModel).Persona.ID;
         using (DatabaseContext db = new DatabaseContext())
         {
             ANNUNCIO model = db.ANNUNCIO.Where(v => v.TOKEN == tokenDecriptato && v.ID_PERSONA == idUtente)
                              .SingleOrDefault();
             // verifico se l'annuncio è stato sospeso in automatico o per via di un acquisto non concluso da più di 1 giorno
             if (model != null)
             {
                 if (model.STATO == (int)StatoVendita.SOSPESO && (model.DATA_MODIFICA == null || DateTime.Now > model.DATA_MODIFICA.Value.AddDays(1)))
                 {
                     model.STATO         = (int)StatoVendita.ATTIVO;
                     model.DATA_MODIFICA = DateTime.Now;
                     if (db.SaveChanges() > 0)
                     {
                         LOG_SBLOCCO_ANNUNCIO log = new LOG_SBLOCCO_ANNUNCIO();
                         log.ID_ANNUNCIO       = model.ID;
                         log.ID_UTENTE_SBLOCCO = idUtente;
                         log.TIPO       = (int)TipoSbloccoAnnuncio.SospensioneAnnuncio;
                         log.DATA_AVVIO = (DateTime)model.DATA_MODIFICA;
                         db.LOG_SBLOCCO_ANNUNCIO.Add(log);
                         db.SaveChanges();
                         return(Json(true));
                     }
                 }
                 else if (model.STATO == (int)StatoVendita.ATTIVO && model.DATA_FINE != null && model.DATA_FINE <= DateTime.Now)
                 {
                     TimeSpan span = Convert.ToDateTime(model.DATA_FINE).Subtract(model.DATA_AVVIO);
                     model.DATA_FINE     = DateTime.Now.AddDays(span.Days);
                     model.DATA_MODIFICA = DateTime.Now;
                     if (db.SaveChanges() > 0)
                     {
                         LOG_SBLOCCO_ANNUNCIO log = new LOG_SBLOCCO_ANNUNCIO();
                         log.ID_ANNUNCIO       = model.ID;
                         log.ID_UTENTE_SBLOCCO = idUtente;
                         log.TIPO       = (int)TipoSbloccoAnnuncio.SospensioneAnnuncio;
                         log.DATA_AVVIO = model.DATA_AVVIO;
                         log.DATA_FINE  = model.DATA_FINE;
                         db.LOG_SBLOCCO_ANNUNCIO.Add(log);
                         db.SaveChanges();
                         return(Json(true));
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         //Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
         LoggatoreModel.Errore(ex);
     }
     Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest;
     return(Json(ExceptionMessage.UnblockFailed));
 }
예제 #6
0
        public ActionResult SuggestAdActivation(string chiave1, string idAttivita = null)
        {
            string backUrl = Request.UrlReferrer.PathAndQuery;

            using (DatabaseContext db = new DatabaseContext())
            {
                //string tokenAnnuncio = id.Substring(3, id.Length - 6);
                db.Database.Connection.Open();
                ANNUNCIO annuncio    = db.ANNUNCIO.Single(m => m.TOKEN.ToString() == chiave1);
                int      idAnnuncio  = annuncio.ID;
                PERSONA  persona     = (Session["utente"] as PersonaModel).Persona;
                int      idUtente    = persona.ID;
                int?     keyAttivita = null;
                // se è stata selezionata una attività commerciale dell'utente
                List <AttivitaModel> listaAttivita = (Session["utente"] as PersonaModel).Attivita;
                if (listaAttivita != null && listaAttivita.Count > 0 && !string.IsNullOrWhiteSpace(idAttivita))
                {
                    keyAttivita = listaAttivita.SingleOrDefault(m => m.Attivita.TOKEN.ToString() == idAttivita).ID;
                }
                // notifica già inviata.
                if (db.ANNUNCIO_NOTIFICA.Count(m => m.ID_ANNUNCIO == idAnnuncio && (m.NOTIFICA.ID_PERSONA == idUtente || (keyAttivita != null && m.NOTIFICA.ID_ATTIVITA == keyAttivita))) > 0)
                {
                    TempData["MESSAGGIO"] = Language.SuggestAdActivationError;
                    //return RedirectToAction("", "Cerca");
                    return(Redirect(backUrl));
                }
                Guid portale = Guid.Parse(System.Configuration.ConfigurationManager.AppSettings["portaleweb"]);
                int  bonus   = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["bonusSuggerimentoAttivazioneAnnuncio"]);
                this.AddBonus(db, ControllerContext, persona, portale, bonus, TipoTransazione.BonusSuggerimentoAttivazioneAnnuncio, Bonus.SuggestAdActivation);

                NOTIFICA notifica = new NOTIFICA();
                notifica.ID_PERSONA               = idUtente;
                notifica.ID_ATTIVITA              = keyAttivita;
                notifica.ID_PERSONA_DESTINATARIO  = annuncio.ID_PERSONA;
                notifica.ID_ATTIVITA_DESTINATARIO = annuncio.ID_ATTIVITA;
                notifica.MESSAGGIO        = (int)TipoNotifica.AttivaAnnuncio;
                notifica.DATA_INSERIMENTO = DateTime.Now;
                notifica.STATO            = (int)Stato.ATTIVO;
                db.NOTIFICA.Add(notifica);
                if (db.SaveChanges() > 0)
                {
                    db.ANNUNCIO_NOTIFICA.Add(new ANNUNCIO_NOTIFICA()
                    {
                        ID_ANNUNCIO = idAnnuncio,
                        ID_NOTIFICA = notifica.ID
                    });
                    if (db.SaveChanges() > 0)
                    {
                        TempData["MESSAGGIO"] = Language.SuggestAdActivationOK;
                        //return RedirectToAction("", "Cerca");
                        return(Redirect(backUrl));
                    }
                }
            }
            TempData["MESSAGGIO"] = Language.SuggestAdActivationKO;
            //return RedirectToAction("", "Cerca");
            return(Redirect(backUrl));
        }
        public ActionResult Index(int id, TipoFeedback tipo)
        {
            string nomeView = "";
            // verificare come visualizzare soltanto
            // verificare come differenziare tra compratore e venditore
            FeedbackViewModel viewModel = new FeedbackViewModel();

            try
            {
                if (ModelState.IsValid)
                {
                    using (DatabaseContext db = new DatabaseContext())
                    {
                        //string acquistoDecodificato = Uri.UnescapeDataString(id);
                        //string acquistoPulito = acquistoDecodificato.Trim().Substring(3, acquistoDecodificato.Trim().Length - 6);
                        //int idAcquisto = Utility.DecodeToInt(acquistoPulito);
                        int idUtente            = (Session["utente"] as PersonaModel).Persona.ID;
                        ANNUNCIO_FEEDBACK model = db.ANNUNCIO_FEEDBACK.Where(f => f.ID_ANNUNCIO == id && f.ID_VOTANTE == idUtente).SingleOrDefault();
                        if (model != null)
                        {
                            TempData["feedback"] = model;
                            return(RedirectToAction("Inviato", new { id = model.ID }));
                        }

                        // se è un nuovo voto, recupero i dati del pagamento
                        ANNUNCIO model2 = null;
                        if (tipo == TipoFeedback.Acquirente)
                        {
                            model2               = db.ANNUNCIO.Where(p => p.ID == id && p.ID_PERSONA != idUtente).SingleOrDefault();
                            viewModel.Nome       = model2.NOME;
                            viewModel.AcquistoID = id;
                            viewModel.Tipo       = tipo;
                        }
                        else if (tipo == TipoFeedback.Venditore)
                        {
                            model2               = db.ANNUNCIO.Where(p => p.ID == id && p.ID_PERSONA == idUtente).SingleOrDefault();
                            viewModel.Nome       = model2.NOME;
                            viewModel.AcquistoID = id;
                            viewModel.Tipo       = tipo;
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                //Elmah.ErrorSignal.FromCurrentContext().Raise(exception);
                LoggatoreModel.Errore(exception);
                // se ha un errore generico o semplicemente sta cercando di fare un feedback
                return(Redirect(System.Web.Security.FormsAuthentication.DefaultUrl));
            }
            return(View(nomeView, viewModel));
        }
예제 #8
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);
        }
예제 #9
0
        private PubblicazioneViewModel UpdateServizio(ANNUNCIO model, PubblicaServizioCopiaViewModel viewModelCopia)
        {
            PubblicazioneViewModel viewModel = null;

            viewModel = new PubblicaServizioViewModel(model);
            // se è stato copiato l'annuncio, allora riporto le modifiche
            if (viewModel != null)
            {
                viewModel.Update(viewModelCopia);
            }

            return(viewModel);
        }
예제 #10
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);
        }
예제 #11
0
        public ActionResult Completato(int id)
        {
            // se ancora la registrazione è incompleta, lo obbligo a concluderla
            if (!Utility.IsUtenteAttivo(1, TempData))
            {
                return(RedirectToAction("Impostazioni", "Utente"));
            }

            AnnuncioViewModel viewModel = null;

            try
            {
                ANNUNCIO model = new ANNUNCIO();
                using (DatabaseContext db = new DatabaseContext())
                {
                    model = db.ANNUNCIO.Include(m => m.ANNUNCIO_FOTO)
                            .Include(m => m.CATEGORIA)
                            //.Include("ANNUNCIO_FOTO.FOTO")
                            .SingleOrDefault(m => m.ID == id);

                    viewModel = new AnnuncioViewModel(db, model);
                    if (model.CONDIVISIONE_FACEBOOK_G4G == null || (StatoPubblicaAnnuncioFacebook)model.CONDIVISIONE_FACEBOOK_G4G == StatoPubblicaAnnuncioFacebook.NonPubblicato)
                    {
                        // PUBBLICAZIONE SOCIAL
                        string emailUtente = (Session["utente"] as PersonaModel)
                                             .Email.FirstOrDefault(item => item.TIPO == (int)TipoEmail.Registrazione).EMAIL;
                        string dominio = GetCurrentDomain();
                        if (HttpContext.IsDebuggingEnabled)
                        {
                            dominio = "https://www.gratisforgratis.com";
                        }
                        string indirizzoImmagine = dominio + "/Uploads/Images/" + emailUtente + "/" + DateTime.Now.Year + "/Normal/" + viewModel.Foto[0].ALLEGATO.NOME;

                        SendPostFacebook(viewModel.Nome, viewModel.Nome + " GRATIS con " + viewModel.Punti, indirizzoImmagine, dominio);
                        model.CONDIVISIONE_FACEBOOK_G4G = (int)StatoPubblicaAnnuncioFacebook.Pubblicato;
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                //ErrorSignal.FromCurrentContext().Raise(ex);
                LoggatoreModel.Errore(ex);
                return(RedirectToAction("Index", "Utente"));
            }

            return(View(viewModel));
        }
        public ActionResult AnnullaVendita(string token)
        {
            DatabaseContext db = new DatabaseContext();

            try
            {
                token = Server.UrlDecode(token);
                Guid tokenDecriptato = Guid.Parse(Utils.DecodeToString(token.Substring(3).Substring(0, token.Length - 6)));
                int  idUtente        = (Session["utente"] as PersonaModel).Persona.ID;
                //using (DatabaseContext db = new DatabaseContext())
                //{
                db.Database.Connection.Open();
                using (var transazione = db.Database.BeginTransaction())
                {
                    ANNUNCIO model = db.ANNUNCIO.Where(v => v.TOKEN == tokenDecriptato && v.ID_PERSONA == idUtente && v.STATO != (int)StatoVendita.BARATTATO &&
                                                       v.STATO != (int)StatoVendita.ELIMINATO && v.STATO != (int)StatoVendita.VENDUTO).SingleOrDefault();
                    if (model != null)
                    {
                        model.STATO         = (int)StatoVendita.ELIMINATO;
                        model.DATA_MODIFICA = DateTime.Now;
                        if (db.SaveChanges() > 0)
                        {
                            OffertaModel.AnnullaOfferteEffettuate(db, model.ID);
                            OffertaModel.AnnullaOfferteRicevute(db, model.ID);
                            transazione.Commit();
                            return(Json(new { Messaggio = App_GlobalResources.Language.StateSellDelete }));
                        }
                    }
                    transazione.Rollback();
                    //}
                }
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
            }
            finally
            {
                if (db.Database.Connection.State != System.Data.ConnectionState.Closed)
                {
                    db.Database.Connection.Close();
                    db.Database.Connection.Dispose();
                }
            }
            Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest;
            return(Json(App_GlobalResources.Language.ErrorRefuseBid));
        }
예제 #13
0
        private bool SaveAcquisto(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      = 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);
                    if (verifica == Models.Enumerators.VerificaAcquisto.Ok)
                    {
                        if (model.CompletaAcquisto(db, viewModel, idPaypal))
                        {
                            transaction.Commit();
                            this.RefreshPunteggioUtente(db);
                            this.SendNotifica(annuncioModel.PERSONA, annuncioModel.PERSONA1, TipoNotifica.AnnuncioAcquistato, ControllerContext, "annuncioAcquistato", annuncioModel);
                            this.SendNotifica(annuncioModel.PERSONA1, annuncioModel.PERSONA, TipoNotifica.AnnuncioVenduto, ControllerContext, "annuncioVenduto", annuncioModel);
                            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);
        }
 private void SetOggettoViewModel(OggettoViewModel oggetto, ANNUNCIO vendita)
 {
     oggetto.Id                  = (int)vendita.ID_OGGETTO;
     oggetto.CategoriaID         = vendita.ID_CATEGORIA;
     oggetto.Categoria           = vendita.CATEGORIA.NOME;
     oggetto.Token               = Utils.RandomString(3) + vendita.TOKEN.ToString() + Utils.RandomString(3);
     oggetto.Citta               = vendita.OGGETTO.COMUNE.NOME;
     oggetto.DataInserimento     = vendita.DATA_INSERIMENTO;
     oggetto.VenditoreToken      = vendita.PERSONA.TOKEN;
     oggetto.Foto                = vendita.ANNUNCIO_FOTO.Where(f => f.ID_ANNUNCIO == vendita.ID).Select(f => f.FOTO.FOTO1).ToList();
     oggetto.Marca               = vendita.OGGETTO.MARCA.NOME;
     oggetto.Nome                = vendita.NOME;
     oggetto.Punti               = vendita.PUNTI;
     oggetto.Soldi               = vendita.SOLDI;
     oggetto.StatoOggetto        = (CondizioneOggetto)vendita.OGGETTO.CONDIZIONE;
     oggetto.TipoPagamento       = (TipoPagamento)vendita.TIPO_PAGAMENTO;
     oggetto.VenditoreID         = vendita.ID_PERSONA;
     oggetto.VenditoreNominativo = vendita.PERSONA.NOME + ' ' + vendita.PERSONA.COGNOME;
     oggetto.Note                = vendita.NOTE_AGGIUNTIVE;
     oggetto.Quantità            = vendita.OGGETTO.NUMERO_PEZZI;
     oggetto.StatoVendita        = (StatoVendita)vendita.STATO;
 }
예제 #15
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);
            }
        }
        public ActionResult Acquista(string nome, string token)
        {
            if (string.IsNullOrWhiteSpace(nome) || string.IsNullOrWhiteSpace(token))
            {
                return(RedirectToAction("", "Cerca"));
            }

            OggettoViewModel oggetto  = new OggettoViewModel();
            string           nomeView = "Index";

            try
            {
                TempData["azione"] = "Buy";
                string tokenDecodificato = Server.UrlDecode(token);
                string tokenPulito       = tokenDecodificato.Substring(3).Substring(0, tokenDecodificato.Length - 6);
                Guid   tokenGuid         = Guid.Parse(tokenPulito);

                string nomeDecodificato = Server.UrlDecode(nome);

                // recuperare oggetto e visualizzare vista corretta
                using (DatabaseContext db = new DatabaseContext())
                {
                    db.Database.Connection.Open();
                    ANNUNCIO vendita = new ANNUNCIO();
                    if (TempData["annuncio"] == null)
                    {
                        vendita = db.ANNUNCIO
                                  .Include("Categoria")
                                  .Include("Persona")
                                  .Include("Oggetto")
                                  .Include("Annuncio_Foto")
                                  .Where(v => v.TOKEN == tokenGuid && v.NOME == nomeDecodificato && v.OGGETTO != null).FirstOrDefault();
                        if (Session["utente"] != null && vendita.ID_PERSONA == (Session["utente"] as PersonaModel).Persona.ID)
                        {
                            if (vendita.STATO == (int)StatoVendita.ATTIVO || vendita.STATO == (int)StatoVendita.INATTIVO || vendita.STATO == (int)StatoVendita.SOSPESO)
                            {
                                TempData["annuncio"] = vendita;
                                return(RedirectToAction("Modifica", "Oggetto", new { nome = nome, token = token }));
                            }
                        }
                        else if (vendita.STATO != (int)StatoVendita.ATTIVO)
                        {
                            TempData["annuncio"] = vendita;
                            return(RedirectToAction("Index", "Oggetto", new { nome = nome, token = token }));
                        }
                    }
                    else
                    {
                        vendita = TempData["annuncio"] as ANNUNCIO;
                    }
                    nomeView = vendita.CATEGORIA.DESCRIZIONE;
                    SetOggettoViewModel(oggetto, vendita);
                    oggetto = SetInfoCategoriaOggetto(vendita.OGGETTO, oggetto);
                    SetFeedbackVenditoreOggetto(db, oggetto);
                }
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                return(RedirectToAction("", "Cerca"));
            }
            SetMetaTag(oggetto);
            return(View(nomeView, oggetto));
        }
예제 #17
0
        public string CopiaServizio(PubblicaServizioCopiaViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                using (DatabaseContext db = new DatabaseContext())
                {
                    using (DbContextTransaction transaction = db.Database.BeginTransaction())
                    {
                        try
                        {
                            PERSONA  persona  = (Session["utente"] as PersonaModel).Persona;
                            Guid     token    = Guid.Parse(viewModel.TokenOK);
                            ANNUNCIO annuncio = db.ANNUNCIO.SingleOrDefault(m => m.TOKEN == token && m.ID_PERSONA != persona.ID);
                            if (annuncio != null)
                            {
                                // controllo se ha già quell'annuncio
                                ANNUNCIO annuncioInPossesso = db.ANNUNCIO.FirstOrDefault(m => m.ID_PERSONA == persona.ID &&
                                                                                         (m.STATO == (int)StatoVendita.ATTIVO || m.STATO == (int)StatoVendita.INATTIVO) &&
                                                                                         (m.ID == annuncio.ID || m.ID_ORIGINE == annuncio.ID));
                                if (annuncioInPossesso == null)
                                {
                                    ANNUNCIO_DESIDERATO annuncioDesiderato = db.ANNUNCIO_DESIDERATO.Where(m => m.ANNUNCIO.TOKEN == token && m.ID_PERSONA == persona.ID).SingleOrDefault();
                                    if (annuncioDesiderato != null)
                                    {
                                        db.ANNUNCIO_DESIDERATO.Remove(annuncioDesiderato);
                                        db.SaveChanges();
                                    }
                                    // copiare e salvare annuncio
                                    PubblicazioneViewModel viewModelAnnuncio = UpdateServizio(annuncio, viewModel);
                                    // copia foto
                                    List <string> fotoEsistenti = annuncio.ANNUNCIO_FOTO
                                                                  .Where(m => viewModelAnnuncio.Foto.Contains(m.ALLEGATO.NOME) == true)
                                                                  .Select(m => m.ALLEGATO.NOME).ToList();
                                    for (int i = 0; i < fotoEsistenti.Count; i++)
                                    {
                                        string path = "~/Uploads/Images/";
                                        if (annuncio.ATTIVITA != null)
                                        {
                                            path += annuncio.ATTIVITA.TOKEN;
                                        }
                                        else
                                        {
                                            path += annuncio.PERSONA.TOKEN;
                                        }

                                        string          nomeFileOriginale = Server.MapPath(path + "/" + annuncio.DATA_INSERIMENTO.Year + "/Original/" + fotoEsistenti[i]);
                                        HttpFile        fileOriginale     = new HttpFile(nomeFileOriginale);
                                        FileUploadifive fileSalvatato     = UploadImmagine("/Temp/Images/" + Session.SessionID + "/" + viewModel.TokenUploadFoto, fileOriginale);
                                        if (fileSalvatato != null)
                                        {
                                            string[] array       = viewModelAnnuncio.Foto.ToArray();
                                            int      indiceArray = Array.IndexOf(array, fileSalvatato.NomeOriginale);
                                            viewModelAnnuncio.Foto[indiceArray] = fileSalvatato.Nome;
                                        }
                                    }
                                    viewModelAnnuncio.DbContext = db;
                                    annuncioInPossesso          = new ANNUNCIO();
                                    if (viewModelAnnuncio.SalvaAnnuncio(ControllerContext, annuncioInPossesso))
                                    {
                                        int?idAnnuncio = annuncioInPossesso.ID;
                                        if (idAnnuncio != null)
                                        {
                                            // ASSEGNAZIONE CREDITI
                                            PersonaModel utente = ((PersonaModel)Session["utente"]);
                                            viewModelAnnuncio.InviaEmail(ControllerContext, annuncio, utente);
                                            decimal numeroCreditiBonus = AddBonus(db, utente, viewModelAnnuncio);
                                            TempData["BONUS"] = string.Format(Bonus.YouWin, numeroCreditiBonus, Language.Moneta);

                                            annuncioInPossesso.PERSONA = persona; // perchè sennò non riesce a recuperare l'associazione
                                            AnnuncioViewModel nuovoAnnuncio = new AnnuncioViewModel(db, annuncioInPossesso);
                                            transaction.Commit();
                                            return(RenderRazorViewToString("PartialPages/_Possiedo", nuovoAnnuncio));
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception eccezione)
                        {
                            transaction.Rollback();
                            //ErrorSignal.FromCurrentContext().Raise(eccezione);
                            LoggatoreModel.Errore(eccezione);
                        }
                    }
                }
            }
            // desiderio non registrato
            throw new Exception(ExceptionMessage.CopyAdvertising);
        }
        public ActionResult Barattato(string nome, string token)
        {
            OggettoViewModel oggetto          = new OggettoViewModel();
            string           nomeView         = "Index";
            string           nomeDecodificato = Server.UrlDecode(nome);

            try
            {
                TempData["azione"] = "View";

                string tokenDecodificato = Server.UrlDecode(token);
                string tokenPulito       = tokenDecodificato.Substring(3).Substring(0, tokenDecodificato.Length - 6);
                Guid   tokenGuid         = Guid.Parse(tokenPulito);

                // recuperare oggetto e visualizzare vista corretta
                using (DatabaseContext db = new DatabaseContext())
                {
                    ANNUNCIO vendita = new ANNUNCIO();
                    if (TempData["annuncio"] == null)
                    {
                        vendita = db.ANNUNCIO.Where(v => v.TOKEN == tokenGuid && v.NOME == nomeDecodificato && v.OGGETTO != null /*&& (v.STATO == (int)StatoVendita.BARATTOINCORSO || v.STATO == (int)StatoVendita.BARATTATO)*/).FirstOrDefault();
                    }
                    else
                    {
                        vendita = TempData["annuncio"] as ANNUNCIO;
                    }
                    nomeView                = vendita.CATEGORIA.DESCRIZIONE;
                    oggetto.Id              = (int)vendita.ID_OGGETTO;
                    oggetto.CategoriaID     = vendita.ID_CATEGORIA;
                    oggetto.Categoria       = vendita.CATEGORIA.NOME;
                    oggetto.Token           = Utils.RandomString(3) + vendita.TOKEN.ToString() + Utils.RandomString(3);
                    oggetto.Citta           = vendita.OGGETTO.COMUNE.NOME;
                    oggetto.DataInserimento = vendita.DATA_INSERIMENTO;
                    oggetto.VenditoreToken  = vendita.PERSONA.TOKEN;
                    //oggetto.Foto = vendita.ANNUNCIO_FOTO.Select(f => f.FOTO).ToList();
                    oggetto.Foto                = vendita.ANNUNCIO_FOTO.Where(f => f.ID_ANNUNCIO == vendita.ID).Select(f => f.FOTO.FOTO1).ToList();
                    oggetto.Marca               = vendita.OGGETTO.MARCA.NOME;
                    oggetto.Nome                = vendita.NOME;
                    oggetto.Punti               = vendita.PUNTI;
                    oggetto.Soldi               = vendita.SOLDI;
                    oggetto.StatoOggetto        = (CondizioneOggetto)vendita.OGGETTO.CONDIZIONE;
                    oggetto.TipoPagamento       = (TipoPagamento)vendita.TIPO_PAGAMENTO;
                    oggetto.VenditoreID         = vendita.ID_PERSONA;
                    oggetto.VenditoreNominativo = vendita.PERSONA.NOME + ' ' + vendita.PERSONA.COGNOME;
                    oggetto.Note                = vendita.NOTE_AGGIUNTIVE;
                    oggetto.Quantità            = vendita.OGGETTO.NUMERO_PEZZI;
                    //oggetto = SetOggettoViewModel(db, oggetto);
                    oggetto = SetInfoCategoriaOggetto(vendita.OGGETTO, oggetto);
                    SetFeedbackVenditoreOggetto(db, oggetto);

                    ViewBag.Title = App_GlobalResources.Language.Buy + " " + oggetto.Nome + " " + App_GlobalResources.Language.Gratis;
                }
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                return(RedirectToAction("", "Cerca"));
            }

            return(View(nomeView, oggetto));
        }
예제 #19
0
        public ActionResult Acquista(string nome, string token)
        {
            ServizioViewModel servizio = new ServizioViewModel();
            string            nomeView = "Index";

            try
            {
                TempData["azione"] = "Buy";

                string tokenDecodificato = Server.UrlDecode(token);
                string tokenPulito       = tokenDecodificato.Substring(3).Substring(0, tokenDecodificato.Length - 6);
                Guid   tokenGuid         = Guid.Parse(tokenPulito);

                // recuperare oggetto e visualizzare vista corretta
                using (DatabaseContext db = new DatabaseContext())
                {
                    ANNUNCIO vendita = db.ANNUNCIO.Where(v => v.TOKEN == tokenGuid && v.NOME == nome && v.SERVIZIO != null).FirstOrDefault();
                    // reindirizza alla lista generale di oggetti
                    if (vendita == null)
                    {
                        return(RedirectToAction("Tutti", "Servizi"));
                    }
                    else if (vendita.STATO == (int)StatoVendita.BARATTATO || vendita.STATO == (int)StatoVendita.BARATTOINCORSO)
                    {
                        return(RedirectToAction("Barattato", "Servizio", new { nome = nome, token = token }));
                    }

                    nomeView                 = vendita.CATEGORIA.DESCRIZIONE;
                    servizio.Id              = (int)vendita.ID_SERVIZIO;
                    servizio.CategoriaID     = vendita.ID_CATEGORIA;
                    servizio.Categoria       = vendita.CATEGORIA.NOME;
                    servizio.Token           = Utils.RandomString(3) + Utils.Encode(vendita.TOKEN.ToString()) + Utils.RandomString(3);
                    servizio.Citta           = vendita.SERVIZIO.COMUNE.NOME;
                    servizio.DataInserimento = vendita.DATA_INSERIMENTO;
                    servizio.VenditoreToken  = vendita.PERSONA.TOKEN;
                    servizio.Foto            = vendita.ANNUNCIO_FOTO.Select(f => f.FOTO.FOTO1).ToList();
                    servizio.Nome            = vendita.NOME;
                    servizio.Punti           = vendita.PUNTI;
                    servizio.Soldi           = vendita.SOLDI;
                    servizio.Lunedi          = (bool)vendita.SERVIZIO.LUNEDI;
                    servizio.Martedi         = (bool)vendita.SERVIZIO.MARTEDI;
                    servizio.Mercoledi       = (bool)vendita.SERVIZIO.MERCOLEDI;
                    servizio.Giovedi         = (bool)vendita.SERVIZIO.GIOVEDI;
                    servizio.Venerdi         = (bool)vendita.SERVIZIO.VENERDI;
                    servizio.Sabato          = (bool)vendita.SERVIZIO.SABATO;
                    servizio.Domenica        = (bool)vendita.SERVIZIO.DOMENICA;
                    if (vendita.SERVIZIO.TUTTI != null)
                    {
                        servizio.Tutti = (bool)vendita.SERVIZIO.TUTTI;
                    }
                    servizio.OraInizio = (TimeSpan)vendita.SERVIZIO.ORA_INIZIO_FERIALI;
                    servizio.OraFine   = (TimeSpan)vendita.SERVIZIO.ORA_FINE_FERIALI;
                    if (vendita.SERVIZIO.ORA_INIZIO_FESTIVI != null)
                    {
                        servizio.OraInizioFestivita = (TimeSpan)vendita.SERVIZIO.ORA_INIZIO_FESTIVI;
                    }
                    if (vendita.SERVIZIO.ORA_FINE_FESTIVI != null)
                    {
                        servizio.OraFineFestivita = (TimeSpan)vendita.SERVIZIO.ORA_FINE_FESTIVI;
                    }
                    servizio.RisultatiFinali     = vendita.SERVIZIO.RISULTATI_FINALI;
                    servizio.ServiziOfferti      = vendita.SERVIZIO.SERVIZI_OFFERTI;
                    servizio.TipoPagamento       = (TipoPagamento)vendita.TIPO_PAGAMENTO;
                    servizio.VenditoreID         = vendita.ID_PERSONA;
                    servizio.VenditoreNominativo = vendita.PERSONA.NOME + ' ' + vendita.PERSONA.COGNOME;
                    servizio.Tariffa             = (Tariffa)vendita.SERVIZIO.TARIFFA;
                    servizio.StatoVendita        = (StatoVendita)vendita.STATO;
                    servizio = SetServizioViewModel(db, servizio);
                    SetFeedbackVenditoreServizio(db, servizio);
                    // verifico che non stia provando ad accedere il venditore stesso
                    if (servizio.VenditoreID == (Session["utente"] as PersonaModel).Persona.ID)
                    {
                        TempData["azione"] = "View";
                    }
                }
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
            }
            ViewBag.Title       = string.Format(App_GlobalResources.MetaTag.TitleService, servizio.Nome, servizio.Categoria);
            ViewBag.Description = string.Format(App_GlobalResources.MetaTag.DescriptionService, servizio.Nome, servizio.Categoria, servizio.Citta, servizio.Punti);
            ViewBag.Keywords    = string.Format(App_GlobalResources.MetaTag.KeywordsService, servizio.Nome, servizio.Categoria, servizio.Citta, servizio.Punti);
            return(View(nomeView, servizio));
        }
예제 #20
0
        public ActionResult Acquista(ServizioViewModel model)
        {
            if (model == null || string.IsNullOrWhiteSpace(model.Token))
            {
                return(Redirect("/Servizi/Tutti"));
            }

            if (model.Offerta.TipoOfferta == TipoOfferta.Baratto && model.Offerta.ServiziBarattati != null && model.Offerta.ServiziBarattati.Length > 4)
            {
                ModelState.AddModelError("ErroreOfferta", ErroreOfferta.PrezzoErrato.ToString());
            }

            if (CheckUtenteAttivo(1))
            {
                return(RedirectToAction("Impostazioni", "Utente"));
            }

            string nomeView = "Index";

            try
            {
                using (DatabaseContext db = new DatabaseContext())
                {
                    string tokenDecodificato = Server.UrlDecode(model.Token);
                    string tokenPulito       = tokenDecodificato.Substring(3).Substring(0, tokenDecodificato.Length - 6);
                    Guid   tokenGuid         = Guid.Parse(tokenPulito);

                    if (ModelState.IsValid)
                    {
                        ObjectParameter errore = new ObjectParameter("Errore", typeof(int));
                        errore.Value = 0;
                        string baratti = "";
                        if (model.Offerta.TipoOfferta == TipoOfferta.Baratto)
                        {
                            XElement xml = new XElement("Root",
                                                        model.Offerta.ServiziBarattati.Select((i, index)
                                                                                              => new XElement("Guid", i)
                                                                                              )
                                                        );
                            baratti = xml.ToString();
                        }

                        int?idOfferta = db.BENE_SAVE_OFFERTA_SERVIZIO(tokenGuid, ((PersonaModel)Session["utente"]).Persona.ID_CONTO_CORRENTE, 1, (int)model.Offerta.TipoOfferta, model.Offerta.PuntiOfferti, Utils.cambioValuta(model.Offerta.PuntiOfferti), baratti, errore);

                        if (idOfferta != null && Convert.ToInt32(errore.Value) == 0)
                        {
                            // impostare invio email offerta effettuata
                            EmailModel email = new EmailModel(ControllerContext);
                            email.To.Add(new System.Net.Mail.MailAddress(model.VenditoreToken.ToString(), App_GlobalResources.Email.BidOf + " " + model.VenditoreNominativo + " - " + System.Web.Configuration.WebConfigurationManager.AppSettings["nomeSito"]));
                            email.Subject   = App_GlobalResources.Email.BidSubject + " " + model.Nome;
                            email.Body      = "Offerta";
                            email.DatiEmail = model;
                            new EmailController().SendEmail(email);

                            return(RedirectToAction("OffertaInviata", "Servizio", new { idOfferta = idOfferta }));
                        }

                        // ERRORE
                        ModelState.AddModelError("ErroreOfferta", ((ErroreOfferta)errore.Value).GetDisplayName());
                    }
                    else
                    {
                        ModelState.AddModelError("ErroreOfferta", App_GlobalResources.Language.ErrorGenericBid);
                    }
                    int idUtente = (Session["utente"] as PersonaModel).Persona.ID;
                    // recupero le informazioni sul servizio
                    ANNUNCIO vendita = db.ANNUNCIO.Where(v => v.TOKEN == tokenGuid && v.SERVIZIO != null && v.ID_PERSONA != idUtente && (v.STATO == (int)StatoVendita.ATTIVO || v.STATO == (int)StatoVendita.BARATTOINCORSO)).FirstOrDefault();
                    // reindirizza alla lista generale di servizi
                    if (vendita == null)
                    {
                        return(RedirectToAction("Tutti", "Servizi"));
                    }
                    nomeView                  = vendita.CATEGORIA.DESCRIZIONE;
                    model.Id                  = (int)vendita.ID_SERVIZIO;
                    model.CategoriaID         = vendita.ID_CATEGORIA;
                    model.Categoria           = vendita.CATEGORIA.NOME;
                    model.Token               = Utils.RandomString(3) + vendita.TOKEN.ToString() + Utils.RandomString(3);
                    model.Citta               = vendita.OGGETTO.COMUNE.NOME;
                    model.DataInserimento     = vendita.DATA_INSERIMENTO;
                    model.VenditoreToken      = vendita.PERSONA.TOKEN;
                    model.Foto                = vendita.ANNUNCIO_FOTO.Select(f => f.FOTO.FOTO1).ToList();
                    model.Nome                = vendita.NOME;
                    model.Punti               = vendita.PUNTI;
                    model.Soldi               = vendita.SOLDI;
                    model.Lunedi              = (bool)vendita.SERVIZIO.LUNEDI;
                    model.Martedi             = (bool)vendita.SERVIZIO.MARTEDI;
                    model.Mercoledi           = (bool)vendita.SERVIZIO.MERCOLEDI;
                    model.Giovedi             = (bool)vendita.SERVIZIO.GIOVEDI;
                    model.Venerdi             = (bool)vendita.SERVIZIO.VENERDI;
                    model.Sabato              = (bool)vendita.SERVIZIO.SABATO;
                    model.Domenica            = (bool)vendita.SERVIZIO.DOMENICA;
                    model.Tutti               = (bool)vendita.SERVIZIO.TUTTI;
                    model.OraInizio           = (TimeSpan)vendita.SERVIZIO.ORA_INIZIO_FERIALI;
                    model.OraFine             = (TimeSpan)vendita.SERVIZIO.ORA_FINE_FERIALI;
                    model.OraInizio           = (TimeSpan)vendita.SERVIZIO.ORA_INIZIO_FESTIVI;
                    model.OraFine             = (TimeSpan)vendita.SERVIZIO.ORA_FINE_FESTIVI;
                    model.TipoPagamento       = (TipoPagamento)vendita.TIPO_PAGAMENTO;
                    model.VenditoreID         = vendita.ID_PERSONA;
                    model.VenditoreNominativo = vendita.PERSONA.NOME + ' ' + vendita.PERSONA.COGNOME;
                    model.Tariffa             = (Tariffa)vendita.SERVIZIO.TARIFFA;
                    model.StatoVendita        = (StatoVendita)vendita.STATO;
                    model = SetServizioViewModel(db, model);
                    SetFeedbackVenditoreServizio(db, model);
                }
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
            }

            return(View(nomeView, model));
        }
예제 #21
0
        private PubblicazioneViewModel UpdateOggetto(ANNUNCIO model, PubblicaOggettoCopiaViewModel viewModelCopia)
        {
            PubblicazioneViewModel viewModel = null;

            if (model.ID_CATEGORIA == 12)
            {
                viewModel = new PubblicaTelefoniSmartphoneViewModel(model);
            }
            else if (model.ID_CATEGORIA == 64)
            {
                viewModel = new PubblicaConsoleViewModel(model);
            }
            else if (model.ID_CATEGORIA == 13 || (model.ID_CATEGORIA >= 62 && model.ID_CATEGORIA <= 63) || model.ID_CATEGORIA == 65)
            {
                viewModel = new PubblicaTecnologiaViewModel(model);
            }
            else if (model.ID_CATEGORIA == 14)
            {
                viewModel = new PubblicaPcViewModel(model);
            }
            else if (model.ID_CATEGORIA == 26)
            {
                viewModel = new PubblicaElettrodomesticoViewModel(model);
            }
            else if ((model.ID_CATEGORIA >= 28 && model.ID_CATEGORIA <= 39) || model.ID_CATEGORIA == 41)
            {
                viewModel = new PubblicaMusicaViewModel(model);
            }
            else if (model.ID_CATEGORIA == 40)
            {
                viewModel = new PubblicaStrumentoViewModel(model);
            }
            else if (model.ID_CATEGORIA == 45)
            {
                viewModel = new PubblicaVideogamesViewModel(model);
            }
            else if (model.ID_CATEGORIA >= 42 && model.ID_CATEGORIA <= 47)
            {
                viewModel = new PubblicaGiocoViewModel(model);
            }
            else if (model.ID_CATEGORIA >= 50 && model.ID_CATEGORIA <= 61)
            {
                viewModel = new PubblicaSportViewModel(model);
            }
            else if (model.ID_CATEGORIA >= 67 && model.ID_CATEGORIA <= 80)
            {
                viewModel = new PubblicaVideoViewModel(model);
            }
            else if (model.ID_CATEGORIA >= 81 && model.ID_CATEGORIA <= 85)
            {
                viewModel = new PubblicaLibroViewModel(model);
            }
            else if (model.ID_CATEGORIA >= 89 && model.ID_CATEGORIA <= 93)
            {
                viewModel = new PubblicaVeicoloViewModel(model);
            }
            else if (model.ID_CATEGORIA >= 127 && model.ID_CATEGORIA <= 170 && model.ID_CATEGORIA != 161 && model.ID_CATEGORIA != 152 && model.ID_CATEGORIA != 141 && model.ID_CATEGORIA != 127)
            {
                viewModel = new PubblicaVestitoViewModel(model);
            }
            else
            {
                viewModel = new PubblicaOggettoViewModel(model);
            }
            // se è stato copiato l'annuncio, allora riporto le modifiche
            if (viewModel != null)
            {
                viewModel.Update(viewModelCopia);
            }

            return(viewModel);
        }
예제 #22
0
        public ActionResult Index(FeedbackViewModel viewModel)
        {
            using (DatabaseContext db = new DatabaseContext())
            {
                try
                {
                    if (ModelState.IsValid)
                    {
                        db.Database.Connection.Open();
                        //string acquistoDecodificato = Uri.UnescapeDataString(viewModel.AcquistoID);
                        //string acquistoPulito = acquistoDecodificato.Trim().Substring(3, acquistoDecodificato.Trim().Length - 6);
                        //int idAcquisto = Utility.DecodeToInt(acquistoPulito);
                        PersonaModel      utente = (Session["utente"] as PersonaModel);
                        ANNUNCIO_FEEDBACK model  = db.ANNUNCIO_FEEDBACK.Include("Annuncio.Persona").Where(f => f.ID_VOTANTE == utente.Persona.ID && f.ID_ANNUNCIO == viewModel.AcquistoID).SingleOrDefault();
                        if (model != null)
                        {
                            TempData["feedback"] = model;
                            TempData["salvato"]  = Language.SavedFeedback;
                            return(RedirectToAction("Inviato", new { id = model.ID }));
                        }

                        model = new ANNUNCIO_FEEDBACK();
                        ANNUNCIO model2 = null;
                        if (viewModel.Tipo == TipoFeedback.Acquirente)
                        {
                            model2 = db.ANNUNCIO.Where(p => p.ID == viewModel.AcquistoID && p.ID_PERSONA != utente.Persona.ID).SingleOrDefault();
                        }
                        else if (viewModel.Tipo == TipoFeedback.Venditore)
                        {
                            model2 = db.ANNUNCIO.Where(p => p.ID == viewModel.AcquistoID && p.ID_PERSONA == utente.Persona.ID).SingleOrDefault();
                        }

                        if (model2 != null)
                        {
                            model.ID_ANNUNCIO      = model2.ID;
                            model.ID_VOTANTE       = utente.Persona.ID;
                            model.VOTO             = viewModel.Voto;
                            model.COMMENTO         = viewModel.Opinione;
                            model.DATA_INSERIMENTO = DateTime.Now;
                            model.DATA_MODIFICA    = model.DATA_INSERIMENTO;
                            model.STATO            = (int)Stato.ATTIVO;
                            db.ANNUNCIO_FEEDBACK.Add(model);
                            if (db.SaveChanges() > 0)
                            {
                                // feedback salvato
                                AddBonusFeedback(utente.Persona, db, Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["bonusFeedback"]), model.ID_ANNUNCIO);
                                return(RedirectToAction("Inviato", new { id = model.ID, nuovo = true }));
                            }
                        }
                        ModelState.AddModelError("Errore", Language.ErrorFeedback);
                    }
                }
                catch (Exception exception)
                {
                    //Elmah.ErrorSignal.FromCurrentContext().Raise(exception);
                    LoggatoreModel.Errore(exception);
                    // 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());
        }
        public ActionResult Acquista(OggettoViewModel model)
        {
            // VERIFICARE CHE TI MANDI VERAMENTE AL REDIRECT SU TUTTI!
            if (model == null || string.IsNullOrWhiteSpace(model.Token))
            {
                return(RedirectToAction("", "Cerca"));
            }

            if (model.Offerta.TipoOfferta == TipoOfferta.Baratto && model.Offerta.OggettiBarattati != null && model.Offerta.OggettiBarattati.Length > 4)
            {
                ModelState.AddModelError("ErroreOfferta", ErroreOfferta.PrezzoErrato.ToString());
            }

            if (CheckUtenteAttivo(1))
            {
                return(RedirectToAction("Impostazioni", "Utente"));
            }

            string nomeView = "Index";

            try
            {
                using (DatabaseContext db = new DatabaseContext())
                {
                    string tokenDecodificato = Server.UrlDecode(model.Token);
                    string tokenPulito       = tokenDecodificato.Substring(3).Substring(0, tokenDecodificato.Length - 6);
                    Guid   tokenGuid         = Guid.Parse(tokenPulito);

                    if (ModelState.IsValid)
                    {
                        ObjectParameter errore = new ObjectParameter("Errore", typeof(int));
                        errore.Value = 0;
                        string baratti = "";
                        if (model.Offerta.TipoOfferta == TipoOfferta.Baratto)
                        {
                            XElement xml = new XElement("Root",
                                                        model.Offerta.OggettiBarattati.Select((i, index)
                                                                                              => new XElement("Guid", i)
                                                                                              )
                                                        );
                            baratti = xml.ToString();
                        }

                        int?idOfferta = db.BENE_SAVE_OFFERTA(tokenGuid, ((PersonaModel)Session["utente"]).Persona.ID_CONTO_CORRENTE, 1, (int)model.Offerta.TipoOfferta, model.Offerta.PuntiOfferti, Utils.cambioValuta(model.Offerta.PuntiOfferti), baratti, errore).FirstOrDefault();

                        if (idOfferta != null && Convert.ToInt32(errore.Value) == 0)
                        {
                            // impostare invio email offerta effettuata

                            /*EmailModel email = new EmailModel(ControllerContext);
                             * email.To.Add(new System.Net.Mail.MailAddress(model.Email, App_GlobalResources.Email.BidOf + " " + model.VenditoreNominativo + " - " + WebConfigurationManager.AppSettings["nomeSito"]));
                             * email.Subject = App_GlobalResources.Email.BidSubject + " " + model.Nome;
                             * email.Body = "Offerta";
                             * email.DatiEmail = model;
                             * new EmailController().SendEmail(email);*/

                            return(RedirectToAction("OffertaInviata", "Oggetto", new { idOfferta = idOfferta }));
                        }

                        // ERRORE
                        ModelState.AddModelError("ErroreOfferta", ((ErroreOfferta)errore.Value).GetDisplayName());
                    }
                    else
                    {
                        ModelState.AddModelError("ErroreOfferta", App_GlobalResources.Language.ErrorGenericBid);
                    }

                    int idUtente = (Session["utente"] as PersonaModel).Persona.ID;
                    // recupero le informazioni sull'oggetto
                    ANNUNCIO vendita = db.ANNUNCIO.Where(v => v.TOKEN == tokenGuid && v.OGGETTO != null && v.ID_PERSONA != idUtente && (v.STATO == (int)StatoVendita.ATTIVO || v.STATO == (int)StatoVendita.BARATTOINCORSO)).FirstOrDefault();
                    // reindirizza alla lista generale di oggetti
                    if (vendita == null)
                    {
                        return(RedirectToAction("", "Cerca"));
                    }
                    nomeView              = vendita.CATEGORIA.DESCRIZIONE;
                    model.Id              = (int)vendita.ID_OGGETTO;
                    model.CategoriaID     = vendita.ID_CATEGORIA;
                    model.Categoria       = nomeView;
                    model.Token           = Utils.RandomString(3) + vendita.TOKEN.ToString() + Utils.RandomString(3);
                    model.Citta           = vendita.OGGETTO.COMUNE.NOME;
                    model.DataInserimento = vendita.DATA_INSERIMENTO;
                    model.VenditoreToken  = vendita.PERSONA.TOKEN;
                    //model.Foto = vendita.ANNUNCIO_FOTO.Select(f => f.FOTO).ToList();
                    model.Foto                = vendita.ANNUNCIO_FOTO.Where(f => f.ID_ANNUNCIO == vendita.ID).Select(f => f.FOTO.FOTO1).ToList();
                    model.Marca               = vendita.OGGETTO.MARCA.NOME;
                    model.Nome                = vendita.NOME;
                    model.Punti               = vendita.PUNTI;
                    model.Soldi               = vendita.SOLDI;
                    model.StatoOggetto        = (CondizioneOggetto)vendita.OGGETTO.CONDIZIONE;
                    model.TipoPagamento       = (TipoPagamento)vendita.TIPO_PAGAMENTO;
                    model.VenditoreID         = vendita.ID_PERSONA;
                    model.VenditoreNominativo = vendita.PERSONA.NOME + ' ' + vendita.PERSONA.COGNOME;
                    model.Note                = vendita.NOTE_AGGIUNTIVE;
                    model.Quantità            = vendita.OGGETTO.NUMERO_PEZZI;
                    //model = SetOggettoViewModel(db, model);
                    model = SetInfoCategoriaOggetto(vendita.OGGETTO, model);
                    SetFeedbackVenditoreOggetto(db, model);
                }
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                return(RedirectToAction("", "Cerca"));
            }

            return(View(nomeView, model));
        }