public async Task <IActionResult> Create(LayoutModel layoutModel) { try { UserModel userModel = new UserModel ( new User { Status = (short)StatusOptions.Actived, Role = (short)RoleOptions.Student }, configuration["MediaFolderPath"] ); await layoutModel.Refresh(suggestionLogic, int.Parse(configuration["DashboardTopSuggestionLimit"]), configuration["MediaFolderPath"]); var pageModel = new PageModel <UserModel> ( userModel, layoutModel ); return(View("Edit", pageModel)); } catch (Exception ex) { loggerFactory.CreateLogger(ex.GetType()).LogError($"{ex}\n\n"); TempData["MessageType"] = MessageOptions.Warning; TempData["Message"] = Text.An_error_occured; } if (!string.IsNullOrEmpty(layoutModel.ReturnUrl)) { return(Redirect(layoutModel.ReturnUrl)); } return(RedirectToAction("Index")); }
public async Task <IActionResult> Profile(LayoutModel layoutModel) { try { var userModel = await userLogic.GetAsync ( HttpContext, configuration["MediaFolderPath"] ); var profileModel = new ProfileModel(userModel); await layoutModel.Refresh(suggestionLogic, int.Parse(configuration["DashboardTopSuggestionLimit"]), configuration["MediaFolderPath"]); var pageModel = new PageModel <ProfileModel> ( profileModel, layoutModel ); ViewBag.Account = pageModel.DataModel.Account; return(View(pageModel)); } catch (Exception ex) { loggerFactory.CreateLogger(ex.GetType()).LogError($"{ex}\n\n"); TempData["MessageType"] = MessageOptions.Warning; TempData["Message"] = Text.An_error_occured; } return(RedirectToAction("Logout")); }
public async Task <IActionResult> Edit(int?id, LayoutModel layoutModel) { try { int userId = 0; if (!string.IsNullOrEmpty(User.Claims.FirstOrDefault(x => x.Type == "User.Id")?.Value)) { userId = int.Parse(User.Claims.FirstOrDefault(x => x.Type == "User.Id")?.Value ?? "0"); } var documentModel = await documentLogic.GetAsync ( id ?? 0, configuration["MediaFolderPath"], userId ); if (documentModel == null) { TempData["MessageType"] = MessageOptions.Warning; TempData["Message"] = Text.Document_not_found; if (!string.IsNullOrEmpty(layoutModel.ReturnUrl)) { return(Redirect(layoutModel.ReturnUrl)); } } else { PageModel <DocumentModel> pageModel = null; if (TempData["PageModel"] != null) { pageModel = JsonConvert.DeserializeObject <PageModel <DocumentModel> >(TempData["PageModel"].ToString()); } else { documentModel.SetCategoryModels ( await categoryLogic.NoChildAsync(configuration["MediaFolderPath"]), documentModel.CategoryId ); await layoutModel.Refresh(suggestionLogic, int.Parse(configuration["DashboardTopSuggestionLimit"]), configuration["MediaFolderPath"]); pageModel = new PageModel <DocumentModel> ( documentModel, layoutModel ); } return(View(pageModel)); } } catch (Exception ex) { loggerFactory.CreateLogger(ex.GetType()).LogError($"{ex}\n\n"); TempData["MessageType"] = MessageOptions.Danger; TempData["Message"] = Text.An_error_occured; } return(RedirectToAction("Index")); }
public async Task <IActionResult> Read(string id, LayoutModel layoutModel) { try { int userId = 0; if (!string.IsNullOrEmpty(User.Claims.FirstOrDefault(x => x.Type == "User.Id")?.Value)) { userId = int.Parse(User.Claims.FirstOrDefault(x => x.Type == "User.Id")?.Value ?? "0"); } var documentModel = await documentLogic.GetAsync ( id, (RoleOptions)Enum.Parse(typeof(RoleOptions), User.FindFirst(ClaimTypes.Role).Value), configuration["MediaFolderPath"], userId ); if (documentModel == null) { TempData["MessageType"] = MessageOptions.Warning; TempData["Message"] = Text.Document_not_found; if (!string.IsNullOrEmpty(layoutModel.ReturnUrl)) { return(Redirect(layoutModel.ReturnUrl)); } } else { //documentModel.SetCategoryModels //( // await categoryLogic.NoChildAsync(configuration["MediaFolderPath"]), // documentModel.CategoryId //); await documentLogic.IncrementCountReadAsync(documentModel.Code, userId); await layoutModel.Refresh(suggestionLogic, int.Parse(configuration["DashboardTopSuggestionLimit"]), configuration["MediaFolderPath"]); var pageModel = new PageModel <DocumentModel> ( documentModel, layoutModel ); return(View(pageModel)); } } catch (Exception ex) { loggerFactory.CreateLogger(ex.GetType()).LogError($"{ex}\n\n"); TempData["MessageType"] = MessageOptions.Danger; TempData["Message"] = Text.An_error_occured; } return(RedirectToAction("Index")); }
public async Task <IActionResult> Edit(int?id, LayoutModel layoutModel) { try { var suggestionModel = await suggestionLogic.GetAsync ( id ?? 0, configuration["MediaFolderPath"] ); if (suggestionModel == null) { TempData["MessageType"] = MessageOptions.Warning; TempData["Message"] = Text.Suggestion_not_found; if (!string.IsNullOrEmpty(layoutModel.ReturnUrl)) { return(Redirect(layoutModel.ReturnUrl)); } } else { PageModel <SuggestionModel> pageModel = null; if (TempData["PageModel"] != null) { pageModel = JsonConvert.DeserializeObject <PageModel <SuggestionModel> >(TempData["PageModel"].ToString()); } else { await layoutModel.Refresh(suggestionLogic, int.Parse(configuration["DashboardTopSuggestionLimit"]), configuration["MediaFolderPath"]); pageModel = new PageModel <SuggestionModel> ( suggestionModel, layoutModel ); } return(View(pageModel)); } } catch (Exception ex) { loggerFactory.CreateLogger(ex.GetType()).LogError($"{ex}\n\n"); TempData["MessageType"] = MessageOptions.Danger; TempData["Message"] = Text.An_error_occured; } return(RedirectToAction("Index")); }
public async Task <IActionResult> Edit(int?id, LayoutModel layoutModel) { try { var categoryModel = await categoryLogic.GetAsync ( id ?? 0, configuration["MediaFolderPath"] ); if (categoryModel == null) { TempData["MessageType"] = MessageOptions.Warning; TempData["Message"] = Text.Category_not_found; if (!string.IsNullOrEmpty(layoutModel.ReturnUrl)) { return(Redirect(layoutModel.ReturnUrl)); } } else { categoryModel.SetCategoryParentModels ( await categoryLogic.NoDocumentAsync(configuration["MediaFolderPath"]), categoryModel.CategoryParentId ); await layoutModel.Refresh(suggestionLogic, int.Parse(configuration["DashboardTopSuggestionLimit"]), configuration["MediaFolderPath"]); var pageModel = new PageModel <CategoryModel> ( categoryModel, layoutModel ); return(View(pageModel)); } } catch (Exception ex) { loggerFactory.CreateLogger(ex.GetType()).LogError($"{ex}\n\n"); TempData["MessageType"] = MessageOptions.Warning; TempData["Message"] = Text.An_error_occured; } return(RedirectToAction("Index")); }
public async Task <IActionResult> Create(LayoutModel layoutModel) { try { PageModel <DocumentModel> pageModel = null; if (TempData["PageModel"] != null) { pageModel = JsonConvert.DeserializeObject <PageModel <DocumentModel> >(TempData["PageModel"].ToString()); } else { DocumentModel documentModel = new DocumentModel ( null, await categoryLogic.NoChildAsync(configuration["MediaFolderPath"]), null, StatusOptions.Actived ); await layoutModel.Refresh(suggestionLogic, int.Parse(configuration["DashboardTopSuggestionLimit"]), configuration["MediaFolderPath"]); pageModel = new PageModel <DocumentModel> ( documentModel, layoutModel ); } return(View("Edit", pageModel)); } catch (Exception ex) { loggerFactory.CreateLogger(ex.GetType()).LogError($"{ex}\n\n"); TempData["MessageType"] = MessageOptions.Danger; TempData["Message"] = Text.An_error_occured; } if (!string.IsNullOrEmpty(layoutModel.ReturnUrl)) { return(Redirect(layoutModel.ReturnUrl)); } return(RedirectToAction("Index")); }
public async Task <IActionResult> Login(LayoutModel layoutModel) { if (User.Identity.IsAuthenticated) { return(RedirectToAction("Index", "Home")); } var loginModel = new LoginModel ( "jessica", "Jessica@2020" ); await layoutModel.Refresh(suggestionLogic, int.Parse(configuration["DashboardTopSuggestionLimit"]), configuration["MediaFolderPath"]); var pageModel = new PageModel <LoginModel> ( loginModel, layoutModel ); return(View(pageModel)); }
public async Task <IActionResult> Create(LayoutModel layoutModel) { try { PageModel <SuggestionModel> pageModel = null; if (TempData["PageModel"] != null) { pageModel = JsonConvert.DeserializeObject <PageModel <SuggestionModel> >(TempData["PageModel"].ToString()); } else { int userId = 0; if (!string.IsNullOrEmpty(User.Claims.FirstOrDefault(x => x.Type == "User.Id")?.Value)) { userId = int.Parse(User.Claims.FirstOrDefault(x => x.Type == "User.Id")?.Value ?? "0"); } var userModel = await userLogic.GetAsync(userId, configuration["MediaFolderPath"]); SuggestionModel suggestionModel = new SuggestionModel ( new Suggestion ( 0, null, null, null, false, false, DateTime.UtcNow, userId, new User ( userModel.Id, userModel.Account, userModel.Password, userModel.FullName, (short)userModel.Role, userModel.ImageName, (short)userModel.Status ) ), configuration["MediaFolderPath"], configuration["MediaFolderPath"] ); await layoutModel.Refresh(suggestionLogic, int.Parse(configuration["DashboardTopSuggestionLimit"]), configuration["MediaFolderPath"]); pageModel = new PageModel <SuggestionModel> ( suggestionModel, layoutModel ); } return(View("Edit", pageModel)); } catch (Exception ex) { loggerFactory.CreateLogger(ex.GetType()).LogError($"{ex}\n\n"); TempData["MessageType"] = MessageOptions.Danger; TempData["Message"] = Text.An_error_occured; } if (!string.IsNullOrEmpty(layoutModel.ReturnUrl)) { return(Redirect(layoutModel.ReturnUrl)); } return(RedirectToAction("Index")); }
public async Task <IActionResult> Index() { var dashboardTopCategoryReadingsLimit = int.Parse(configuration["DashboardTopCategoryReadingsLimit"]); var dashboardTopSubCategoryReadingsLimit = int.Parse(configuration["DashboardTopSubCategoryReadingsLimit"]); var dashboardTopPercentSubCategoryReadingsLimit = int.Parse(configuration["DashboardTopPercentSubCategoryReadingsLimit"]); var dashboardTopDocumentReadingsLimit = int.Parse(configuration["DashboardTopDocumentReadingsLimit"]); //top sub categories reading IDictionary <CategoryModel, double> topSubCategoriesReading = await categoryLogic.TopSubCategoriesReading ( dashboardTopSubCategoryReadingsLimit, configuration["MediaFolderPath"] ); //reading per month IDictionary <string, long> readingOverview = await documentLogic.ReadingCountPerMonth(); //top categories readings IDictionary <string, double> readingByCategoryOverview = new Dictionary <string, double>(); var rootCategories = ( await categoryLogic.GetRootsAsync(configuration["MediaFolderPath"]) ) .Where(x => x.DocumentIds.Count > 0).ToArray(); foreach (var root in rootCategories) { readingByCategoryOverview.Add ( root.Name, await documentLogic.ReadCountAsync(root.DocumentIds) ); } // top document reading limit var topDocumentReadings = await documentLogic.TopReading(dashboardTopDocumentReadingsLimit, configuration["MediaFolderPath"]); var dashboardModel = new DashboardModel ( readingByCategoryOverview.Count < dashboardTopCategoryReadingsLimit ? readingByCategoryOverview.Count : dashboardTopCategoryReadingsLimit, dashboardTopSubCategoryReadingsLimit, topSubCategoriesReading.Count < dashboardTopPercentSubCategoryReadingsLimit ? topSubCategoriesReading.Count : dashboardTopPercentSubCategoryReadingsLimit, topSubCategoriesReading, readingOverview, readingByCategoryOverview .Where(x => x.Value > 0) .OrderByDescending(x => x.Value) .Take(dashboardTopCategoryReadingsLimit) .ToDictionary(x => x.Key, x => x.Value), topDocumentReadings ); var layoutModel = new LayoutModel(); await layoutModel.Refresh(suggestionLogic, int.Parse(configuration["DashboardTopSuggestionLimit"]), configuration["MediaFolderPath"]); var pageModel = new PageModel <DashboardModel> ( dashboardModel, layoutModel ); return(View(pageModel)); }