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)); }