コード例 #1
0
ファイル: MediaAction.cs プロジェクト: cronkite-asu/SeedSpeak
 /// <summary>
 /// Method to add new Media.
 /// </summary>
 /// <param name="media"></param>
 /// <returns></returns>
 public Medium AddMedia(MediaManagement media)
 {
     #region Business Logic
     Medium objMedium = new Medium();
     try
     {
         objMedium.id = Guid.NewGuid();
         objMedium.title = media.title;
         objMedium.dateUploaded = DateTime.Now;
         objMedium.seedId = new Guid(media.seedId);
         objMedium.uploadedById = new Guid(media.uploadedById);
         objMedium.type = media.type;
         objMedium.path = media.path;
         objMedium.embedScript = media.embedScript;
         repoObj.Create<Medium>(objMedium);
     }
     catch (Exception ex)
     {
         WriteError(ex);
     }
     return objMedium;
     #endregion
 }
コード例 #2
0
 /// <summary>
 /// Method to add media.
 /// </summary>
 /// <param name="memberId"></param>
 /// <param name="newPassword"></param>
 /// <returns></returns>
 public string AddMedia(string title, string imgName, string seedId, string fileType, string memberId)
 {
     bool isMediaSaved = false;
     string isSaved = string.Empty;
     MediaManagement objMedia = new MediaManagement();
     MediaAction mediaAction = new MediaAction();
     objMedia.title = title;
     objMedia.seedId = seedId;
     objMedia.uploadedById = memberId;
     objMedia.type = fileType;
     objMedia.path = "../../UploadedMedia/" + imgName;
     objMedia.embedScript = "Image Script";
     Medium objMedium = mediaAction.AddMedia(objMedia);
     if (objMedium != null)
         isMediaSaved = true;
     if (isMediaSaved == true)
         isSaved = "Media Uploaded Successfully";
     return isSaved;
 }
