Exemplo n.º 1
0
 public JsonResult UploadImmagine(HttpPostedFileBase file)
 {
     if (file != null && Utility.CheckFormatoFile(file))
     {
         string antiForgeryToken = Request.Form.Get("__TokenUploadFoto");
         if (!string.IsNullOrWhiteSpace(antiForgeryToken) && !antiForgeryToken.ToLower().Equals("undefined"))
         {
             FileUploadifive foto = UploadImmagine("/Temp/Images/" + Session.SessionID + "/" + antiForgeryToken, file);
             foto.Id = foto.Nome;
             string   pathBase                = Path.Combine(Server.MapPath("~/Temp/Images/"), Session.SessionID, antiForgeryToken, "Little");
             string[] listaFotoUpload         = Directory.GetFiles(pathBase);
             PubblicaListaFotoViewModel model = new PubblicaListaFotoViewModel();
             model.TokenUploadFoto = antiForgeryToken;
             if (listaFotoUpload != null && listaFotoUpload.Length > 0)
             {
                 model.Foto = listaFotoUpload.Select(m => new FileInfo(m).Name).ToList();
             }
             string htmlGalleriaFotoAnnuncio = RenderRazorViewToString("PartialPages/_GalleriaFotoAnnuncio", model);
             return(Json(new { Success = true, responseText = htmlGalleriaFotoAnnuncio, Foto = foto }));
         }
         //return Json(new { Success = true, responseText = foto });
     }
     //messaggio di errore
     return(Json(new { Success = false, responseText = Language.ErrorFormatFile }));
 }
Exemplo n.º 2
0
        public JsonResult UploadImmagineProfilo(HttpPostedFileBase file, string token)
        {
            PortaleWebViewModel utente = (Session["portaleweb"] as List <PortaleWebViewModel>).SingleOrDefault(m => m.Token == token);

            if (utente == null)
            {
                return(Json(new { Success = false, responseText = ErrorResource.HappyShopNotFound }));
            }
            FileUploadifive fileSalvato = UploadImmagine("/Uploads/Images/" + utente.Token + "/" + DateTime.Now.Year.ToString(), file);
            FotoModel       model       = new FotoModel();

            using (DatabaseContext db = new DatabaseContext())
            {
                db.Database.Connection.Open();
                int idAllegato = model.Add(db, fileSalvato.Nome);
                if (idAllegato > 0)
                {
                    // salvo allegato come immagine del profilo
                    utente.SetImmagineProfilo(db, idAllegato);
                    if (utente.Foto != null && utente.Foto.Count > 0)
                    {
                        string htmlGalleriaFotoProfilo = RenderRazorViewToString("PartialPages/_GalleriaFotoProfilo", new PortaleWebProfiloViewModel(utente));
                        return(Json(new { Success = true, responseText = htmlGalleriaFotoProfilo }));
                    }
                }
            }
            //Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest;
            //return null;
            return(Json(new { Success = false, responseText = Language.ErrorFormatFile }));
        }
Exemplo n.º 3
0
        public ActionResult SpedizioniConcluse(SpedizioneViewModel viewModel)
        {
            List <SpedizioneViewModel> lista = new List <SpedizioneViewModel>();

            using (DatabaseContext db = new DatabaseContext())
            {
                int token = viewModel.Id;
                if (ModelState.IsValid)
                {
                    // effettuo modifica
                    if (viewModel.LDV != null && Utility.CheckFormatoFile(viewModel.LDV, TipoMedia.TESTO))
                    {
                        CORRIERE_SERVIZIO_SPEDIZIONE spedizione = db.CORRIERE_SERVIZIO_SPEDIZIONE.SingleOrDefault(m => m.ID == viewModel.Id);
                        if (spedizione != null)
                        {
                            var    annuncio      = spedizione.ANNUNCIO_TIPO_SCAMBIO_SPEDIZIONE.FirstOrDefault().ANNUNCIO_TIPO_SCAMBIO.ANNUNCIO;
                            string tokenMittente = annuncio.PERSONA.TOKEN.ToString();
                            if (annuncio.ID_ATTIVITA != null)
                            {
                                tokenMittente = annuncio.ATTIVITA.TOKEN.ToString();
                            }
                            // cambiare percorso di salvataggio
                            FileUploadifive allegatoPdf = UploadFile(viewModel.LDV, TipoUpload.Pdf, tokenMittente);
                            PdfModel        model       = new PdfModel();
                            spedizione.ID_LDV        = model.Add(db, allegatoPdf.Nome);
                            spedizione.DATA_MODIFICA = DateTime.Now;
                            spedizione.STATO         = (int)StatoSpedizione.LDV;
                            // non modifica
                            db.CORRIERE_SERVIZIO_SPEDIZIONE.Attach(spedizione);
                            db.Entry <CORRIERE_SERVIZIO_SPEDIZIONE>(spedizione).State = System.Data.Entity.EntityState.Modified;
                            db.SaveChanges();
                        }
                        else
                        {
                            ViewBag.Message = "Errore nel caricamento dell'LDV! Riprovare più tardi!";
                        }
                    }
                }
                else
                {
                    ViewBag.Message = "Inserire LDV da caricare.";
                }
                token = 0;
                lista = db.SPEDIZIONE_CONCLUSA
                        .Where(m => m.ID == token || token <= 0)
                        .Select(m => new SpedizioneViewModel()
                {
                    Id           = m.ID,
                    NomeAnnuncio = m.NOME,
                    Prezzo       = 0,
                    Stato        = Stato.ATTIVO
                }).ToList();
            }
            return(View(lista));
        }
