Exemplo n.º 1
0
        private List <OffertaViewModel> GetListaOfferte(DatabaseContext db, int utente, int pagina)
        {
            List <OffertaViewModel> offerte = new List <OffertaViewModel>();
            var query = db.OFFERTA.Where(item => item.PERSONA.ID == utente && item.PERSONA.STATO == (int)Stato.ATTIVO
                                         //&& (item.STATO != (int)StatoOfferta.ACCETTATA && item.STATO != (int)StatoOfferta.ANNULLATA)
                                         && (
                                             item.STATO != (int)StatoOfferta.ANNULLATA &&
                                             (item.ANNUNCIO.STATO != (int)StatoVendita.BARATTATO && item.ANNUNCIO.STATO != (int)StatoVendita.ELIMINATO &&
                                              item.ANNUNCIO.STATO != (int)StatoVendita.INATTIVO && item.ANNUNCIO.STATO != (int)StatoVendita.VENDUTO)
                                             ) &&
                                         (item.ANNUNCIO.ID_OGGETTO != null || item.ANNUNCIO.ID_SERVIZIO != null));
            int numeroElementi = Convert.ToInt32(WebConfigurationManager.AppSettings["numeroElementi"]);

            ViewData["TotalePagine"] = (int)Math.Ceiling((decimal)query.Count() / (decimal)numeroElementi);
            ViewData["Pagina"]       = pagina;
            pagina -= 1;
            string         randomString = Utility.RandomString(3);
            List <OFFERTA> lista        = query
                                          .OrderByDescending(item => item.DATA_INSERIMENTO)
                                          .Skip(pagina * numeroElementi)
                                          .Take(numeroElementi).ToList();

            foreach (OFFERTA item in lista)
            {
                OffertaViewModel offertaEffettuata = new OffertaViewModel(db, item);
                offerte.Add(offertaEffettuata);
            }
            if (offerte.Count > 0)
            {
                RefreshPunteggioUtente(db);
            }

            return(offerte);
        }
Exemplo n.º 2
0
        public ActionResult OfferteRicevute(string vendita = "", int pagina = 1)
        {
            List <OffertaViewModel> offerte = new List <OffertaViewModel>();

            try
            {
                Guid?token = null;
                if (!string.IsNullOrWhiteSpace(vendita))
                {
                    token = Guid.Parse(HttpUtility.UrlDecode(vendita));
                }

                int utente = ((PersonaModel)Session["utente"]).Persona.ID;

                using (DatabaseContext db = new DatabaseContext())
                {
                    int numeroElementi = Convert.ToInt32(WebConfigurationManager.AppSettings["numeroElementi"]);
                    //var query = db.OFFERTA.Where(c => c.ANNUNCIO == idVendita && (c.STATO != (int)StatoOfferta.ANNULLATA || c.STATO != (int)StatoOfferta.INATTIVA || c.STATO != (int)StatoOfferta.SOSPESA));
                    var query = db.OFFERTA.Where(c => (token == null || c.ANNUNCIO.TOKEN == token) && c.ANNUNCIO.ID_PERSONA == utente && c.PERSONA.STATO == (int)Stato.ATTIVO);
                    ViewData["TotalePagine"] = (int)Math.Ceiling((decimal)query.Count() / (decimal)numeroElementi);
                    ViewData["Pagina"]       = pagina;
                    pagina -= 1;
                    List <OFFERTA> lista = query
                                           .OrderByDescending(item => item.DATA_INSERIMENTO)
                                           .Skip(pagina * numeroElementi)
                                           .Take(numeroElementi)
                                           .ToList();
                    // fare update LETTA della lista recuperata
                    //offerte.Id = lista.Select(o => o.ANNUNCIO.ID).FirstOrDefault();
                    //offerte.NomeVendita = lista.Select(o => o.ANNUNCIO.NOME).FirstOrDefault();
                    //offerte.DataInserimento = lista.Select(o => o.ANNUNCIO.DATA_INSERIMENTO).FirstOrDefault();
                    foreach (OFFERTA o in lista)
                    {
                        OffertaViewModel offertaEffettuata = new OffertaViewModel(db, o);
                        offerte.Add(offertaEffettuata);
                    }
                }
            }
            catch (Exception ex)
            {
                //Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                LoggatoreModel.Errore(ex);
            }

            return(View(offerte));
        }