コード例 #3
0
        public ActionResult EditSeedInfo(string txtEdtSeedTitle, string txtEdtDesc, string seedCoordinatesEdt, string seedLocationEdt, string txtCategoryEdt, IEnumerable<HttpPostedFileBase> mediaFilesEdt, string EdtSeedID)
        {
            #region codeRegion
            try
            {
                SeedAction objSeed = new SeedAction();
                LocationAction objLocation = new LocationAction();

                Seed seed = GetSeedInformation(EdtSeedID);
                seed.title = txtEdtSeedTitle;
                string s = Regex.Replace(txtEdtDesc, @"<(.|\n)*?>", string.Empty);
                s = s.Replace("&nbsp;", " ");
                s = Regex.Replace(s, @"\s+", " ");
                s = Regex.Replace(s, @"\r\n", "\n");
                s = Regex.Replace(s, @"\n+", "\n");
                string description = s;

                badWordsFilter objWords = new badWordsFilter();
                string wordsFilePath = Server.MapPath("~/utils/badWords.xml");
                List<string> lstBadWords = badWordsFilter.BadWordList(ref wordsFilePath);
                description = objWords.FilterBadWords(lstBadWords, description);

                seed.description = description;

                Location loc = seed.Location;
                //Format address and create add seed model
                string[] splitAddress = seedLocationEdt.Split(',');
                string[] strSplitLatLong = seedCoordinatesEdt.Split(',');
                loc.localLat = Convert.ToDouble(strSplitLatLong[0].ToString());
                loc.localLong = Convert.ToDouble(strSplitLatLong[1].ToString());

                if (splitAddress.Length > 4)
                {
                    string[] splitZipRegion = splitAddress[3].ToString().Trim().Split(' ');
                    loc.crossStreet = splitAddress[0].ToString() + ", " + splitAddress[1].ToString();
                    string cityid = objLocation.GetCityIdByCityName(splitAddress[2].ToString().Trim(), splitZipRegion[0].ToString().Trim());
                    loc.cityId = new Guid(cityid);
                    loc.zipcode = splitZipRegion[1].ToString().Trim();
                }
                else
                {
                    string[] splitZipRegion = splitAddress[2].ToString().Trim().Split(' ');
                    loc.crossStreet = splitAddress[0].ToString();
                    string cityid = objLocation.GetCityIdByCityName(splitAddress[1].ToString().Trim(), splitZipRegion[0].ToString().Trim());
                    loc.cityId = new Guid(cityid);
                    loc.zipcode = splitZipRegion[1].ToString().Trim();
                }
                //End formatting address

                loc = objLocation.UpdateLocation(loc);
                seed.locationId = loc.id;
                seed = objSeed.UpdateSeed(seed);
                string plantedSeedId = seed.id.ToString();

                if (txtCategoryEdt != null)
                {
                    string catIds = string.Empty;
                    string[] splitCategories = txtCategoryEdt.Split(',');
                    for (int i = 0; i < splitCategories.Length; i++)
                    {
                        CategoryAction objCatg = new CategoryAction();
                        string idCatg = objCatg.GetCategoryIdByCategoryName(splitCategories[i].ToString());
                        if (!string.IsNullOrEmpty(idCatg))
                        {
                            if (string.IsNullOrEmpty(catIds))
                                catIds = idCatg;
                            else
                                catIds = catIds + "," + idCatg;
                        }
                    }
                    //bool isPlanted = false;
                    if (!string.IsNullOrEmpty(catIds))
                    {
                        string[] arrCatIds = catIds.Split(',');
                        objSeed.AddCategories(plantedSeedId, arrCatIds);
                    }
                }
                if (mediaFilesEdt != null)
                {
                    foreach (var file in mediaFilesEdt)
                    {
                        if (file.ContentLength > 0)
                        {
                            Bitmap sourceImage = new Bitmap(file.InputStream);
                            MediaManagement objMedia = new MediaManagement();
                            bool isMediaSaved = false;
                            int fileSize = file.ContentLength;
                            string fileOk = CheckFile(file.FileName, fileSize);
                            if (fileOk != "Invalid")
                            {
                                string strImgFileExtension = System.IO.Path.GetExtension(file.FileName);
                                DateTime datImg = DateTime.Now;
                                string ImgfileUploadtime = datImg.Day.ToString() + datImg.Month.ToString() + datImg.Year.ToString() + datImg.Hour.ToString() + datImg.Minute.ToString() + datImg.Second.ToString();
                                string filePath = Path.Combine(HttpContext.Server.MapPath("/UploadedMedia"), (plantedSeedId + "_" + ImgfileUploadtime + strImgFileExtension));
                                objMedia.title = plantedSeedId + "_" + ImgfileUploadtime;
                                objMedia.path = "../../UploadedMedia/" + (plantedSeedId + "_" + ImgfileUploadtime + strImgFileExtension);
                                objMedia.type = fileOk;
                                objMedia.seedId = plantedSeedId;
                                sourceImage.Save(filePath, FileExtensionToImageFormat(filePath));
                                objMedia.embedScript = "Image Script";
                                isMediaSaved = SaveMediaInformation(objMedia);
                            }
                            else
                                throw new Exception("Please check file type or file size, Max Size Allowed : (Image : 2 MB) & (Video : 4 MB)");
                        }
                    }
                }
                return Redirect("/Seed/SeedDetails/" + plantedSeedId);
            }
            catch (Exception ex)
            {
                SessionStore.SetSessionValue("PlantError", ex.Message.ToString());
                return RedirectToAction("PlantError", "Seed");
            }
            #endregion
        }
コード例 #4
0
 private bool SaveMediaInformation(MediaManagement objMedia)
 {
     #region
     bool isInfoSaved = false;
     Member memberData = (Member)SessionStore.GetSessionValue(SessionStore.Memberobject);
     objMedia.uploadedById = memberData.id.ToString();
     MediaAction objMediaAction = new MediaAction();
     objMediaAction.AddMedia(objMedia);
     isInfoSaved = true;
     return isInfoSaved;
     #endregion
 }
