コード例 #1
0
        public ActionResult SaveHoroscopeImage(HttpPostedFileBase file, string ProfileID)
        {
            Mugurtham.Core.Login.LoggedInUser objLoggedIn = (Mugurtham.Core.Login.LoggedInUser)Session["LoggedInUser"];
            if (file != null && file.ContentLength > 0)
            {
                try
                {
                    string strProfileHoroFolderPath = Path.Combine(Server.MapPath("~/Areas/Profile/Images/ProfilePhoto/" + objLoggedIn.CommunityName + "/" + ProfileID + "/Horoscope"));

                    if (!Directory.Exists(strProfileHoroFolderPath))
                    {
                        Directory.CreateDirectory(strProfileHoroFolderPath);
                    }

                    System.IO.DirectoryInfo objDirectoryInfo = new DirectoryInfo(strProfileHoroFolderPath);

                    foreach (FileInfo objFile in objDirectoryInfo.GetFiles())
                    {
                        objFile.Delete();
                    }
                    foreach (DirectoryInfo objDir in objDirectoryInfo.GetDirectories())
                    {
                        objDir.Delete(true);
                    }
                    string path = Path.Combine(Server.MapPath("~/Areas/Profile/Images/ProfilePhoto/" + objLoggedIn.CommunityName + "/" + ProfileID + "/Horoscope/" + ProfileID + Path.GetExtension(Path.GetFileName(file.FileName))));
                    string strProfileHoroPath = "/Areas/Profile/Images/ProfilePhoto/" + objLoggedIn.CommunityName + "/" + ProfileID + "/Horoscope/" + ProfileID + Path.GetExtension(Path.GetFileName(file.FileName));
                    if (
                        Path.GetExtension(Path.GetFileName(file.FileName)).ToString().ToLower() == ".jpg".ToString().ToLower() ||
                        Path.GetExtension(Path.GetFileName(file.FileName)).ToString().ToLower() == ".jpeg".ToString().ToLower() ||
                        Path.GetExtension(Path.GetFileName(file.FileName)).ToString().ToLower() == ".gif".ToString().ToLower() ||
                        Path.GetExtension(Path.GetFileName(file.FileName)).ToString().ToLower() == ".png".ToString().ToLower()
                        )
                    {
                        file.SaveAs(path);
                        addTextWatermark(path);
                        Mugurtham.Core.Profile.Horoscope.HoroscopeCore objHoroscopeCore = new Core.Profile.Horoscope.HoroscopeCore(ref objLoggedIn);
                        using (objHoroscopeCore as IDisposable)
                        {
                            Mugurtham.Core.Profile.Horoscope.HoroscopeCoreEntity objHoroscopeCoreEntity = new Core.Profile.Horoscope.HoroscopeCoreEntity();
                            using (objHoroscopeCoreEntity as IDisposable)
                            {
                                objHoroscopeCoreEntity      = objHoroscopeCore.GetByProfileID(ProfileID, objLoggedIn.LoginID);
                                objHoroscopeCoreEntity.Path = strProfileHoroPath;
                                if (!string.IsNullOrEmpty(strProfileHoroPath))
                                {
                                    objHoroscopeCore.updateHoroscope(ref objHoroscopeCoreEntity);
                                }
                            }
                            objHoroscopeCoreEntity = null;
                        }
                        objHoroscopeCore = null;
                    }
                }
                catch (Exception ex)
                {
                    ViewBag.Message = "ERROR:" + ex.Message.ToString();
                }
            }
            else
            {
                ViewBag.Message = "You have not specified a file.";
            }
            return(Redirect("/Matrimony#/Horoscope"));
        }
コード例 #2
0
        public ActionResult SaveHoroscopeImage(HttpPostedFileBase file, string ProfileID)
        {
            Mugurtham.Core.Login.LoggedInUser objLoggedIn = (Mugurtham.Core.Login.LoggedInUser)Session["LoggedInUser"];
            if (file != null && file.ContentLength > 0)
                try
                {
                    string strProfileHoroFolderPath = Path.Combine(Server.MapPath("~/Areas/Profile/Images/ProfilePhoto/" + ProfileID + "/Horoscope"));

                    if (!Directory.Exists(strProfileHoroFolderPath))
                        Directory.CreateDirectory(strProfileHoroFolderPath);

                    System.IO.DirectoryInfo objDirectoryInfo = new DirectoryInfo(strProfileHoroFolderPath);

                    foreach (FileInfo objFile in objDirectoryInfo.GetFiles())
                    {
                        objFile.Delete();
                    }
                    foreach (DirectoryInfo objDir in objDirectoryInfo.GetDirectories())
                    {
                        objDir.Delete(true);
                    }
                    string path = Path.Combine(Server.MapPath("~/Areas/Profile/Images/ProfilePhoto/" + ProfileID + "/Horoscope/" + ProfileID + Path.GetExtension(Path.GetFileName(file.FileName))));
                    string strProfileHoroPath = "/Areas/Profile/Images/ProfilePhoto/" + ProfileID + "/Horoscope/" + ProfileID + Path.GetExtension(Path.GetFileName(file.FileName));
                    if (
                    Path.GetExtension(Path.GetFileName(file.FileName)).ToString().ToLower() == ".jpg".ToString().ToLower() ||
                    Path.GetExtension(Path.GetFileName(file.FileName)).ToString().ToLower() == ".jpeg".ToString().ToLower() ||
                    Path.GetExtension(Path.GetFileName(file.FileName)).ToString().ToLower() == ".gif".ToString().ToLower() ||
                    Path.GetExtension(Path.GetFileName(file.FileName)).ToString().ToLower() == ".png".ToString().ToLower()
                    )
                    {
                        file.SaveAs(path);
                        Mugurtham.Core.Profile.Horoscope.HoroscopeCore objHoroscopeCore = new Core.Profile.Horoscope.HoroscopeCore();
                        using (objHoroscopeCore as IDisposable)
                        {
                            Mugurtham.Core.Profile.Horoscope.HoroscopeCoreEntity objHoroscopeCoreEntity = new Core.Profile.Horoscope.HoroscopeCoreEntity();
                            using (objHoroscopeCoreEntity as IDisposable)
                            {
                                objHoroscopeCoreEntity = objHoroscopeCore.GetByProfileID(ProfileID);
                                objHoroscopeCoreEntity.Path = strProfileHoroPath;
                                if (!string.IsNullOrEmpty(strProfileHoroPath))
                                    objHoroscopeCore.updateHoroscope(ref objHoroscopeCoreEntity);
                            }
                            objHoroscopeCoreEntity = null;
                        }
                        objHoroscopeCore = null;
                    }
                }
                catch (Exception ex)
                {
                    ViewBag.Message = "ERROR:" + ex.Message.ToString();
                }
            else
            {
                ViewBag.Message = "You have not specified a file.";
            }
            return Redirect("/Mugurtham#/Horoscope");
        }