コード例 #1
0
        public UserSession VerifySession(string sessionId)
        {
            if (string.IsNullOrEmpty(sessionId))
            {
                return(null);
            }
            IUserSessionRepository userSessionRepository = RepositoryClassFactory.GetInstance().GetUserSessionRepository();
            UserSession            userSession           = userSessionRepository.FindByID(sessionId);

            if (userSession == null)
            {
                return(null);
            }

            if (!userSession.UpdatedDate.HasValue)
            {
                return(null);
            }

            TimeSpan time = DateTime.Now - userSession.UpdatedDate.Value;

            if (time.Milliseconds > TIME_OUT_MINUTES * 60 * 1000)
            {
                userSessionRepository.Delete(sessionId);
            }
            else
            {
                userSessionRepository.Update(userSession);
                return(userSession);
            }
            return(null);
        }
コード例 #2
0
        public JsonResult UploadFiles(HttpPostedFileBase file)
        {
            var sessionId = this.Session["SessionID"].ToString();
            IUserSessionRepository userSessionRepository = RepositoryClassFactory.GetInstance().GetUserSessionRepository();
            UserSession            userSession           = userSessionRepository.FindByID(sessionId);

            if (userSession == null)
            {
                return(Json(new { errorCode = (int)ErrorCode.Redirect, message = Resources.AdminResource.msg_sessionInvalid }, JsonRequestBehavior.AllowGet));
            }

            InsertResponse response = new InsertResponse();

            string url       = string.Empty;
            string msg       = string.Empty;
            int    errorcode = 0;

            if (file != null)
            {
                try
                {
                    //Create folder
                    try
                    {
                        if (!System.IO.File.Exists(Server.MapPath("~/Content/upload/files/")))
                        {
                            Directory.CreateDirectory(Server.MapPath("~/Content/upload/files/"));
                        }
                    }
                    catch (Exception) {}

                    string filename = file.FileName.Substring(0, file.FileName.LastIndexOf("."));
                    filename = string.Format("{0}-{1}", filename, UrlSlugger.Get8Digits()).Replace(" ", "_");
                    string extension = file.FileName.Substring(file.FileName.LastIndexOf("."));
                    file.SaveAs(Server.MapPath("~/Content/upload/files/" + filename + extension));
                    url = string.Format("{0}://{1}:{2}/{3}", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, "Content/upload/files/" + filename + extension);

                    UploadModel upload = new UploadModel();
                    upload.UploadID    = Guid.NewGuid().ToString();
                    upload.CreatedBy   = userSession.UserID;
                    upload.CreatedDate = DateTime.Now;
                    upload.Title       = filename;
                    upload.UploadURL   = url;
                    upload.FilePath    = "/Content/upload/files/" + filename + extension;

                    response = _uploadService.CreateUpload(upload);
                }
                catch (Exception ex)
                {
                    msg       = ex.Message;
                    errorcode = (int)ErrorCode.Error;
                }
            }

            return(Json(new { errorcode = errorcode, message = msg, url = url }, JsonRequestBehavior.AllowGet));
        }
コード例 #3
0
        public User GetUserBySessionID(string sessionID)
        {
            IUserRepository        userRepository        = RepositoryClassFactory.GetInstance().GetUserRepository();
            IUserSessionRepository userSessionRepository = RepositoryClassFactory.GetInstance().GetUserSessionRepository();
            UserSession            userSession           = userSessionRepository.FindByID(sessionID);

            if (userSession != null)
            {
                return(userRepository.FindByID(userSession.UserID));
            }
            return(null);
        }
コード例 #4
0
        public ActionResult AdminList()
        {
            var sessionId = this.Session["SessionID"].ToString();
            IUserSessionRepository userSessionRepository = RepositoryClassFactory.GetInstance().GetUserSessionRepository();
            UserSession            userSession           = userSessionRepository.FindByID(sessionId);

            FindAllItemReponse <AdminModel> response = _adminService.GetAdminsExceptMe(userSession.UserID);

            if (response.Items == null)
            {
                response.Items = new List <AdminModel>();
            }
            return(View(response.Items));
        }
