private List <LogRecord> getPagedRecords(int?page, LogRecordType recType, out int maxPageNumber) { maxPageNumber = 0; using (zcrlDbContext = new ZcrlContext()) { List <LogRecord> allRecords; allRecords = (from p in zcrlDbContext.LogJournal where (p.RecordType == recType) orderby p.СreatedDate descending select p).ToList(); maxPageNumber = (int)(Math.Ceiling(allRecords.Count() / 50.0)); if (!page.HasValue) { return(allRecords.Take(50).ToList()); } if ((page.Value < 1) || (page.Value > maxPageNumber)) { return(null); } else { return(allRecords.Skip(((page.Value - 1) * 10)).Take(50).ToList()); } } }
public ActionResult Download(long?id) { if (!id.HasValue) { return(RedirectToAction("NotFound", "Error")); } string filePath = null; string fileName = null; using (zcrlDbContext = new ZcrlContext()) { var fileInDb = (from dbF in zcrlDbContext.UploadFiles where (dbF.Id == id.Value) select dbF).FirstOrDefault(); if (fileInDb == null) { return(RedirectToAction("NotFound", "Error")); } else { if (string.IsNullOrWhiteSpace(fileInDb.FileName)) { return(RedirectToAction("NotFound", "Error")); } filePath = System.IO.Path.Combine(Server.MapPath(UPLOADFILE_DIR), fileInDb.FileName); fileName = clearFileName(fileInDb.DisplayName) + System.IO.Path.GetExtension(fileInDb.FileName); } fileInDb.DownloadCount++; zcrlDbContext.SaveChanges(); } byte[] fileBytes = System.IO.File.ReadAllBytes(filePath); return(File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName)); }
// Список статей public ActionResult Articles(int?page) { ViewBag.Title = "Статті"; if (page.HasValue && page.Value <= 0) { return(RedirectToAction("NotFound", "Error")); } using (zcrlDbContext = new ZcrlContext()) { var portalArticles = (from n in zcrlDbContext.PortalPublications.Include("Author").Include("Themes") where (n.InformationType == Models.PublicationType.Article) orderby n.PublicationDate descending select n).ToList(); int maxPageNumber = (int)(Math.Ceiling(portalArticles.Count() / 10.0)); ViewBag.ArticlesCount = portalArticles.Count(); ViewBag.MaxPageNumber = maxPageNumber; if (!page.HasValue) { return(View("PublicationsList", portalArticles.Take(10).ToList())); } ViewBag.page = page.Value; if (page.Value > maxPageNumber) { return(RedirectToAction("NotFound", "Error")); } return(View("PublicationsList", portalArticles.Skip(((page.Value - 1) * 10)).Take(10).ToList())); } }
public ActionResult EditTenderItem(long?id) { using (zcrlDbContext = new ZcrlContext()) { if (!id.HasValue) { return(RedirectToAction("NotFound", "Error")); } ViewBag.GroupsList = (from tg in zcrlDbContext.PortalDataGroups where (tg.RelatedGroup == DataGroupType.TenderGroup) select new ZcrlPortal.ViewModels.SelectListItem() { DisplayName = tg.Name, Value = tg.Id }).ToList(); ViewBag.YearsList = (from y in zcrlDbContext.TenderYears select new ZcrlPortal.ViewModels.SelectListItem() { DisplayName = y.Value.ToString(), Value = y.Id }).ToList(); var requiredItem = (from item in zcrlDbContext.TenderItems.Include("RelatedFile") where (item.Id == id) select item).FirstOrDefault(); if (requiredItem != null) { ViewBag.Mode = CrudMode.Edit; return(View("AddEditItem", requiredItem)); } else { return(RedirectToAction("Tender", "Home")); } } }
public override bool DeleteUser(string username, bool deleteAllRelatedData) { bool result = false; using (ZcrlContext zc = new ZcrlContext()) { var userForDelete = (from u in zc.Users where (u.Login == username) select u).FirstOrDefault(); var userProfile = (from p in zc.Profiles where (p.RelatedUser.Login == username) select p).FirstOrDefault(); if (userProfile != null && deleteAllRelatedData) { zc.Profiles.Remove(userProfile); zc.Users.Remove(userForDelete); zc.SaveChanges(); result = true; } if (userForDelete != null) { zc.Users.Remove(userForDelete); zc.SaveChanges(); result = true; } } return(result); }
public ActionResult UsersList(int?page) { int maxPageNumber = 0; using (zcrlDbContext = new ZcrlContext()) { List <UserProfile> allUsers; allUsers = (from p in zcrlDbContext.Profiles select p).ToList(); maxPageNumber = (int)(Math.Ceiling(allUsers.Count() / 50.0)); ViewBag.MaxPageNumber = maxPageNumber; if (!page.HasValue) { return(View(allUsers.Take(50).ToList())); } ViewBag.page = page.Value; if ((page.Value < 1) || (page.Value > maxPageNumber)) { return(RedirectToAction("NotFound", "Error")); } else { return(View(allUsers.Skip(((page.Value - 1) * 10)).Take(50).ToList())); } } }
public ActionResult EditUserBiography(ZcrlPortal.Models.UserProfile profile) { int profileEditorId = int.Parse(Profile["Id"].ToString()); if ((profile.Id != profileEditorId) && !User.IsInRole("Administrators")) { return(RedirectToAction("EditProfile", "UserProfile")); } using (zcrlDbContext = new ZcrlContext()) { var requiredProfile = (from p in zcrlDbContext.Profiles where (p.Id == profile.Id) select p).FirstOrDefault(); if (requiredProfile != null) { requiredProfile.AboutMe = profile.AboutMe; ViewBag.editProfileSuccess = true; zcrlDbContext.SaveChanges(); zcrlDbContext.LogJournal.Add(new ZcrlPortal.Models.LogRecord() { СreatedDate = DateTime.Now, RecordType = Models.LogRecordType.UserChanges, Content = (requiredProfile.Id == (int)Profile["Id"]) ? string.Format("Користувач <b>{0} {1}.{2}.</b> змінив свою біографію.", requiredProfile.LastName, requiredProfile.FirstName.First(), requiredProfile.MiddleName.First()) : string.Format("Користувач <b>{0} {1}.{2}.</b> змінив біографію користувача <b>{3} {4}.{5}.</b>.", (string)Profile["LastName"], ((string)Profile["FirstName"]).First(), ((string)Profile["MiddleName"]).First(), requiredProfile.LastName, requiredProfile.FirstName.First(), requiredProfile.MiddleName.First()) }); zcrlDbContext.SaveChanges(); } } TempData["Success"] = true; return(RedirectToAction("EditProfile")); }
public ActionResult RegistrationRequestsList(int?page) { int maxPageNumber = 0; using (zcrlDbContext = new ZcrlContext()) { List <RegistrationRequest> allRegRequests; allRegRequests = (from rr in zcrlDbContext.UserRegistrationRequests select rr).ToList(); maxPageNumber = (int)(Math.Ceiling(allRegRequests.Count() / 50.0)); ViewBag.MaxPageNumber = maxPageNumber; if (!page.HasValue) { return(View(allRegRequests.Take(50).ToList())); } ViewBag.page = page.Value; if ((page.Value < 1) || (page.Value > maxPageNumber)) { return(RedirectToAction("NotFound", "Error")); } else { return(View(allRegRequests.Skip(((page.Value - 1) * 10)).Take(50).ToList())); } } }
public ActionResult ChangeChapter(StaticChapter chap) { using (zcrlDbContext = new ZcrlContext()) { var historyChapter = (from c in zcrlDbContext.Chapters where (c.Id == chap.Id) select c).First(); if (historyChapter == null) { return(RedirectToAction("NotFound", "Error")); } historyChapter.Content = chap.Content; zcrlDbContext.SaveChanges(); switch (chap.ChapterType) { case StaticChapterType.History: { return(RedirectToAction("History", "Home")); } case StaticChapterType.PortalInformation: { return(RedirectToAction("Information", "Home")); } default: { return(RedirectToAction("News", "Home")); } } } }
public ActionResult DeleteRegRequest(long?id) { using (zcrlDbContext = new ZcrlContext()) { if (!id.HasValue) { return(RedirectToAction("NotFound", "Error")); } var deletedRequest = (from rr in zcrlDbContext.UserRegistrationRequests where (rr.Id == id) select rr).FirstOrDefault(); if (deletedRequest != null) { string deletedRequestOwner = deletedRequest.LastName + " " + deletedRequest.FirstName + " " + deletedRequest.MiddleName; zcrlDbContext.UserRegistrationRequests.Remove(deletedRequest); zcrlDbContext.SaveChanges(); TempData["SuccessMessage"] = "Заявка користувача " + deletedRequestOwner + " відмовлена!"; return(RedirectToAction("RegistrationRequestsList")); } else { return(RedirectToAction("RegistrationRequestsList")); } } }
public static User CreateUser(string username, string password, Role userRole = null) { using (ZcrlContext zc = new ZcrlContext()) { var userExistRecord = (from u in zc.Users where (u.Login == username) select u).FirstOrDefault(); if (userExistRecord != null) { throw new Exception("Користувач з таким логіном вже існує"); } User newUser = new User() { Login = username, Password = Crypto.HashPassword(password + SALT) }; if (userRole != null) { newUser.UserRole = userRole; newUser.RoleId = userRole.Id; } else { Role defaultRole = (from r in zc.Roles where (r.Name == "JustUsers") select r).FirstOrDefault(); newUser.RoleId = defaultRole.Id; } return(newUser); } }
private void logChanges(AdvBanner oldBanner, AdvBanner newBanner) { string changes = null; if (oldBanner.Name != newBanner.Name) { changes += string.Format("Користувач <b>{0} {1}.{2}.</b> змінив назву банера з '{3}' на '{4}'<br />", (string)Profile["LastName"], ((string)Profile["FirstName"]).First(), ((string)Profile["MiddleName"]).First(), oldBanner.Name, newBanner.Name); } if (oldBanner.DestUrl != newBanner.DestUrl) { changes += string.Format("Користувач <b>{0} {1}.{2}.</b> змінив адресу посилання банера з '{3}' на '{4}'<br />", (string)Profile["LastName"], ((string)Profile["FirstName"]).First(), ((string)Profile["MiddleName"]).First(), oldBanner.DestUrl, newBanner.DestUrl); } if (!string.IsNullOrWhiteSpace(changes)) { using (zcrlDbContext = new ZcrlContext()) { zcrlDbContext.LogJournal.Add(new LogRecord() { СreatedDate = DateTime.Now, RecordType = LogRecordType.BannerAddEdit, Content = changes }); zcrlDbContext.SaveChanges(); } } }
public ActionResult BannersList() { using (zcrlDbContext = new ZcrlContext()) { List <AdvBanner> banners = (from b in zcrlDbContext.Banners orderby b.ViewPriority ascending select b).ToList(); return(View(banners)); } }
public ActionResult FilesList() { using (zcrlDbContext = new ZcrlContext()) { var files = (from uf in zcrlDbContext.UploadFiles where (uf.FileType == UploadFileType.AdminPrivateUpload) select uf).ToList(); return(View(files)); } }
public ActionResult Developer() { using (zcrlDbContext = new ZcrlContext()) { int adminId = (from p in zcrlDbContext.Profiles orderby p.Id ascending select p.Id).First(); return(RedirectToAction("UserInfo", new { id = adminId })); } }
// История больницы public ActionResult History() { using (zcrlDbContext = new ZcrlContext()) { var stChap = (from c in zcrlDbContext.Chapters where (c.ChapterType == Models.StaticChapterType.History) select c).First(); return(View(stChap)); } }
public ActionResult EditFileInList(UploadFile updatedFile, HttpPostedFileBase attachedFile) { string error = getModelError(updatedFile); if (!string.IsNullOrWhiteSpace(error)) { TempData["Error"] = error; return(View("AddEditFile", updatedFile)); } using (zcrlDbContext = new ZcrlContext()) { var requiredFile = (from f in zcrlDbContext.UploadFiles where ((f.FileType == UploadFileType.AdminPrivateUpload) && (f.Id == updatedFile.Id)) select f).FirstOrDefault(); if (requiredFile != null) { if (attachedFile.isValidFile()) { try { if (!string.IsNullOrWhiteSpace(requiredFile.FileName)) { if (System.IO.File.Exists(System.IO.Path.Combine(Server.MapPath(UPLOADFILE_DIR), requiredFile.FileName))) { System.IO.File.Delete(System.IO.Path.Combine(Server.MapPath(UPLOADFILE_DIR), requiredFile.FileName)); } } string newFileName = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(attachedFile.FileName); string newPath = System.IO.Path.Combine(Server.MapPath(UPLOADFILE_DIR), newFileName); attachedFile.SaveAs(newPath); updatedFile.FileName = newFileName; } catch { TempData["Error"] = "Помилка при завантаженні файлу"; return(View("AddEditFile", updatedFile)); } } requiredFile.DisplayName = updatedFile.DisplayName; requiredFile.FileName = updatedFile.FileName; zcrlDbContext.SaveChanges(); TempData["SuccessMessage"] = "Файл успішно змінений"; return(RedirectToAction("FilesList")); } else { return(RedirectToAction("NotFound", "Error")); } } }
public override string[] GetRolesForUser(string username) { string[] rolesForUser = null; using (ZcrlContext zc = new ZcrlContext()) { rolesForUser = (from u in zc.Users where (u.Login == username) select u.UserRole.Name).ToArray(); } return(rolesForUser); }
public override string[] GetAllRoles() { string[] allRoles = null; using (ZcrlContext zc = new ZcrlContext()) { allRoles = (from r in zc.Roles select r.Name).ToArray(); } return(allRoles); }
public ActionResult Register(RegistrationRequest request) { if (User.Identity.IsAuthenticated) { return(RedirectToAction("News", "Home")); } if (ModelState.IsValid) { using (zcrlDbContext = new ZcrlContext()) { var existUser = (from u in zcrlDbContext.Users where (u.Login == request.Login) select u).FirstOrDefault(); var existRequest = (from r in zcrlDbContext.UserRegistrationRequests where (r.Login == request.Login) select r).FirstOrDefault(); if (existUser != null || existRequest != null) { ViewBag.RegistrationError = "Такий логін вже зареєстрований"; return(View(request)); } if (!string.IsNullOrWhiteSpace(request.Email)) { var existUserEmail = (from p in zcrlDbContext.Profiles where (p.Email == request.Email.ToLower()) select p).FirstOrDefault(); var existRequestEmail = (from r in zcrlDbContext.UserRegistrationRequests where (r.Email == request.Email.ToLower()) select r).FirstOrDefault(); if (existUserEmail != null || existRequestEmail != null) { ViewBag.RegistrationError = "Така адреса електронної пошти вже зареєстрована"; return(View(request)); } } } ViewBag.RegistrationSuccess = true; using (zcrlDbContext = new ZcrlContext()) { zcrlDbContext.UserRegistrationRequests.Add(request); zcrlDbContext.SaveChanges(); } // Уведомляем администратора о регистрации sendEmail("*****@*****.**", "ЗАЯВКА НА РЕЄСТРАЦІЮ", string.Format("<b>{0} {1} {2} подав(ла) заявку на реєстрацію на порталі Запорізької ЦРЛ</b>", request.LastName, request.FirstName, request.MiddleName)); return(View()); } else { ViewBag.RegistrationError = ModelState.Values.First(f => f.Errors.Count() >= 1).Errors.First().ErrorMessage; return(View(request)); } }
public override bool RoleExists(string roleName) { bool result = false; using (ZcrlContext zc = new ZcrlContext()) { var requiredRole = (from r in zc.Roles where (r.Name == roleName) select r).FirstOrDefault(); result = (requiredRole != null); } return(result); }
public static bool IsUserExist(string username) { bool result = false; using (ZcrlContext zc = new ZcrlContext()) { var existUser = (from u in zc.Users where (u.Login == username) select u).FirstOrDefault(); result = (existUser != null); } return(result); }
public ActionResult EditInformation() { ViewBag.Title = "Редагування розділу Інформація"; using (zcrlDbContext = new ZcrlContext()) { var historyChapter = (from c in zcrlDbContext.Chapters where (c.ChapterType == StaticChapterType.PortalInformation) select c).First(); return(View("EditStaticChapters", historyChapter)); } }
public ActionResult EditHistory() { ViewBag.Title = "Редагування історії закладу"; using (zcrlDbContext = new ZcrlContext()) { var historyChapter = (from c in zcrlDbContext.Chapters where (c.ChapterType == StaticChapterType.History) select c).First(); return(View("EditStaticChapters", historyChapter)); } }
public ActionResult DeleteUser(int?id) { using (zcrlDbContext = new ZcrlContext()) { if (!id.HasValue) { return(RedirectToAction("NotFound", "Error")); } var deletedProfile = (from p in zcrlDbContext.Profiles where (p.Id == id) select p).FirstOrDefault(); if (deletedProfile != null) { // Таким образои хотя бы один админ останется :) if (deletedProfile.Id == (int)Profile["Id"]) { TempData["Error"] = "Ви не можете видалити самі себе!"; return(RedirectToAction("UsersList")); } string deletedProfileName = deletedProfile.LastName + " " + deletedProfile.FirstName + " " + deletedProfile.MiddleName; ViewBag.Mode = CrudMode.Delete; int userId = deletedProfile.RelatedUser.Id; // Удаляем фото if (deletedProfile.PhotoFileName != null && (System.IO.File.Exists(System.IO.Path.Combine(UPLOADPHOTO_DIR, deletedProfile.PhotoFileName)))) { System.IO.File.Delete(System.IO.Path.Combine(UPLOADPHOTO_DIR, deletedProfile.PhotoFileName)); } zcrlDbContext.LogJournal.Add(new ZcrlPortal.Models.LogRecord() { СreatedDate = DateTime.Now, RecordType = Models.LogRecordType.UserChanges, Content = string.Format("Користувач <b>{0} {1}.{2}.</b> видалив користувача <b>{3} {4}.{5}.</b>", (string)Profile["LastName"], ((string)Profile["FirstName"]).First(), ((string)Profile["MiddleName"]).First(), deletedProfile.LastName, deletedProfile.FirstName.First(), deletedProfile.MiddleName.First()) }); zcrlDbContext.Profiles.Remove(deletedProfile); zcrlDbContext.SaveChanges(); var deletedUser = (from u in zcrlDbContext.Users where (u.Id == userId) select u).First(); zcrlDbContext.Users.Remove(deletedUser); zcrlDbContext.SaveChanges(); TempData["SuccessMessage"] = "Пользователь " + deletedProfileName + " успешно удалён!"; return(RedirectToAction("UsersList")); } else { return(RedirectToAction("UsersList")); } } }
public override string[] GetUsersInRole(string roleName) { string[] usersInRole = null; using (ZcrlContext zc = new ZcrlContext()) { usersInRole = (from u in zc.Users where (u.UserRole.Name == roleName) select u.Login).ToArray(); } return(usersInRole); }
public override string[] FindUsersInRole(string roleName, string usernameToMatch) { string[] usersInRole = null; using (ZcrlContext zc = new ZcrlContext()) { usersInRole = (from u in zc.Users where ((u.UserRole.Name == roleName) && (u.Login == usernameToMatch)) select u.Login).ToArray(); } return(usersInRole); }
public ActionResult Delete(LogRecordType recordsGroup) { string redirectActionName = null; using (zcrlDbContext = new ZcrlContext()) { var logsList = (from l in zcrlDbContext.LogJournal where (l.RecordType == recordsGroup) select l); if (logsList != null) { zcrlDbContext.LogJournal.RemoveRange(logsList); zcrlDbContext.SaveChanges(); } switch (recordsGroup) { case LogRecordType.UserChanges: case LogRecordType.RegistrationsRequests: { redirectActionName = "UsersLog"; break; } case LogRecordType.BannerAddEdit: { redirectActionName = "BannersLog"; break; } case LogRecordType.NewsAddEdit: { redirectActionName = "NewsLog"; break; } case LogRecordType.ArticlesAddEdit: { redirectActionName = "ArticleLog"; break; } case LogRecordType.TendersAddEdit: { redirectActionName = "TenderLog"; break; } } TempData["SuccessMessage"] = "Журнал очіщєно"; return(RedirectToAction(redirectActionName)); } }
public MasterController() { using (zcrlDbContext = new ZcrlContext()) { ViewBag.Banners = (from b in zcrlDbContext.Banners orderby b.ViewPriority ascending select b).ToList(); ViewBag.RegistrationRequests = (from regReq in zcrlDbContext.UserRegistrationRequests select regReq).ToList().Count(); ViewBag.TendersList = (from tenItems in zcrlDbContext.TenderItems group tenItems by tenItems.Year into tenYear orderby tenYear.Max(t => t.Year.Value) descending select new ViewTenderYear() { Name = tenYear.Key.Value.ToString(), Value = tenYear.Key.Value }).ToList(); } }
public override bool IsUserInRole(string username, string roleName) { bool isInRole = false; using (ZcrlContext zc = new ZcrlContext()) { var userInRole = (from u in zc.Users where ((u.Login == username) && (u.UserRole.Name == roleName)) select u).FirstOrDefault(); isInRole = (userInRole != null); } return(isInRole); }