public JsonResult SaveUpdateConference(ConferenceDeclarationModel conference, 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));
            }
            //conference.ActionURL = string.Format("{0}-{1}", UrlSlugger.ToUrlSlug(conference.Title), UrlSlugger.Get8Digits());
            conference.UpdatedBy   = userSession.UserID;
            conference.UpdatedDate = DateTime.Now;
            BaseResponse response = _conferenceService.UpdateConference(conference);

            if (response.ErrorCode == (int)ErrorCode.None)
            {
                //Image
                if (imageFile != null)
                {
                    //Create Folder
                    try
                    {
                        if (!System.IO.File.Exists(Server.MapPath("~/Content/upload/images/Conference/")))
                        {
                            Directory.CreateDirectory(Server.MapPath("~/Content/upload/images/Conference/"));
                        }
                    }
                    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/Conference/" + filename + extension));
                    conference.ImageURL = "/Content/upload/images/Conference/" + filename + extension;
                    _conferenceService.UpdateConference(conference);
                }
                if (file != null)
                {
                    //Create Folder
                    try
                    {
                        if (!System.IO.File.Exists(Server.MapPath("~/Content/upload/documents/Conference/")))
                        {
                            Directory.CreateDirectory(Server.MapPath("~/Content/upload/documents/Conference/"));
                        }
                    }
                    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/Conference/" + filename + extension));
                    conference.AttachmentURL = "/Content/upload/documents/Conference/" + filename + extension;
                    _conferenceService.UpdateConference(conference);
                }
            }
            return(Json(new { errorCode = response.ErrorCode, message = response.Message }, JsonRequestBehavior.AllowGet));
        }
        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));
        }
        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));
        }