Exemplo n.º 3
0
        public ActionResult OfferteRifiutate(int pagina = 1)
        {
            List <OffertaViewModel> offerte = new List <OffertaViewModel>();

            try
            {
                using (DatabaseContext db = new DatabaseContext())
                {
                    int utente = ((PersonaModel)Session["utente"]).Persona.ID;
                    // verifica stato offerta se attivo o non accettata, identità utente e stato di attivazione, presenza bene o servizio -- vechia
                    // verifica identità utente e stato di attivazione, presenza bene o servizio
                    var query = db.OFFERTA.Where(item => item.PERSONA.ID == utente && item.PERSONA.STATO == (int)Stato.ATTIVO &&
                                                 (item.STATO == (int)StatoOfferta.ANNULLATA) &&
                                                 (item.ANNUNCIO.ID_OGGETTO != null || item.ANNUNCIO.ID_SERVIZIO != null));
                    int numeroElementi = Convert.ToInt32(WebConfigurationManager.AppSettings["numeroElementi"]);
                    ViewData["TotalePagine"] = (int)Math.Ceiling((decimal)query.Count() / (decimal)numeroElementi);
                    ViewData["Pagina"]       = pagina;
                    pagina -= 1;
                    string         randomString = Utility.RandomString(3);
                    List <OFFERTA> lista        = query
                                                  .OrderByDescending(item => item.DATA_INSERIMENTO)
                                                  .Skip(pagina * numeroElementi)
                                                  .Take(numeroElementi).ToList();

                    foreach (OFFERTA item in lista)
                    {
                        OffertaViewModel offertaEffettuata = new OffertaViewModel(db, item);
                        offerte.Add(offertaEffettuata);
                    }
                    if (offerte.Count > 0)
                    {
                        RefreshPunteggioUtente(db);
                    }
                }
            }
            catch (Exception eccezione)
            {
                //Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                LoggatoreModel.Errore(eccezione);
            }
            return(View(offerte));
        }
Exemplo n.º 4
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));
        }
Exemplo n.º 5
0
        public ActionResult InviaOfferta(OffertaViewModel viewModel)
        {
            AnnuncioModel model     = new AnnuncioModel();
            string        messaggio = ErrorResource.BidAd;

            if (ModelState.IsValid)
            {
                if (!Utility.IsUtenteAttivo(1, TempData))
                {
                    Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest;
                    return(Json(ErrorResource.UserEnabled));
                }

                using (DatabaseContext db = new DatabaseContext())
                {
                    using (DbContextTransaction transaction = db.Database.BeginTransaction())
                    {
                        try
                        {
                            if (viewModel.Save(db, ref messaggio))
                            {
                                // aggiungere nella lista dei desideri
                                string            tokenDecodificato = HttpContext.Server.UrlDecode(viewModel.Annuncio.Token);
                                Guid              tokenGuid         = Guid.Parse(tokenDecodificato);
                                PersonaModel      utente            = (PersonaModel)HttpContext.Session["utente"];
                                AnnuncioViewModel annuncio          = null;
                                addDesiderio(db, tokenGuid, utente.Persona.ID, ref annuncio);
                                // salvare transazione
                                transaction.Commit();
                                this.RefreshPunteggioUtente(db);
                                // invia e-mail al venditore
                                if (annuncio.Venditore.Persona != null)
                                {
                                    this.SendNotifica(utente.Persona, annuncio.Venditore.Persona, TipoNotifica.OffertaRicevuta, ControllerContext, "offerta", viewModel);
                                }
                                return(Json(new { Messaggio = Language.JsonSendBid }));
                            }

                            transaction.Rollback();
                        }
                        catch (Exception eccezione)
                        {
                            //Elmah.ErrorSignal.FromCurrentContext().Raise(eccezione);
                            transaction.Rollback();
                            LoggatoreModel.Errore(eccezione);
                            Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest;
                            return(Json(eccezione.Message));
                        }
                    }
                }
            }
            else
            {
                var errori = ModelState.Where(m => m.Value.Errors.Count > 0)
                             .Select(m => m.Value.Errors.Select(n => n.ErrorMessage)).SelectMany(m => m).ToList();
                if (errori != null && errori.Count > 0)
                {
                    messaggio = string.Join("<br />", errori);
                }
            }
            // acquisto generico
            Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest;
            return(Json(messaggio));
        }
