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)); }
public UserLoginResponse Login(string username, string password) { try { IUserRepository userRepository = RepositoryClassFactory.GetInstance().GetUserRepository(); User _user = userRepository.FindByUserName(username); if (_user != null) { if (_user.Locked) { return(new UserLoginResponse { ErrorCode = (int)ErrorCode.Error, Message = Resources.Resource.msg_account_locked }); } } IUserSessionRepository userSessionRepository = RepositoryClassFactory.GetInstance().GetUserSessionRepository(); User user = userRepository.Login(username, password); if (user != null) { try { userSessionRepository.DeleteByUserID(user.UserID); } catch (Exception) { } int timeOut = TIME_OUT_MINUTES * 60 * 1000; UserSession userSession = new UserSession { CreatedDate = DateTime.Now, UserID = user.UserID, SessionID = Guid.NewGuid().ToString(), UpdatedDate = DateTime.Now }; object sessionID = userSessionRepository.Insert(userSession); return(new UserLoginResponse { ErrorCode = (int)ErrorCode.None, Message = string.Empty, SessionId = userSession.SessionID, UserId = user.UserID, UserName = user.UserName }); } else { return(new UserLoginResponse { ErrorCode = (int)ErrorCode.Error, Message = Resources.Resource.msg_login_fail }); } } catch (Exception ex) { return(new UserLoginResponse { ErrorCode = (int)ErrorCode.Error, Message = ex.Message }); } }