コード例 #5
0
        public ActionResult UploadVedioMedia(HttpPostedFileBase uploadFile, MediaManagement objMedia, string seedId)
        {
            #region
            Member memberData = (Member)SessionStore.GetSessionValue(SessionStore.Memberobject);
            try
            {
                if (uploadFile != null)
                {
                    if (uploadFile.ContentLength > 0)
                    {
                        bool isMediaSaved = false;
                        int fileSize = uploadFile.ContentLength;
                        string fileOk = CheckFile(uploadFile.FileName, fileSize);
                        string strFileExtension = System.IO.Path.GetExtension(uploadFile.FileName);

                        DateTime dat = DateTime.Now;
                        string fileUploadtime = dat.Day.ToString() + dat.Month.ToString() + dat.Year.ToString() + dat.Hour.ToString() + dat.Minute.ToString() + dat.Second.ToString();
                        string filePath = Path.Combine(HttpContext.Server.MapPath("/UploadedMedia"), (memberData.id.ToString() + "_" + fileUploadtime + strFileExtension));

                        objMedia.path = "../../UploadedMedia/" + (memberData.id.ToString() + "_" + fileUploadtime + strFileExtension);
                        objMedia.type = fileOk;
                        if (fileOk == SystemStatements.MEDIA_VIDEO)
                        {
                            uploadFile.SaveAs(filePath);
                            objMedia.embedScript = "Media Script";
                            isMediaSaved = SaveMediaInformation(objMedia);
                            if (isMediaSaved == true)
                            {
                                SendMediaUploadMail(seedId);
                                ViewData["MediaMsg"] = "<b>Media has been uploaded successfully.</b>";
                            }
                        }

                        if (fileOk == "Invalid")
                        {
                            ViewData["MediaMsg"] = "<span>Please check file type or file size, Max Size Allowed : 4 MB</span>";
                        }
                    }
                    else
                    {
                        ViewData["MediaMsg"] = "<span>Please check file type or file size.</span>";
                    }
                }
                else
                {
                    ViewData["MediaMsg"] = "<span>Please select a file.</span>";
                }
            }
            catch (Exception ex)
            {
                ViewData["MediaMsg"] = ex.Message.ToString();
            }
            SeedAction objSeed = new SeedAction();
            Seed seedData = objSeed.GetSeedBySeedId(seedId);
            ViewData["SeedTitle"] = seedData.title;
            ViewData["SeedValue"] = seedData.id;
            ViewData["SeedData"] = seedData;
            IList<Medium> MList = seedData.Media.Where(x => x.type.Equals(SystemStatements.MEDIA_VIDEO)).OrderByDescending(x => x.dateUploaded).ToList();
            ViewData["MList"] = MList;

            return View();
            #endregion
        }
