예제 #1
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
        }