Exemplo n.º 4
0
        protected FileUploadifive UploadFile(HttpPostedFileBase file, TipoUpload tipo, string tokenUtente)
        {
            FileUploadifive fileUpload = new FileUploadifive();

            if (file != null && file.ContentLength > 0)
            {
                string estensione = new FileInfo(Path.GetFileName(file.FileName)).Extension;
                fileUpload.NomeOriginale = file.FileName;
                fileUpload.Nome          = System.Guid.NewGuid().ToString() + estensione;

                fileUpload.PathOriginale = Request.Url.GetLeftPart(UriPartial.Authority) + "/Uploads/Text/" + tokenUtente + "/" + DateTime.Now.Year.ToString() + "/Original/";
                string directoryOriginale = Server.MapPath("~/Uploads/Text/" + tokenUtente + "/" + DateTime.Now.Year.ToString() + "/Original/");

                Directory.CreateDirectory(directoryOriginale);

                file.SaveAs(Path.Combine(directoryOriginale, fileUpload.Nome));
                return(fileUpload);
            }
            return(null);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        public ActionResult SpedizioniInAttesa(SpedizioneViewModel viewModel)
        {
            List <SpedizioneViewModel> lista = new List <SpedizioneViewModel>();

            using (DatabaseContext db = new DatabaseContext())
            {
                db.Database.Connection.Open();
                int token = viewModel.Id;
                if (ModelState.IsValid)
                {
                    // effettuo modifica
                    if (viewModel.LDV != null && Utility.CheckFormatoFile(viewModel.LDV, TipoMedia.TESTO))
                    {
                        CORRIERE_SERVIZIO_SPEDIZIONE spedizione = db.CORRIERE_SERVIZIO_SPEDIZIONE
                                                                  .Include(m => m.INDIRIZZO.PERSONA_INDIRIZZO)
                                                                  .Include(m => m.INDIRIZZO1.PERSONA_INDIRIZZO)
                                                                  .SingleOrDefault(m => m.ID == viewModel.Id);
                        if (spedizione != null)
                        {
                            var    annuncio      = spedizione.ANNUNCIO_TIPO_SCAMBIO_SPEDIZIONE.FirstOrDefault().ANNUNCIO_TIPO_SCAMBIO.ANNUNCIO;
                            string tokenMittente = annuncio.PERSONA.TOKEN.ToString();
                            if (annuncio.ID_ATTIVITA != null)
                            {
                                tokenMittente = annuncio.ATTIVITA.TOKEN.ToString();
                            }
                            // cambiare percorso di salvataggio
                            FileUploadifive allegatoPdf = UploadFile(viewModel.LDV, TipoUpload.Pdf, tokenMittente);
                            PdfModel        model       = new PdfModel();
                            spedizione.ID_LDV        = model.Add(db, allegatoPdf.Nome);
                            spedizione.DATA_MODIFICA = DateTime.Now;
                            spedizione.STATO         = (int)StatoSpedizione.LDV;
                            // non modifica
                            db.CORRIERE_SERVIZIO_SPEDIZIONE.Attach(spedizione);
                            db.Entry <CORRIERE_SERVIZIO_SPEDIZIONE>(spedizione).State = System.Data.Entity.EntityState.Modified;
                            db.SaveChanges();

                            var mittente     = spedizione.INDIRIZZO.PERSONA_INDIRIZZO.FirstOrDefault().PERSONA;
                            var destinatario = spedizione.INDIRIZZO1.PERSONA_INDIRIZZO.FirstOrDefault().PERSONA;
                            var modelEmail   = db.PERSONA_EMAIL.Where(m => m.ID_PERSONA == destinatario.ID && m.TIPO == (int)TipoEmail.Registrazione).FirstOrDefault();
                            // invio email
                            EmailModel email = new EmailModel(ControllerContext);
                            email.To.Add(new System.Net.Mail.MailAddress(modelEmail.EMAIL, mittente.NOME + " " + mittente.COGNOME));
                            email.Subject     = string.Format(App_GlobalResources.Email.LDVSubject, viewModel.NomeAnnuncio) + " - " + System.Web.Configuration.WebConfigurationManager.AppSettings["nomeSito"];
                            email.Body        = "LDV";
                            email.DatiEmail   = viewModel;
                            email.Attachments = new List <System.Web.HttpPostedFileBase>()
                            {
                                viewModel.LDV
                            };
                            new EmailController().SendEmail(email);
                        }
                        else
                        {
                            ViewBag.Message = "Errore nel caricamento dell'LDV! Riprovare più tardi!";
                        }
                    }
                }
                else
                {
                    ViewBag.Message = "Inserire LDV da caricare.";
                }
                token = 0;
                lista = db.SPEDIZIONE_INATTESA
                        .Where(m => m.ID == token || token <= 0)
                        .Select(m => new SpedizioneViewModel()
                {
                    Id           = m.ID,
                    NomeAnnuncio = m.NOME_ANNUNCIO,
                    Destinatario = m.NOME + " " + m.COGNOME_RAGSOC,
                    Prezzo       = m.PREZZO,
                    Stato        = Stato.ATTIVO
                }).ToList();
            }
            return(View(lista));
        }
Exemplo n.º 7
0
        protected FileUploadifive UploadImmagine(string path, HttpPostedFileBase file)
        {
            FileUploadifive fileUpload = new FileUploadifive();

            if (file != null && file.ContentLength > 0)
            {
                FileInfo informazioniFile = new FileInfo(Path.GetFileName(file.FileName));
                string   estensione       = informazioniFile.Extension;
                fileUpload.NomeOriginale = informazioniFile.Name;
                fileUpload.Nome          = System.Guid.NewGuid().ToString() + estensione;

                fileUpload.PathOriginale = Request.Url.GetLeftPart(UriPartial.Authority) + path + "/Original";
                fileUpload.PathMedia     = Request.Url.GetLeftPart(UriPartial.Authority) + path + "/Normal";
                fileUpload.PathPiccola   = Request.Url.GetLeftPart(UriPartial.Authority) + path + "/Little";
                string directoryOriginale = Server.MapPath("~" + path + "/Original");
                string directoryMedia     = Server.MapPath("~" + path + "/Normal");
                string directoryPiccola   = Server.MapPath("~" + path + "/Little");

                Directory.CreateDirectory(directoryOriginale);
                Directory.CreateDirectory(directoryMedia);
                Directory.CreateDirectory(directoryPiccola);

                file.SaveAs(Path.Combine(directoryOriginale, fileUpload.Nome));
                using (Image img = Image.FromFile(Path.Combine(directoryOriginale, fileUpload.Nome), true))
                {
                    int widthMedia    = 300;
                    int heightMedia   = 300;
                    int widthPiccola  = 100;
                    int heightPiccola = 100;
                    // se orizzontale setto l'altezza altrimenti la larghezza
                    if (img.Width > img.Height)
                    {
                        //setto altezza img media
                        decimal ratioMedia = (decimal)widthMedia / img.Width;
                        decimal tempMedia  = img.Height * ratioMedia;
                        heightMedia = (int)tempMedia;
                        //setto altezza img piccola
                        decimal ratioPiccola = (decimal)widthPiccola / img.Width;
                        decimal tempPiccola  = img.Height * ratioPiccola;
                        heightPiccola = (int)tempPiccola;
                    }
                    else
                    {
                        //setto larghezza img media
                        decimal ratioMedia = (decimal)heightMedia / img.Height;
                        decimal tempMedia  = img.Width * ratioMedia;
                        widthMedia = (int)tempMedia;
                        //setto larghezza img piccola
                        decimal ratioPiccola = (decimal)heightPiccola / img.Height;
                        decimal tempPiccola  = img.Width * ratioPiccola;
                        widthPiccola = (int)tempPiccola;
                    }
                    using (Image imgMedia = new Bitmap(img, widthMedia, heightMedia))
                    {
                        imgMedia.Save(Path.Combine(directoryMedia, fileUpload.Nome));
                    }

                    using (Image imgPiccola = new Bitmap(img, widthPiccola, heightPiccola))
                    {
                        imgPiccola.Save(Path.Combine(directoryPiccola, fileUpload.Nome));
                    }
                }
                return(fileUpload);
            }
            return(null);
        }