コード例 #6
0
        public ActionResult UploadMedia(HttpPostedFileBase uploadFile, MediaManagement objMedia, string seedId)
        {
            #region
            Member memberData = (Member)SessionStore.GetSessionValue(SessionStore.Memberobject);
            try
            {
                if (uploadFile != null)
                {
                    if (uploadFile.ContentLength > 0)
                    {
                        bool isMediaSaved = false;
                        int fileSize = uploadFile.ContentLength;
                        string fileOk = CheckFile(uploadFile.FileName, fileSize);
                        string strImgFileExtension = System.IO.Path.GetExtension(uploadFile.FileName);
                        DateTime datImg = DateTime.Now;
                        string ImgfileUploadtime = datImg.Day.ToString() + datImg.Month.ToString() + datImg.Year.ToString() + datImg.Hour.ToString() + datImg.Minute.ToString() + datImg.Second.ToString();

                        string filePath = Path.Combine(HttpContext.Server.MapPath("/UploadedMedia"), (memberData.id.ToString() + "_" + ImgfileUploadtime + strImgFileExtension));

                        objMedia.path = "../../UploadedMedia/" + (memberData.id.ToString() + "_" + ImgfileUploadtime + strImgFileExtension);
                        objMedia.type = fileOk;

                        if (fileOk == SystemStatements.MEDIA_IMAGE)
                        {
                            int maxImageWidth = 600;
                            Bitmap sourceImage = new Bitmap(uploadFile.InputStream);

                            // Resize if source image width is greater than the max:
                            if (sourceImage.Width > maxImageWidth)
                            {
                                int newImageHeight = (int)(sourceImage.Height * ((float)maxImageWidth / (float)sourceImage.Width));
                                Bitmap resizedImage = new Bitmap(maxImageWidth, newImageHeight);
                                Graphics gr = Graphics.FromImage(resizedImage);
                                gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
                                gr.DrawImage(sourceImage, 0, 0, maxImageWidth, newImageHeight);
                                // Save the resized image:
                                resizedImage.Save(filePath, FileExtensionToImageFormat(filePath));
                                objMedia.embedScript = "Image Script";
                                isMediaSaved = SaveMediaInformation(objMedia);
                                if (isMediaSaved == true)
                                {
                                    SendMediaUploadMail(seedId);
                                    ViewData["MediaMsg"] = "<b>Image has been uploaded successfully.</b>";
                                }
                            }
                            else
                            {
                                // Save the source image (no resizing necessary):
                                sourceImage.Save(filePath, FileExtensionToImageFormat(filePath));
                                objMedia.embedScript = "Image Script";
                                isMediaSaved = SaveMediaInformation(objMedia);
                                if (isMediaSaved == true)
                                {
                                    SendMediaUploadMail(seedId);
                                    ViewData["MediaMsg"] = "<b>Image has been uploaded successfully.</b>";
                                }
                            }
                        }
                        if (fileOk == "Invalid")
                        {
                            ViewData["MediaMsg"] = "<span>Please check file type or file size, Max Size Allowed : 4 MB</span>";
                        }
                    }
                    else
                    {
                        ViewData["MediaMsg"] = "<span>Please check file type or file size.</span>";
                    }
                }
                else
                {
                    ViewData["MediaMsg"] = "<span>Please select a file.</span>";
                }
            }
            catch (Exception ex)
            {
                ViewData["MediaMsg"] = ex.Message.ToString();
            }
            SeedAction objSeed = new SeedAction();
            Seed seedData = objSeed.GetSeedBySeedId(seedId);
            ViewData["SeedTitle"] = seedData.title;
            ViewData["SeedValue"] = seedData.id;
            ViewData["SeedData"] = seedData;
            IList<Medium> MList = seedData.Media.Where(x => x.type.Equals(SystemStatements.MEDIA_IMAGE)).OrderByDescending(x => x.dateUploaded).ToList();
            ViewData["MList"] = MList;

            return View();
            #endregion
        }