Exemplo n.º 6
0
        public ActionResult Suggeriti(int pagina = 1)
        {
            //List<ProposteAnnuncio> viewModel = new List<ProposteAnnuncio>();
            List <OffertaViewModel> viewModel = new List <OffertaViewModel>();

            try
            {
                using (DatabaseContext db = new DatabaseContext())
                {
                    db.Database.Connection.Open();
                    PersonaModel utente       = (PersonaModel)Session["utente"];
                    int          idUtente     = utente.Persona.ID;
                    int          contoAttuale = utente.Punti;

                    /*
                     * var query = db.ANNUNCIO_DESIDERATO.Where(m => m.ID_PERSONA == idUtente && // sugli annunci che desidero
                     *      (m.ANNUNCIO.PUNTI <= contoAttuale || // gli annunci che mi posso permettere
                     *          m.PERSONA.ANNUNCIO.Count(a => a.ANNUNCIO_DESIDERATO.Count(ad => ad.ID_PERSONA == m.ANNUNCIO.ID_PERSONA) > 0) > 0)); // o di cui desiderano almeno un mio annuncio
                     */
                    var query = db.ANNUNCIO_DESIDERATO.Where(m => m.ID_PERSONA == idUtente && (                                                                                     // sugli annunci che desidero
                                                                 (m.ANNUNCIO.STATO != (int)StatoVendita.ELIMINATO && m.ANNUNCIO.STATO != (int)StatoVendita.BARATTATO && m.ANNUNCIO.STATO != (int)StatoVendita.VENDUTO) &&
                                                                 m.PERSONA.CONTO_CORRENTE.CONTO_CORRENTE_MONETA.Count() >= m.ANNUNCIO.PUNTI ||                                      // se ho abbastanza crediti
                                                                 db.ANNUNCIO_DESIDERATO.Count(ad => ad.ID_PERSONA == m.ANNUNCIO.ID_PERSONA && ad.ANNUNCIO.ID_PERSONA == idUtente && // o di cui desiderano almeno un mio annuncio
                                                                                              (ad.ANNUNCIO.STATO != (int)StatoVendita.ELIMINATO && ad.ANNUNCIO.STATO != (int)StatoVendita.BARATTATO && ad.ANNUNCIO.STATO != (int)StatoVendita.VENDUTO)
                                                                                              ) > 0)
                                                             );
                    int numeroElementi = Convert.ToInt32(WebConfigurationManager.AppSettings["numeroElementi"]);
                    ViewData["TotalePagine"] = (int)Math.Ceiling((decimal)query.Count() / (decimal)numeroElementi);
                    ViewData["Pagina"]       = pagina;
                    pagina -= 1;

                    /*
                     * query.OrderByDescending(item => item.ANNUNCIO.DATA_INSERIMENTO).OrderByDescending(item => item.ID) // ordinato per inserimento annuncio e poi per inserimento desiderio
                     *  .OrderByDescending(item => item.PERSONA.ANNUNCIO.Count(a => a.ANNUNCIO_DESIDERATO.Count(ad => ad.ID_PERSONA == item.ANNUNCIO.ID_PERSONA) > 0)) // ordinato per numeri annunci desiderati da altri
                     */
                    query.OrderByDescending(item => item.ID)                                                                                                         // ordinato per inserimento annuncio e poi per inserimento desiderio
                    .OrderByDescending(item => db.ANNUNCIO_DESIDERATO.Count(ad => ad.ID_PERSONA == item.ANNUNCIO.ID_PERSONA && ad.ANNUNCIO.ID_PERSONA == idUtente && // o di cui desiderano almeno un mio annuncio
                                                                            (ad.ANNUNCIO.STATO != (int)StatoVendita.ELIMINATO && ad.ANNUNCIO.STATO != (int)StatoVendita.BARATTATO && ad.ANNUNCIO.STATO != (int)StatoVendita.VENDUTO)
                                                                            ))                                                                                       // ordinato per numeri annunci desiderati da altri
                    .Skip(pagina * numeroElementi)
                    .Take(numeroElementi)
                    .ToList().ForEach(m =>
                    {
                        /*ProposteAnnuncio proposta = new ProposteAnnuncio(db, m.ANNUNCIO);
                         * db.ANNUNCIO.Where(a => a.ID_PERSONA == idUtente && (a.ANNUNCIO_DESIDERATO.Count(ad => ad.ID_PERSONA == m.ANNUNCIO.ID_PERSONA) > 0)).ToList().ForEach(a =>
                         * {
                         *  proposta.AnnunciDesiderati.Add(new AnnuncioViewModel(db, a));
                         * });
                         *
                         * viewModel.Add(proposta);*/
                        OffertaViewModel offerta = new OffertaViewModel();
                        offerta.Annuncio         = new AnnuncioViewModel(db, m.ANNUNCIO);
                        db.ANNUNCIO.Where(a => a.ID_PERSONA == idUtente && (a.ANNUNCIO_DESIDERATO.Count(ad => ad.ID_PERSONA == m.ANNUNCIO.ID_PERSONA) > 0)).ToList().ForEach(a =>
                        {
                            offerta.Baratti.Add(new AnnuncioViewModel(db, a));
                        });

                        viewModel.Add(offerta);
                    });
                }
            }
            catch (Exception eccezione)
            {
                //Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                LoggatoreModel.Errore(eccezione);
            }
            return(View(viewModel));
        }