Beispiel #4
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));
        }
        public JsonResult SaveUserInfomation(RegistrationModel registration)
        {
            if (this.Session["User-SessionID"] == null)
            {
                return(Json(new { ErrorCode = (int)ErrorCode.Redirect }, JsonRequestBehavior.AllowGet));
            }
            BaseResponse response = new BaseResponse();
            FindItemReponse <UserModel> userResponse = _userService.FindUserByID(registration.UserID);

            if (userResponse.Item != null)
            {
                var user = userResponse.Item;
                user.Title                      = registration.Title != "Empty" ? registration.Title : user.Title;
                user.Email                      = registration.Email != "Empty" ? registration.Email : user.Email;
                user.FullName                   = registration.FullName != "Empty" ? registration.FullName : user.FullName;
                user.Sex                        = registration.Sex != "Empty" ? registration.Sex : user.Sex;
                user.MealPreference             = registration.MealPreference != "Empty" ? registration.MealPreference : user.MealPreference;
                user.DisabilitySpecialTreatment = registration.DisabilityOrTreatment != "Empty" ? registration.DisabilityOrTreatment : user.DisabilitySpecialTreatment;
                user.OtherEmail                 = registration.OtherEmail != "Empty" ? registration.OtherEmail : user.OtherEmail;
                user.PhoneNumber                = registration.Phone != "Empty" ? registration.Phone : user.PhoneNumber;
                user.Address                    = registration.Address != "Empty" ? registration.Address : user.Address;
                user.City                       = registration.City != "Empty" ? registration.City : user.City;
                user.Country                    = registration.Country != "Empty" ? registration.Country : user.Country;
                user.WorkAddress                = registration.WorkAddress != "Empty" ? registration.WorkAddress : user.WorkAddress;
                user.Organization               = registration.Organization != "Empty" ? registration.Organization : user.Organization;
                user.DateOfBirth                = registration.DateOfBirth.HasValue ? registration.DateOfBirth : user.DateOfBirth;
                //Don't update password
                user.Password = null;

                //Updare user
                response = _userService.UpdateUser(user);
            }
            else
            {
                response.ErrorCode = (int)ErrorCode.Error;
                response.Message   = Resources.Resource.msg_commonError;
            }
            FindItemReponse <MailingAddressModel> mailingResponse = _mailingService.FindMailingAddressByID(registration.MailingAddressID);

            if (mailingResponse.Item != null)
            {
                var mailing = mailingResponse.Item;
                mailing.ParticipantType      = registration.ParticipantType != "Empty" ? registration.ParticipantType : mailing.ParticipantType;
                mailing.ParticipateYouth     = registration.YouthConference;
                mailing.NeedVisaSupport      = registration.NeedVisaSupport;
                mailing.OriginalNationality  = registration.OriginalNationality != "Empty" ? registration.OriginalNationality : mailing.OriginalNationality;
                mailing.CurrentNationality   = registration.CurrentNationality != "Empty" ? registration.CurrentNationality : mailing.CurrentNationality;
                mailing.Occupation           = registration.Occupation != "Empty" ? registration.Occupation : mailing.Occupation;
                mailing.DetailOfEmbassy      = registration.DetailOfEmbassy != "Empty" ? registration.DetailOfEmbassy : mailing.DetailOfEmbassy;
                mailing.PassportNumber       = registration.PassportNumber != "Empty" ? registration.PassportNumber : mailing.PassportNumber;
                mailing.DateOfPassportIssue  = registration.DateOfPassportIssue.HasValue ? registration.DateOfPassportIssue.Value : mailing.DateOfPassportIssue;
                mailing.DateOfPassportExpiry = registration.DateOfPassportExpiry.HasValue ? registration.DateOfPassportExpiry.Value : mailing.DateOfPassportExpiry;

                //Update mailing
                response = _mailingService.UpdateMailingAddress(mailing);
            }
            else
            {
                var mailing = new MailingAddressModel
                {
                    MailingAddressID     = Guid.NewGuid().ToString(),
                    ActivationCode       = UrlSlugger.Get8Digits(),
                    CreatedDate          = DateTime.Now,
                    ParticipantType      = registration.ParticipantType,
                    ParticipateYouth     = registration.YouthConference,
                    NeedVisaSupport      = registration.NeedVisaSupport,
                    OriginalNationality  = registration.OriginalNationality,
                    CurrentNationality   = registration.CurrentNationality,
                    Occupation           = registration.Occupation,
                    DetailOfEmbassy      = registration.DetailOfEmbassy,
                    PassportNumber       = registration.PassportNumber,
                    DateOfPassportIssue  = registration.DateOfPassportIssue,
                    DateOfPassportExpiry = registration.DateOfPassportExpiry,
                    PassportPhoto1       = registration.PassportPhoto1,
                    PassportPhoto2       = registration.PassportPhoto2,
                    PassportPhoto3       = registration.PassportPhoto3,
                    RegistrationNumber   = UrlSlugger.Get8Digits(),
                    TypeOfPassport       = registration.TypeOfPassport,
                    UserID = userResponse.Item.UserID
                };
                var insertResponse = _mailingService.CreateMailingAddress(mailing);
                response.ErrorCode = insertResponse.ErrorCode;
                response.Message   = insertResponse.ErrorCode != (int)ErrorCode.None ? "Please input required fields" : "Update succeeded";
            }
            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Beispiel #6
0
        public JsonResult SaveVideo(VideoModel video)
        {
            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();

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

            return(Json(new { errorCode = response.ErrorCode, message = response.Message }, JsonRequestBehavior.AllowGet));
        }
Beispiel #7
0
        public JsonResult SaveAlbum(AlbumModel album)
        {
            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();

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

            response = _albumService.CreateAlbum(album);

            return(Json(new { errorCode = response.ErrorCode, message = response.Message }, JsonRequestBehavior.AllowGet));
        }
Beispiel #8
0
        public JsonResult SaveArticle(ArticleModel article, string menuTitle, 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 menuID = null;
            string url    = string.Empty;

            if (!string.IsNullOrEmpty(menuTitle))
            {
                FindItemReponse <MenuModel> findParentMenu = _menuCategoryService.FindByTitle(menuTitle);
                if (findParentMenu.Item == null)
                {
                    return(Json(new { errorCode = (int)ErrorCode.Error, message = string.Format(Resources.AdminResource.msg_menuCategoryNotFound, menuTitle) }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    menuID = findParentMenu.Item.MenuID;
                }
            }

            //Create article
            article.Title = article.Title.Length > 200 ? article.Title.Substring(0, 100) + "..." : article.Title;
            if (article.ShortContent != null)
            {
                article.ShortContent = article.ShortContent.Length > 300 ? article.ShortContent.Substring(0, 296) + "..." : article.ShortContent;
            }
            article.ArticleID   = Guid.NewGuid().ToString();
            article.ActionURL   = string.Format("{0}-{1}", UrlSlugger.ToUrlSlug(article.Title), UrlSlugger.Get8Digits());
            article.CreatedDate = DateTime.Now;
            article.CreatedBy   = userSession.UserID;
            article.MenuID      = menuID;

            if (string.IsNullOrEmpty(menuID))
            {
                url = string.Format("{0}://{1}:{2}/Home/ArticleView/{3}", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, article.ActionURL);
            }

            response = _articleService.CreateArticle(article);

            if (response.ErrorCode == (int)ErrorCode.None)
            {
                //Image
                if (file != null)
                {
                    //Create folder
                    try
                    {
                        if (!System.IO.File.Exists(Server.MapPath("~/Content/upload/images/article/")))
                        {
                            Directory.CreateDirectory(Server.MapPath("~/Content/upload/images/article/"));
                        }
                    }
                    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/images/article/" + filename + extension));

                    article.ImageURL = "/Content/upload/images/article/" + filename + extension;
                    _articleService.UpdateArticle(article);
                }
            }

            return(Json(new { errorCode = response.ErrorCode, message = response.Message, url = url }, JsonRequestBehavior.AllowGet));
        }
        public JsonResult SaveImportantDeadline(ImportantDeadlineModel importantDeadline)
        {
            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();

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

            return(Json(new { errorCode = response.ErrorCode, message = response.Message }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Upload(int?chunk, string name, string AlbumID)
        {
            FindItemReponse <AlbumModel> albumResponse = _albumService.FindAlbumByID(AlbumID);

            if (albumResponse.Item == null)
            {
                return(Json(new { success = false }, JsonRequestBehavior.AllowGet));
            }

            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));
            }

            chunk = chunk ?? 0;

            InsertResponse response = new InsertResponse();

            PhotoModel photo = new PhotoModel();

            if (chunk == 0)
            {
                photo.Title       = name.Length > 200 ? name.Substring(0, 100) + "..." : name;
                photo.ActionURL   = string.Format("{0}-{1}", UrlSlugger.ToUrlSlug(photo.Title), UrlSlugger.Get8Digits());
                photo.CreatedDate = DateTime.Now;
                photo.PhotoID     = Guid.NewGuid().ToString();
                photo.ImageURL    = "";
                photo.CreatedBy   = userSession != null ? userSession.UserID : string.Empty;
                photo.AlbumID     = AlbumID;

                response = _photoService.CreatePhoto(photo);
            }

            if (response.ErrorCode == (int)ErrorCode.None)
            {
                var fileUpload = Request.Files[0];

                //Image
                if (fileUpload != null)
                {
                    //Create Folder
                    try
                    {
                        if (!System.IO.File.Exists(Server.MapPath("~/Content/upload/images/Photo/")))
                        {
                            Directory.CreateDirectory(Server.MapPath("~/Content/upload/images/Photo/"));
                        }
                    }
                    catch (Exception) { }

                    var    uploadPath = Server.MapPath("~/Content/upload/images/Photo/");
                    string extension  = name.Substring(name.LastIndexOf("."));
                    string filename   = name.Substring(0, name.LastIndexOf(".")).Replace(" ", "-");
                    filename = string.Format("{0}-{1}", filename, UrlSlugger.Get8Digits());

                    using (var fs = new FileStream(Path.Combine(uploadPath, string.Format("{0}{1}", filename, extension)), chunk == 0 ? FileMode.Create : FileMode.Append))
                    {
                        var buffer = new byte[fileUpload.InputStream.Length];
                        fileUpload.InputStream.Read(buffer, 0, buffer.Length);
                        fs.Write(buffer, 0, buffer.Length);
                    }

                    if (chunk == 0)
                    {
                        photo.ImageURL = "/Content/upload/images/Photo/" + filename + extension;
                        _photoService.UpdatePhoto(photo);
                    }
                }
            }
            return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
        }
 public ActionResult UpdateCategoryMenu(MenuModel menu)
 {
     if (ModelState.IsValid)
     {
         menu.ActionURL = string.Format("{0}-{1}", UrlSlugger.ToUrlSlug(menu.Title), UrlSlugger.Get8Digits());
         BaseResponse response = _menuCategoryService.UpdateMenu(menu);
         ViewBag.Message = response;
     }
     return(View("UpdateCategory", menu));
 }
        public ActionResult CreateCategoryMenu(MenuModel menu, string parentTitle)
        {
            if (ModelState.IsValid)
            {
                FindItemReponse <MenuModel> findParentMenu = _menuCategoryService.FindByTitle(parentTitle);
                if (findParentMenu.Item != null)
                {
                    menu.ParentID = findParentMenu.Item.MenuID;
                }
                menu.MenuID      = Guid.NewGuid().ToString();
                menu.ActionURL   = string.Format("{0}-{1}", UrlSlugger.ToUrlSlug(menu.Title), UrlSlugger.Get8Digits());
                menu.CreatedDate = DateTime.Now;

                InsertResponse response = _menuCategoryService.CreateMenu(menu);
            }
            return(RedirectToAction("Index"));
        }
        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));
        }