コード例 #5
0
        public JsonResult SaveUpdateNews(NewsModel news, HttpPostedFileBase imageFile)
        {
            var sessionId = this.Session["SessionID"].ToString();
            IUserSessionRepository userSessionRepository = RepositoryClassFactory.GetInstance().GetUserSessionRepository();
            UserSession            userSession           = userSessionRepository.FindByID(sessionId);

            if (userSession == null)
            {
                return(Json(new { errorCode = (int)ErrorCode.Redirect, message = Resources.AdminResource.msg_sessionInvalid }, JsonRequestBehavior.AllowGet));
            }

            //news.ActionURL = string.Format("{0}-{1}", UrlSlugger.ToUrlSlug(news.Title), UrlSlugger.Get8Digits());
            news.UpdatedBy = userSession.UserID;
            BaseResponse response = _newsService.UpdateNews(news);

            if (response.ErrorCode == (int)ErrorCode.None)
            {
                //Image
                if (imageFile != null)
                {
                    //Create folder
                    try
                    {
                        if (!System.IO.File.Exists(Server.MapPath("~/Content/upload/images/news/")))
                        {
                            Directory.CreateDirectory(Server.MapPath("~/Content/upload/images/news/"));
                        }
                    }
                    catch (Exception) { }

                    if (!string.IsNullOrEmpty(news.ThumbnailURL))
                    {
                        if (System.IO.File.Exists(Server.MapPath(news.ThumbnailURL)))
                        {
                            System.IO.File.Delete(Server.MapPath(news.ThumbnailURL));
                        }
                    }

                    string extension = imageFile.FileName.Substring(imageFile.FileName.LastIndexOf("."));
                    string filename  = imageFile.FileName.Substring(0, imageFile.FileName.LastIndexOf(".")).Replace(" ", "-");
                    filename = string.Format("{0}-{1}", filename, UrlSlugger.Get8Digits());
                    imageFile.SaveAs(Server.MapPath("~/Content/upload/images/news/" + filename + extension));

                    news.ThumbnailURL = "/Content/upload/images/news/" + filename + extension;
                    _newsService.UpdateNews(news);
                }
            }
            return(Json(new { errorCode = response.ErrorCode, message = response.Message }, JsonRequestBehavior.AllowGet));
        }
コード例 #6
0
        public JsonResult SaveSlider(SliderModel slider, HttpPostedFileBase imageFile)
        {
            var sessionId = this.Session["SessionID"].ToString();
            IUserSessionRepository userSessionRepository = RepositoryClassFactory.GetInstance().GetUserSessionRepository();
            UserSession            userSession           = userSessionRepository.FindByID(sessionId);

            if (userSession == null)
            {
                return(Json(new { errorCode = (int)ErrorCode.Redirect, message = Resources.AdminResource.msg_sessionInvalid }, JsonRequestBehavior.AllowGet));
            }
            InsertResponse response = new InsertResponse();

            slider.Title = slider.Title.Length > 200 ? slider.Title.Substring(0, 100) + "..." : slider.Title;

            slider.SliderID = Guid.NewGuid().ToString();
            //slider.URL = string.Format("{0}-{1}", UrlSlugger.ToUrlSlug(slider.Title), UrlSlugger.Get8Digits());
            slider.CreatedDate = DateTime.Now;
            slider.CreatedBy   = userSession != null ? userSession.UserID : string.Empty;
            slider.ImageURL    = "";
            response           = _slider.CreateSlider(slider);
            if (response.ErrorCode == (int)ErrorCode.None)
            {
                //Image
                if (imageFile != null)
                {
                    //Create folder
                    try
                    {
                        if (!System.IO.File.Exists(Server.MapPath("~/Content/upload/images/slider/")))
                        {
                            Directory.CreateDirectory(Server.MapPath("~/Content/upload/images/slider/"));
                        }
                    }
                    catch (Exception) { }

                    string extension = imageFile.FileName.Substring(imageFile.FileName.LastIndexOf("."));
                    string filename  = imageFile.FileName.Substring(0, imageFile.FileName.LastIndexOf(".")).Replace(" ", "-");
                    filename = string.Format("{0}-{1}", filename, UrlSlugger.Get8Digits());
                    imageFile.SaveAs(Server.MapPath("~/Content/upload/images/slider/" + filename + extension));

                    slider.ImageURL = "/Content/upload/images/slider/" + filename + extension;
                    _slider.UpdateSlider(slider);
                }
            }
            return(Json(new { errorCode = response.ErrorCode, message = response.Message }, JsonRequestBehavior.AllowGet));
        }