コード例 #7
0
        public ActionResult ShareIdea1(string returnAction, string txtSeedTitle, string txtDesc, string seedCoordinates, string seedLocation, string txtCategory, IEnumerable<HttpPostedFileBase> mediaFiles)
        {
            #region codeRegion
            try
            {
                SeedAction objSeed = new SeedAction();
                LocationAction objLocation = new LocationAction();

                //Format address and create add seed model
                string[] splitAddress = seedLocation.Split(',');
                AddSeed seedData = new AddSeed();
                seedData.SeedName = txtSeedTitle;
                seedData.Description = txtDesc;
                seedData.LongLat = seedCoordinates;
                string seedCountry = string.Empty;
                if (splitAddress.Length > 4)
                {
                    seedData.StreetAddress = splitAddress[0].ToString() + ", " + splitAddress[1].ToString();
                    seedData.City = splitAddress[2].ToString().Trim();
                    string[] splitZipRegion = splitAddress[3].ToString().Trim().Split(' ');
                    seedData.ZipCode = splitZipRegion[1].ToString().Trim();
                    seedData.StateCode = splitZipRegion[0].ToString().Trim();
                    seedCountry = splitAddress[4].ToString();
                }
                else
                {
                    seedData.StreetAddress = splitAddress[0].ToString();
                    seedData.City = splitAddress[1].ToString().Trim();
                    string[] splitZipRegion = splitAddress[2].ToString().Trim().Split(' ');
                    seedData.ZipCode = splitZipRegion[1].ToString().Trim();
                    seedData.StateCode = splitZipRegion[0].ToString().Trim();
                    seedCountry = splitAddress[3].ToString();
                }
                //End formatting address

                if (seedCountry.Trim().Equals("USA") || seedCountry.Trim().Equals("US"))
                    seedCountry = seedCountry.Trim();
                else
                    throw new Exception("Seeds can not be planted outside region of United States");

                string plantedSeedId = AddSeedData(seedData);

                if (txtCategory != null)
                {
                    string catIds = string.Empty;
                    string[] splitCategories = txtCategory.Split(',');
                    for (int i = 0; i < splitCategories.Length; i++)
                    {
                        CategoryAction objCatg = new CategoryAction();
                        string idCatg = objCatg.GetCategoryIdByCategoryName(splitCategories[i].ToString());
                        if (!string.IsNullOrEmpty(idCatg))
                        {
                            if (string.IsNullOrEmpty(catIds))
                                catIds = idCatg;
                            else
                                catIds = catIds + "," + idCatg;
                        }
                    }
                    //bool isPlanted = false;
                    if (!string.IsNullOrEmpty(catIds))
                    {
                        string[] arrCatIds = catIds.Split(',');
                        objSeed.AddCategories(plantedSeedId, arrCatIds);
                    }
                }
                if (mediaFiles != null)
                {
                    foreach (var file in mediaFiles)
                    {
                        if (file.ContentLength > 0)
                        {
                            Bitmap sourceImage = new Bitmap(file.InputStream);
                            MediaManagement objMedia = new MediaManagement();
                            bool isMediaSaved = false;
                            int fileSize = file.ContentLength;
                            string fileOk = CheckFile(file.FileName, fileSize);
                            if (fileOk != "Invalid")
                            {
                                string strImgFileExtension = System.IO.Path.GetExtension(file.FileName);
                                DateTime datImg = DateTime.Now;
                                string ImgfileUploadtime = datImg.Day.ToString() + datImg.Month.ToString() + datImg.Year.ToString() + datImg.Hour.ToString() + datImg.Minute.ToString() + datImg.Second.ToString();
                                string filePath = Path.Combine(HttpContext.Server.MapPath("/UploadedMedia"), (plantedSeedId.ToString() + "_" + ImgfileUploadtime + strImgFileExtension));
                                objMedia.title = plantedSeedId.ToString() + "_" + ImgfileUploadtime;
                                objMedia.path = "../../UploadedMedia/" + (plantedSeedId.ToString() + "_" + ImgfileUploadtime + strImgFileExtension);
                                objMedia.type = fileOk;
                                objMedia.seedId = plantedSeedId;
                                sourceImage.Save(filePath, FileExtensionToImageFormat(filePath));
                                objMedia.embedScript = "Image Script";
                                isMediaSaved = SaveMediaInformation(objMedia);
                            }
                            else
                                throw new Exception("Please check file type or file size, Max Size Allowed : (Image : 2 MB) & (Video : 4 MB)");
                        }
                    }
                }
                Seed seed = GetSeedInformation(plantedSeedId);
                // Creating array list for token
                ArrayList arrTokens = new ArrayList();
                arrTokens.Add(seed.Member.firstName + " " + seed.Member.lastName);
                arrTokens.Add(seed.title);
                arrTokens.Add("http://" + Request.ServerVariables["SERVER_NAME"] + "/Seed/SeedDetails/" + seed.id);
                arrTokens.Add("http://" + Request.ServerVariables["SERVER_NAME"] + "/Member/Profile");

                // Filling mail object
                SendMail objSendMail = new SendMail();

                Regex rgxEmail = new Regex("\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
                if (rgxEmail.IsMatch(seed.Member.username))
                    objSendMail.ToEmailId = seed.Member.username;
                else
                    objSendMail.ToEmailId = seed.Member.Email;
                objSendMail.Subject = "email.seedPlanted.subject.content";
                objSendMail.MsgBody = "email.seedPlanted.body.content";
                objSendMail.ChangesInMessage = arrTokens;

                objSendMail.SendEmail(objSendMail);

                return Redirect("/Seed/SeedDetails/" + seed.id);
            }
            catch (Exception ex)
            {
                SessionStore.SetSessionValue("PlantError", "Error occurred while planting seed#" + ex.Message.ToString());
                //ViewData["PlantErrMsg"] = ex.Message.ToString();
                return RedirectToAction("PlantError", "Seed");
            }
            #endregion
        }