コード例 #7
0
        public ActionResult Index()
        {
            var sessionId = this.Session["SessionID"].ToString();
            IUserSessionRepository userSessionRepository = RepositoryClassFactory.GetInstance().GetUserSessionRepository();
            UserSession            userSession           = userSessionRepository.FindByID(sessionId);

            string currentLanguage = Session["AdminCulture"] != null ? Session["AdminCulture"].ToString() : "EN";

            if (Session["AdminCulture"] == null)
            {
                Session["AdminCulture"] = currentLanguage;
            }

            FindAllItemReponse <MenuModel> menuReponse = _menuCategoryService.FindAllMenus(currentLanguage);

            return(View(menuReponse.Items));
        }
コード例 #8
0
        public JsonResult SavePresentation(PresentationModel presentation, HttpPostedFileBase imageFile, HttpPostedFileBase file)
        {
            var sessionId = this.Session["SessionID"].ToString();
            IUserSessionRepository userSessionRepository = RepositoryClassFactory.GetInstance().GetUserSessionRepository();
            UserSession            userSession           = userSessionRepository.FindByID(sessionId);

            if (userSession == null)
            {
                return(Json(new { errorCode = (int)ErrorCode.Redirect, message = Resources.AdminResource.msg_sessionInvalid }, JsonRequestBehavior.AllowGet));
            }

            InsertResponse response = new InsertResponse();

            presentation.Title = presentation.Title.Length > 200 ? presentation.Title.Substring(0, 100) + "..." : presentation.Title;
            if (!string.IsNullOrEmpty(presentation.ShortContent))
            {
                presentation.ShortContent = presentation.ShortContent.Length > 300 ? presentation.ShortContent.Substring(0, 296) + "..." : presentation.ShortContent;
            }
            else
            {
                presentation.ShortContent = null;
            }
            presentation.ActionURL      = string.Format("{0}-{1}", UrlSlugger.ToUrlSlug(presentation.Title), UrlSlugger.Get8Digits());
            presentation.CreatedDate    = DateTime.Now;
            presentation.PresentationID = Guid.NewGuid().ToString();
            presentation.CreatedBy      = userSession != null ? userSession.UserID : string.Empty;

            response = _presentationService.CreatePresentation(presentation);
            if (response.ErrorCode == (int)ErrorCode.None)
            {
                //Image
                if (imageFile != null)
                {
                    //Create Folder
                    try
                    {
                        if (!System.IO.File.Exists(Server.MapPath("~/Content/upload/images/Presentation/")))
                        {
                            Directory.CreateDirectory(Server.MapPath("~/Content/upload/images/Presentation/"));
                        }
                    }
                    catch (Exception) { }
                    string extension = imageFile.FileName.Substring(imageFile.FileName.LastIndexOf("."));
                    string filename  = imageFile.FileName.Substring(0, imageFile.FileName.LastIndexOf(".")).Replace(" ", "-");
                    filename = string.Format("{0}-{1}", filename, UrlSlugger.Get8Digits());
                    imageFile.SaveAs(Server.MapPath("~/Content/upload/images/Presentation/" + filename + extension));
                    presentation.ImageURL = "/Content/upload/images/Presentation/" + filename + extension;
                    _presentationService.UpdatePresentation(presentation);
                }
                if (file != null)
                {
                    //Create Folder
                    try
                    {
                        if (!System.IO.File.Exists(Server.MapPath("~/Content/upload/documents/Presentation/")))
                        {
                            Directory.CreateDirectory(Server.MapPath("~/Content/upload/documents/Presentation/"));
                        }
                    }
                    catch (Exception) { }
                    string extension = file.FileName.Substring(file.FileName.LastIndexOf("."));
                    string filename  = file.FileName.Substring(0, file.FileName.LastIndexOf(".")).Replace(" ", "-");
                    filename = string.Format("{0}-{1}", filename, UrlSlugger.Get8Digits());
                    file.SaveAs(Server.MapPath("~/Content/upload/documents/Presentation/" + filename + extension));
                    presentation.AttachmentURL = "/Content/upload/documents/Presentation/" + filename + extension;
                    _presentationService.UpdatePresentation(presentation);
                }
            }
            return(Json(new { errorCode = response.ErrorCode, message = response.Message }, JsonRequestBehavior.AllowGet));
        }