public ActionResult DocumentsNotificationUserMessage() { DateTime TodayDate = DateTime.ParseExact(DateTime.Now.ToString("yyyy/MM/dd").Replace("-", "/"), "yyyy/MM/dd", null); string CurrentUserId = this.User.Identity.GetUserId(); List <Document> Documents = db.Documents.Where(a => a.NotificationUserId.Equals(CurrentUserId) && a.NotificationDate != null).ToList(); Documents = Documents.Where(a => EqualDate(a.NotificationDate, TodayDate)).OrderByDescending(a => a.CreatedAt).Take(4).ToList(); Notification notification = null; string NotificationTime = DateTime.Now.ToString("dd/MM/yyyy-HH:mm:ss"); List <Notification> NotificationList = new List <Notification>(); foreach (Document d in Documents) { notification = new Notification() { CreatedAt = NotificationTime, Active = false, Message = "تنبيه للوثيقة :" + (ManagedAes.CipherData?ManagedAes.DecryptText(d.DocumentNumber): d.DocumentNumber) + " " + " موضوع الوثيقة :" + (ManagedAes.CipherData ? ManagedAes.DecryptText(d.Subject) : d.Subject) + " ،عنوان الوثيقة :" + (ManagedAes.CipherData ? ManagedAes.DecryptText(d.Address) : d.Address) + "،وصف الوثيقة :" + (ManagedAes.CipherData ? ManagedAes.DecryptText(d.Description) : d.Description) , NotificationOwnerId = db.Users.Find(CurrentUserId).FullName }; NotificationList.Add(notification); } return(PartialView("_DocumentsNotificationMessage", NotificationList.ToList())); }
public FileResult DownloadDocument(int?id) { var SealFiles = _context.SealFiles.Find(id); var fileName = SealFiles.FileName; if (!ManagedAes.IsSaveInDb) { if (ManagedAes.IsCipher) { SealFiles.FileUrl = ManagedAes.DecryptText(SealFiles.FileUrl); fileName = ManagedAes.DecryptText(fileName); } string filePath = Server.MapPath("~/Uploads/").Replace(@"\", "/") + SealFiles.FileUrl; byte[] fileBytes = ManagedAes.DecryptFile(filePath); return(File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName)); } else { if (ManagedAes.IsCipher) { fileName = ManagedAes.DecryptText(SealFiles.FileName); SealFiles.File = ManagedAes.DecryptArrayByte(SealFiles.File); } return(File(SealFiles.File, System.Net.Mime.MediaTypeNames.Application.Octet, fileName)); } }
public ActionResult Confirm(int?id) { if (id == null) { return(RedirectToAction("BadRequestError", "ErrorController")); } var seal = _context.SealDocuments.Find(id); if (seal == null) { return(RedirectToAction("HttpNotFoundError", "ErrorController")); } if (ManagedAes.IsCipher) { seal.CreatedAt = ManagedAes.DecryptText(seal.CreatedAt); seal.FileName = ManagedAes.DecryptText(seal.FileName); seal.Message = ManagedAes.DecryptText(seal.Message); } _context.SealDocuments.Remove(seal); _context.SaveChanges(); return(RedirectToAction("Index", new { id = seal.DocumentId })); }
public ActionResult ActiveNOnActiveConfirmSeal(int id) { string ActiveMode = string.Empty; string NotificationTime = string.Empty; string UserId = User.Identity.GetUserId(); Document doc = db.DocumentUsers.Include(a => a.document).SingleOrDefault(a => a.Id == id).document; DocumentUser documentUser = db.DocumentUsers.Find(id); if (documentUser.EnableSeal == true) { documentUser.EnableSeal = false; ActiveMode = "الغاء إمكانبة التسديد"; } else { documentUser.EnableSeal = true; ActiveMode = "تفعيل إمكانية التسديد"; } documentUser.UpdatedAt = DateTime.Now.ToString("dd/MM/yyyy-HH:mm:ss"); db.Entry(documentUser).State = EntityState.Modified; int Form_id = documentUser.DocumentId; db.SaveChanges(); Notification notification = null; NotificationTime = DateTime.Now.ToString("dd/MM/yyyy-HH:mm:ss"); notification = new Notification() { CreatedAt = NotificationTime, Active = false, UserId = documentUser.UserId, Message = "تمت عملية " + ActiveMode + " للوثيقة ، رقم الوثيقة" + "" + (ManagedAes.CipherData ? ManagedAes.DecryptText(doc.DocumentNumber) : doc.DocumentNumber) + " موضوع الوثيقة :" + (ManagedAes.CipherData ? ManagedAes.DecryptText(doc.Subject) : doc.Subject) + " ،عنوان الوثيقة :" + (ManagedAes.CipherData ? ManagedAes.DecryptText(doc.Address) : doc.Address) + "،وصف الوثيقة :" + (ManagedAes.CipherData ? ManagedAes.DecryptText(doc.Description) : doc.Description) , NotificationOwnerId = UserId }; db.Notifications.Add(notification); db.SaveChanges(); return(RedirectToAction("Index", new { @id = Form_id, @msg = "EditSuccess" })); }
public ActionResult DeleteConfirmed(int id) { ViewBag.Current = "Document"; List <string> UsersId = new List <string>(); string NotificationTime = string.Empty; string UserId = User.Identity.GetUserId(); DocumentGroup documentGroup = db.DocumentGroups.Find(id); db.DocumentGroups.Remove(documentGroup); int Document_Id = documentGroup.DocumentId; db.SaveChanges(); Document doc = db.Documents.Find(documentGroup.DocumentId); NotificationTime = DateTime.Now.ToString("dd/MM/yyyy-HH:mm:ss"); UsersId = db.UsersGroups.Where(a => a.GroupId == documentGroup.GroupId).Select(a => a.UserId).ToList(); string GroupName = db.Groups.Find(documentGroup.GroupId).Name; Notification notification = null; List <ApplicationUser> Users = db.Users.Where(a => UsersId.Contains(a.Id)).ToList(); foreach (ApplicationUser user in Users) { notification = new Notification() { CreatedAt = NotificationTime, Active = false, UserId = user.Id, Message = "تم حذف وثيقة من المجموعة :" + GroupName + "، رقم الوثيقة :" + (ManagedAes.CipherData ? ManagedAes.DecryptText(doc.DocumentNumber) : doc.DocumentNumber) + " موضوع الوثيقة :" + (ManagedAes.CipherData ? ManagedAes.DecryptText(doc.Subject) : doc.Subject) + " ،عنوان الوثيقة :" + (ManagedAes.CipherData ? ManagedAes.DecryptText(doc.Address) : doc.Address) + "،وصف الوثيقة :" + (ManagedAes.CipherData ? ManagedAes.DecryptText(doc.Description) : doc.Description) , NotificationOwnerId = UserId }; db.Notifications.Add(notification); } db.SaveChanges(); return(RedirectToAction("Index", new { @id = Document_Id, @msg = "DeleteSuccess" })); }
public ActionResult DeleteConfirmed(int id) { List <string> UsersId = new List <string>(); string NotificationTime = string.Empty; string UserId = User.Identity.GetUserId(); Document doc = db.DocumentDepartments.Include(a => a.document).SingleOrDefault(a => a.Id == id).document; DocumentDepartment documentDepartment = db.DocumentDepartments.Find(id); db.DocumentDepartments.Remove(documentDepartment); int Form_id = documentDepartment.DocumentId; db.SaveChanges(); UsersId = db.Users.Where(a => a.DepartmentId == documentDepartment.DepartmentId).Select(a => a.Id).ToList(); Notification notification = null; NotificationTime = DateTime.Now.ToString("dd/MM/yyyy-HH:mm:ss"); List <ApplicationUser> Users = db.Users.Where(a => UsersId.Contains(a.Id)).ToList(); foreach (ApplicationUser user in Users) { notification = new Notification() { CreatedAt = NotificationTime, Active = false, UserId = user.Id, Message = "تم إزالة وثيقة من القسم الحالي، رقم الوثيقة :" + (ManagedAes.CipherData ? ManagedAes.DecryptText(doc.DocumentNumber) : doc.DocumentNumber) + " موضوع الوثيقة :" + (ManagedAes.CipherData ? ManagedAes.DecryptText(doc.Subject) : doc.Subject) + " ،عنوان الوثيقة :" + (ManagedAes.CipherData ? ManagedAes.DecryptText(doc.Address) : doc.Address) + "،وصف الوثيقة :" + (ManagedAes.CipherData ? ManagedAes.DecryptText(doc.Description) : doc.Description) , NotificationOwnerId = UserId }; db.Notifications.Add(notification); } db.SaveChanges(); return(RedirectToAction("Index", new { @id = Form_id, @msg = "DeleteSuccess" })); }
public bool EqualDate(string s1, DateTime s2) { try { if (ManagedAes.CipherData) { s1 = ManagedAes.DecryptText(s1); } s1 = s1.Replace("-", "/"); return(DateTime.ParseExact(s1, "yyyy/MM/dd", null) == s2); } catch (Exception e) { return(false); } }
public ActionResult ActiveNOnActiveSeal(int?id) { if (id == null) { return(RedirectToAction("BadRequestError", "ErrorController")); } DocumentUser documentUser = db.DocumentUsers.Include(a => a.document).Include(a => a.User).SingleOrDefault(a => a.Id == id); if (documentUser == null) { return(RedirectToAction("HttpNotFoundError", "ErrorController")); } if (ManagedAes.CipherData) { documentUser.document.Subject = ManagedAes.DecryptText(documentUser.document.Subject); } return(View(documentUser)); }
public ActionResult Details(int?id) { if (id == null) { return(RedirectToAction("BadRequestError", "ErrorController")); } DocumentGroup documentGroup = db.DocumentGroups.Include(a => a.CreatedBy).Include(a => a.document).Include(a => a.Group).SingleOrDefault(a => a.Id == id); if (documentGroup == null) { return(RedirectToAction("HttpNotFoundError", "ErrorController")); } if (ManagedAes.CipherData) { documentGroup.document.Subject = ManagedAes.DecryptText(documentGroup.document.Subject); } return(View(documentGroup)); }
public ActionResult Delete(int?id) { if (id == null) { return(RedirectToAction("BadRequestError", "ErrorController")); } DocumentDepartment documentDepartment = db.DocumentDepartments.Include(a => a.document).Include(a => a.Department).SingleOrDefault(a => a.Id == id); if (documentDepartment == null) { return(RedirectToAction("HttpNotFoundError", "ErrorController")); } if (ManagedAes.CipherData) { documentDepartment.document.Subject = ManagedAes.DecryptText(documentDepartment.document.Subject); } return(View(documentDepartment)); }
public ActionResult DeleteConfirmed(int id) { string NotificationTime = string.Empty; string UserId = User.Identity.GetUserId(); Document doc = db.DocumentUsers.Include(a => a.document).SingleOrDefault(a => a.Id == id).document; string User_Id = db.DocumentUsers.Include(a => a.document).SingleOrDefault(a => a.Id == id).UserId; DocumentUser documentuser = db.DocumentUsers.Find(id); int Form_id = documentuser.DocumentId; db.DocumentUsers.Remove(documentuser); db.SaveChanges(); Notification notification = null; NotificationTime = DateTime.Now.ToString("dd/MM/yyyy-HH:mm:ss"); notification = new Notification() { CreatedAt = NotificationTime, Active = false, UserId = User_Id, Message = "تم إزالة وثيقة ، رقم الوثيقة :" + (ManagedAes.CipherData ? ManagedAes.DecryptText(doc.DocumentNumber) : doc.DocumentNumber) + " موضوع الوثيقة :" + (ManagedAes.CipherData ? ManagedAes.DecryptText(doc.Subject) : doc.Subject) + " ،عنوان الوثيقة :" + (ManagedAes.CipherData ? ManagedAes.DecryptText(doc.Address) : doc.Address) + "،وصف الوثيقة :" + (ManagedAes.CipherData ? ManagedAes.DecryptText(doc.Description) : doc.Description) , NotificationOwnerId = UserId }; db.Notifications.Add(notification); db.SaveChanges(); return(RedirectToAction("Index", new { @id = Form_id, @msg = "DeleteSuccess" })); }
public ActionResult Delete(int?id) { if (id == null) { return(RedirectToAction("BadRequestError", "ErrorController")); } DocumentParty DocumentParty = db.DocumentParties.Include(a => a.Document).Include(a => a.CreatedBy).Include(a => a.Party).SingleOrDefault(a => a.Id == id); if (DocumentParty == null) { return(RedirectToAction("HttpNotFoundError", "ErrorController")); } if (ManagedAes.CipherData) { DocumentParty.Document.Subject = ManagedAes.DecryptText(DocumentParty.Document.Subject); } return(View(DocumentParty)); }
public ActionResult Index(int?Id, string msg = "none") { ViewBag.Current = "Document"; if (Id == null) { return(RedirectToAction("BadRequestError", "ErrorController")); } Document document = db.Documents.Find(Id); if (document == null) { return(RedirectToAction("HttpNotFoundError", "ErrorController")); } if (!msg.Equals("none")) { ViewBag.Msg = msg; } else { ViewBag.Msg = null; } Session["document_Id"] = Id; var DocumentDepartments = db.DocumentDepartments.Where(a => a.DocumentId == Id).Include(a => a.CreatedBy).Include(a => a.Department).Include(a => a.document).ToList(); if (ManagedAes.CipherData) { foreach (DocumentDepartment Dk in DocumentDepartments) { Dk.document.Subject = ManagedAes.DecryptText(document.Subject); } } return(View(DocumentDepartments.OrderByDescending(a => a.CreatedAt).ToList())); }
public ActionResult Delete(int?id) { if (id == null) { return(RedirectToAction("BadRequestError", "ErrorController")); } var seal = _context.SealDocuments.Find(id); if (seal == null) { return(RedirectToAction("HttpNotFoundError", "ErrorController")); } if (ManagedAes.IsCipher) { seal.CreatedAt = ManagedAes.DecryptText(seal.CreatedAt); seal.FileName = ManagedAes.DecryptText(seal.FileName); seal.Message = ManagedAes.DecryptText(seal.Message); } return(View(seal)); }
public ActionResult AllIndex(int?id) { if (id == null) { return(RedirectToAction("BadRequestError", "ErrorController")); } string currentUserId = this.User.Identity.GetUserId(); ViewBag.DocId = id.Value; var seals = _context.SealDocuments.Where(s => s.DocumentId == id).Include(s => s.Files).Include(s => s.Document).Include(s => s.CreatedBy).ToList(); if (ManagedAes.IsCipher && seals.Count != 0) { seals[0].Document.Subject = ManagedAes.DecryptText(seals[0].Document.Subject); } if (ManagedAes.IsCipher) { //seals[0].Document.Subject = ManagedAes.DecryptText(seals[0].Document.Subject); foreach (var seal in seals) { //seal.Document.Subject = ManagedAes.DecryptText(seal.Document.Subject); seal.CreatedAt = ManagedAes.DecryptText(seal.CreatedAt); seal.FileName = ManagedAes.DecryptText(seal.FileName); seal.Message = ManagedAes.DecryptText(seal.Message); foreach (var file in seal.Files) { file.FileName = ManagedAes.DecryptText(file.FileName); } } } return(View(seals)); }
public ActionResult ChangeSetting(SettingInformations model) { string fileName = Server.MapPath("~/Resources/MySecretFile.xml"); DataSet ds = new DataSet(); ds.ReadXml(fileName); if (ModelState.IsValid) { if (ConfirmLogin(model.UserName, model.Password)) { ds.Tables[0].Rows[0]["sd"] = (model.SaveDataBase == true)?"true":"false"; ds.Tables[0].Rows[0]["ci"] = (model.Cigher == true) ? "true" : "false"; ds.Tables[0].Rows[0]["cf"] = (model.Cigher == true) ? "true" : "false"; ds.Tables[0].Rows[0]["md"] = ManagedAes.EncryptText(model.MotherBoardId); ds.Tables[0].Rows[0]["cd"] = ManagedAes.EncryptText(model.CpudId); ds.WriteXml(fileName); return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("UserName", "خطأ في التأكيد "); ModelState.AddModelError("Password", "خطأ في التأكيد"); return(View(model)); } } return(View()); }
public ActionResult Index(int?id) { if (id == null) { return(RedirectToAction("BadRequestError", "ErrorController")); } var seals = _context.SealDocuments.Where(s => s.DocumentId == id).Include(s => s.Files).Include(s => s.Document).Include(s => s.CreatedBy).ToList(); if (seals == null) { return(RedirectToAction("HttpNotFoundError", "ErrorController")); } if (ManagedAes.IsCipher && seals.Count != 0) { seals[0].Document.Subject = ManagedAes.DecryptText(seals[0].Document.Subject); } if (ManagedAes.IsCipher) { //seals[0].Document.Subject = ManagedAes.DecryptText(seals[0].Document.Subject); foreach (var seal in seals) { //seal.Document.Subject = ManagedAes.DecryptText(seal.Document.Subject); seal.CreatedAt = ManagedAes.DecryptText(seal.CreatedAt); seal.FileName = ManagedAes.DecryptText(seal.FileName); seal.Message = ManagedAes.DecryptText(seal.Message); foreach (var file in seal.Files) { file.FileName = ManagedAes.DecryptText(file.FileName); } } } return(View(seals)); }
public ActionResult Index(int?Id, string msg = "none") { ViewBag.Current = "Document"; if (Id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Document document = db.Documents.Find(Id); if (document == null) { return(HttpNotFound()); } if (!msg.Equals("none")) { ViewBag.Msg = msg; } else { ViewBag.Msg = null; } Session["Document_Id"] = Id; var documentGroups = db.DocumentGroups.Where(a => a.DocumentId == Id).Include(f => f.CreatedBy).Include(f => f.Group).Include(f => f.document); if (ManagedAes.CipherData) { foreach (DocumentGroup Dk in documentGroups) { Dk.document.Subject = ManagedAes.DecryptText(Dk.document.Subject); } } return(View(documentGroups.OrderByDescending(a => a.CreatedAt).ToList())); }
public ActionResult Index() { Informations info = new Informations(); string CurrentUserId = this.User.Identity.GetUserId(); //Information For master: if (db.Users.Find(CurrentUserId).RoleName.Equals("Master")) { info.IsMasterRole = true; //Departments: info.MainDepartmentCount = db.Departments.Where(a => a.ParentId == null).Count(); info.AllDepartmentsCount = db.Departments.Count(); info.LastDateDepartmentCreate = db.Departments.Count() != 0 ? db.Departments.OrderByDescending(a => a.CreatedAt).FirstOrDefault().CreatedAt : ""; info.LastDateDepartmentUpdate = db.Departments.Count(a => a.UpdatedAt != null) != 0 ? db.Departments.OrderByDescending(a => a.UpdatedAt).FirstOrDefault().UpdatedAt : ""; //Groups: info.AllGroupsCount = db.Groups.Count(); info.LastGroupCreate = db.Groups.Count() != 0 ? db.Groups.OrderByDescending(a => a.CreatedAt).FirstOrDefault().CreatedAt : ""; info.TotalUserInGroup = db.UsersGroups.Select(a => a.UserId).Distinct().Count(); info.LastGroupUpdate = db.Groups.Count(a => a.UpdatedAt != null) != 0 ? db.Departments.OrderByDescending(a => a.UpdatedAt).FirstOrDefault().UpdatedAt : ""; int HightGroupUsersC = db.UsersGroups.Count() == 0 ? 0 : db.UsersGroups.Include(a => a.Group).GroupBy(a => a.Group.Name).Select(a => new { Key = a.Key, count = a.Count() }).OrderByDescending(a => a.count).FirstOrDefault().count; ; if (HightGroupUsersC != 0) { List <string> GName = new List <string>(); GName = db.UsersGroups.Include(a => a.Group).GroupBy(a => a.Group.Name).Select(a => new { Key = a.Key, count = a.Count() }).Where(a => a.count == HightGroupUsersC).Select(a => a.Key).ToList(); info.HightGroupUsers = GName.Aggregate((a, b) => a + "," + b); } else { info.HightGroupUsers = ""; } //Forms: info.TotalFormsCount = db.Forms.Count(); info.LastFormCreate = db.Forms.Count() != 0 ? db.Forms.OrderByDescending(a => a.CreatedAt).FirstOrDefault().CreatedAt : ""; info.LastFormUpdate = db.Forms.Count(a => a.UpdatedAt != null) != 0 ? db.Departments.OrderByDescending(a => a.UpdatedAt).FirstOrDefault().UpdatedAt : ""; info.HightFormUsing = ""; int HightFormUsingC = db.Documents.Count() == 0 ? 0 : db.Documents.Include(a => a.Form).GroupBy(a => a.Form.Name) .Select(a => new { key = a.Key, count = a.Count() }).OrderByDescending(a => a.count).FirstOrDefault().count; if (HightFormUsingC != 0) { List <string> FName = new List <string>(); FName = db.Documents.Include(a => a.Form).GroupBy(a => a.Form.Name) .Select(a => new { key = a.Key, count = a.Count() }).Where(a => a.count == HightFormUsingC).Select(a => a.key).ToList(); info.HightFormUsing = FName.Aggregate((a, b) => a + "," + b); } else { info.HightFormUsing = ""; } //Users: info.TotalUserCount = db.Users.Count(); info.LastUserCreate = db.Users.Count() != 0 ? db.Users.OrderByDescending(a => a.CreatedAt).FirstOrDefault().CreatedAt : ""; info.LastUserUpdate = db.Users.Count(a => a.UpdatedAt != null) != 0 ? db.Users.OrderByDescending(a => a.UpdatedAt).FirstOrDefault().UpdatedAt : ""; //Document info.TotalDocumentCount = db.Documents.Count(); info.LastDocumentCreate = db.Documents.Count() != 0 ? db.Documents.OrderByDescending(a => a.CreatedAt).FirstOrDefault().CreatedAt : ""; //Mails: info.TotalMailsCount = db.TypeMails.Count(); info.LastMailsCreate = db.TypeMails.Count() != 0 ? db.TypeMails.OrderByDescending(a => a.CreatedAt).FirstOrDefault().CreatedAt : ""; info.LastMailsUpdate = db.TypeMails.Count(a => a.UpdatedAt != null) != 0 ? db.TypeMails.OrderByDescending(a => a.UpdatedAt).FirstOrDefault().UpdatedAt : ""; int HightMailUsingC = db.Documents.Count() == 0 ? 0 : db.Documents.Include(a => a.TypeMail).GroupBy(a => a.TypeMail.Name) .Select(a => new { key = a.Key, count = a.Count() }).OrderByDescending(a => a.count).FirstOrDefault().count; if (HightMailUsingC != 0) { List <string> MName = new List <string>(); MName = db.Documents.Include(a => a.TypeMail).GroupBy(a => a.TypeMail.Name) .Select(a => new { key = a.Key, count = a.Count() }).Where(a => a.count == HightMailUsingC).Select(a => a.key).ToList(); info.HightMailUsing = MName.Aggregate((a, b) => a + "," + b); } else { info.HightMailUsing = ""; } //Document Kind: info.TotalDocumentKindCount = db.Kinds.Count(); info.LastDocumentKindCreate = db.Kinds.Count() != 0 ? db.Kinds.OrderByDescending(a => a.CreatedAt).FirstOrDefault().CreatedAt : ""; info.LastDocumentKindUpdate = db.Kinds.Count(a => a.UpdatedAt != null) != 0 ? db.Kinds.OrderByDescending(a => a.UpdatedAt).FirstOrDefault().UpdatedAt : ""; int HightDocumentKindUsingC = db.Documents.Include(a => a.Kind).Count(a => a.Kind != null) == 0 ? 0 : db.Documents.Include(a => a.Kind).GroupBy(a => a.Kind.Name) .Select(a => new { key = a.Key, count = a.Count() }).OrderByDescending(a => a.count).FirstOrDefault().count; if (HightDocumentKindUsingC != 0) { List <string> MName = new List <string>(); MName = db.Documents.Include(a => a.Kind).GroupBy(a => a.Kind.Name) .Select(a => new { key = a.Key, count = a.Count() }).Where(a => a.count == HightDocumentKindUsingC).Select(a => a.key).ToList(); info.HightDocumentKindUsing = MName.Aggregate((a, b) => a + "," + b); } else { info.HightDocumentKindUsing = ""; } } else { info.IsMasterRole = false; } //CurrentUser Informations: info.FullName = db.Users.Find(CurrentUserId).FullName; info.UserName = db.Users.Find(CurrentUserId).UserName; info.Email = db.Users.Find(CurrentUserId).Email == null ? "" : db.Users.Find(CurrentUserId).Email; info.Gender = db.Users.Find(CurrentUserId).Gender; int DepId = db.Users.Include(a => a.Department).SingleOrDefault(a => a.Id.Equals(CurrentUserId)).DepartmentId == null ? 0 : db.Users.Include(a => a.Department).SingleOrDefault(a => a.Id.Equals(CurrentUserId)).Department.Id; info.DepartmentName = DepId == 0 ? "" : DepartmentListDisplay.CreateDepartmentDisplay(DepId); info.JobTitle = db.Users.Include(a => a.jobTitle).SingleOrDefault(a => a.Id.Equals(CurrentUserId)).JobTitleId == null ? "" : db.Users.Include(a => a.jobTitle).SingleOrDefault(a => a.Id.Equals(CurrentUserId)).jobTitle.Name; info.UserCreateAt = db.Users.Find(CurrentUserId).CreatedAt; info.UserUpdate = db.Users.Find(CurrentUserId).UpdatedAt == null ? "" : db.Users.Find(CurrentUserId).UpdatedAt; info.RoleName = db.Users.Find(CurrentUserId).RoleName; //User Groups if (!db.Users.Find(CurrentUserId).RoleName.Equals("Master")) { info.IsMasterRole = false; GroupsUserInformation groupsUserInformation = null; info.UserGroups = new List <GroupsUserInformation>(); List <UserGroup> UserG = db.UsersGroups.Include(a => a.Group).Where(a => a.UserId.Equals(CurrentUserId)).ToList(); foreach (UserGroup u in UserG) { groupsUserInformation = new GroupsUserInformation(); groupsUserInformation.Name = u.Group.Name; groupsUserInformation.UsersCount = db.UsersGroups.Where(a => a.GroupId == u.GroupId).Count(); info.UserGroups.Add(groupsUserInformation); } } else { info.IsMasterRole = true; } //User Favorite Form: if (!db.Users.Find(CurrentUserId).RoleName.Equals("Master")) { info.IsMasterRole = false; List <int> FavoriteFormId = db.FavouriteForms.Where(a => a.UserId.Equals(CurrentUserId)).Select(a => a.FormId).ToList();; info.FavoriteForm = new List <Form>(); info.FavoriteForm = db.Forms.Where(a => FavoriteFormId.Contains(a.Id)).ToList(); } else { info.IsMasterRole = true; } //User Basic Information: info.MyTotalDocument = db.Documents.Where(a => a.CreatedById.Equals(CurrentUserId)).Count(); if (!db.Users.Find(CurrentUserId).RoleName.Equals("Master")) { info.MyGroupsCount = db.UsersGroups.Where(a => a.UserId.Equals(CurrentUserId)).Count(); info.LastMyDocumentCreate = db.Documents.Where(a => a.CreatedById.Equals(CurrentUserId)).Count() != 0 ? (ManagedAes.CipherData? ManagedAes.DecryptText(db.Documents .Where(a => a.CreatedById.Equals(CurrentUserId)) .OrderByDescending(a => a.CreatedAt).FirstOrDefault().CreatedAt) : db.Documents.Where(a => a.CreatedById.Equals(CurrentUserId)) .OrderByDescending(a => a.CreatedAt).FirstOrDefault().CreatedAt) : "0/0/0"; info.DepartmentsCount = db.Departments.Count(); } info.Company = db.Company.Find(1); return(View(info)); }
public ActionResult Create(int DocumentIdValue, List <int> Groups) { ViewBag.Current = "Document"; List <string> UsersId = new List <string>(); string NotificationTime = string.Empty; string UserId = User.Identity.GetUserId(); Document doc = db.Documents.Find(DocumentIdValue); if (Groups == null) { return(RedirectToAction("Index", new { @id = DocumentIdValue, @msg = "CreateError" })); } if (ModelState.IsValid) { DocumentGroup documentGroup = null; foreach (int i in Groups) { documentGroup = new DocumentGroup() { GroupId = i, DocumentId = DocumentIdValue, EnableEdit = true, EnableReplay = true, EnableSeal = true, EnableRelate = true, CreatedAt = DateTime.Now.ToString("dd/MM/yyyy-HH:mm:ss"), CreatedById = this.User.Identity.GetUserId() }; db.DocumentGroups.Add(documentGroup); NotificationTime = DateTime.Now.ToString("dd/MM/yyyy-HH:mm:ss"); UsersId = db.UsersGroups.Where(a => a.GroupId == i).Select(a => a.UserId).ToList(); string GroupName = db.Groups.Find(i).Name; Notification notification = null; List <ApplicationUser> Users = db.Users.Where(a => UsersId.Contains(a.Id)).ToList(); foreach (ApplicationUser user in Users) { notification = new Notification() { CreatedAt = NotificationTime, Active = false, UserId = user.Id, Message = "تم إضافة وثيقة جديدة للمجموعة :" + GroupName + "، رقم الوثيقة :" + (ManagedAes.CipherData ? ManagedAes.DecryptText(doc.DocumentNumber) : doc.DocumentNumber) + " موضوع الوثيقة :" + (ManagedAes.CipherData ? ManagedAes.DecryptText(doc.Subject) : doc.Subject) + " ،عنوان الوثيقة :" + (ManagedAes.CipherData ? ManagedAes.DecryptText(doc.Address) : doc.Address) + "،وصف الوثيقة :" + (ManagedAes.CipherData ? ManagedAes.DecryptText(doc.Description) : doc.Description) , NotificationOwnerId = UserId }; db.Notifications.Add(notification); } db.SaveChanges(); } return(RedirectToAction("Index", new { @id = DocumentIdValue, @msg = "CreateSuccess" })); } return(RedirectToAction("Index", new { @id = DocumentIdValue })); }
public ActionResult Create(SealDocument Seal, IEnumerable <HttpPostedFileBase> SealFiles) { if (SealFiles != null) { foreach (var file in SealFiles) { if (!CheckFileFormatting.PermissionFile(file)) { ModelState.AddModelError("File", "صيغة الملف غير مدعومة!"); } } } if (ModelState.IsValid) { Seal.CreatedAt = DateTime.Now.ToString("dd/MM/yyyy-HH:mm:ss"); Seal.CreatedById = User.Identity.GetUserId(); // Encrypt Document Attributes. if (ManagedAes.IsCipher) { Seal.CreatedAt = ManagedAes.EncryptText(Seal.CreatedAt); Seal.Message = ManagedAes.EncryptText(Seal.Message); } _context.SealDocuments.Add(Seal); _context.SaveChanges(); if (ManagedAes.IsSaveInDb) { // start code get image from scanner, save it in database. var scannedImages = Request.Form.GetValues("myfile"); if (scannedImages != null) { int i = 0; foreach (var ImgStr in scannedImages) { i++; var sealFiles = new SealFiles(); sealFiles.SealId = Seal.Id; string imageName = "scannedImage" + i + ".jpg"; var imgAsByteArray = ManagedAes.DecodeUrlBase64(ImgStr); if (ManagedAes.IsCipher) { // Encrypt File Name. sealFiles.FileName = ManagedAes.EncryptText(imageName); // Encrypt File. var EncryptedImgAsByteArray = ManagedAes.EncryptArrayByte(imgAsByteArray); sealFiles.File = new byte[EncryptedImgAsByteArray.Length]; sealFiles.File = EncryptedImgAsByteArray; } else { // File Name. sealFiles.FileName = imageName; // File. sealFiles.File = new byte[imgAsByteArray.Length]; sealFiles.File = imgAsByteArray; } _context.SealFiles.Add(sealFiles); _context.SaveChanges(); } } // .// end code // get image from scanner, save it in server. foreach (HttpPostedFileBase file in SealFiles) { if (file != null) { var sealFiles = new SealFiles(); sealFiles.SealId = Seal.Id; string FileName = Path.GetFileName(file.FileName); sealFiles.FileName = FileName; sealFiles.File = new byte[file.ContentLength]; file.InputStream.Read(sealFiles.File, 0, file.ContentLength); if (ManagedAes.IsCipher) { // Encrypt File Name. sealFiles.FileName = ManagedAes.EncryptText(FileName); // Encrypt File. sealFiles.File = ManagedAes.EncryptArrayByte(sealFiles.File); } _context.SealFiles.Add(sealFiles); _context.SaveChanges(); } } } else { // start code get image from scanner, save it in server var scannedImages = Request.Form.GetValues("myfile"); if (scannedImages != null) { int i = 0; foreach (var ImgStr in scannedImages) { i++; String path = Server.MapPath("~/Uploads"); //Path //Check if directory exist if (!System.IO.Directory.Exists(path)) { System.IO.Directory.CreateDirectory(path); //Create directory if it doesn't exist } string imageName = "scannedImage" + i + ".jpg"; string s1 = DateTime.Now.ToString("yyyyMMddhhHHmmss") + imageName; //set the image path string imgPath = Path.Combine(path, imageName); byte[] imageBytes = ManagedAes.DecodeUrlBase64(ImgStr); var sealFiles = new SealFiles(); sealFiles.SealId = Seal.Id; if (ManagedAes.IsCipher) { ManagedAes.EncryptFile(imageBytes, imgPath); imageName = ManagedAes.EncryptText(imageName); s1 = ManagedAes.EncryptText(s1); } else { System.IO.File.WriteAllBytes(imgPath, imageBytes); } sealFiles.FileName = imageName; sealFiles.FileUrl = s1; _context.SealFiles.Add(sealFiles); _context.SaveChanges(); } } // .// end code // get image from scanner, save it in server. foreach (var file in SealFiles) { if (file != null) { var sealFiles = new SealFiles(); sealFiles.SealId = Seal.Id; //Save File In Uploads string FileName = Path.GetFileName(file.FileName); string s1 = DateTime.Now.ToString("yyyyMMddhhHHmmss") + FileName; string path = Path.Combine(Server.MapPath("~/Uploads"), s1); if (ManagedAes.IsCipher) { ManagedAes.EncryptFile(file, path); FileName = ManagedAes.EncryptText(FileName); s1 = ManagedAes.EncryptText(s1); } else { file.SaveAs(path); } sealFiles.FileName = FileName; sealFiles.FileUrl = s1; _context.SealFiles.Add(sealFiles); _context.SaveChanges(); } } } return(RedirectToAction("Index", new { id = Seal.DocumentId })); } return(View(Seal)); }
public ActionResult ActiveNOnActiveConfirmRelate(int id) { ViewBag.Current = "Document"; string ActiveMode = string.Empty; List <string> UsersId = new List <string>(); string NotificationTime = string.Empty; string UserId = User.Identity.GetUserId(); Document doc = db.DocumentGroups.Include(a => a.document).SingleOrDefault(a => a.Id == id).document; DocumentGroup documentGroup = db.DocumentGroups.Find(id); if (documentGroup.EnableRelate == true) { documentGroup.EnableRelate = false; ActiveMode = "الغاء إمكانية الربط"; } else { documentGroup.EnableRelate = true; ActiveMode = "تفعيل إمكانية الربط"; } documentGroup.UpdatedAt = DateTime.Now.ToString("dd/MM/yyyy-HH:mm:ss"); db.Entry(documentGroup).State = EntityState.Modified; db.SaveChanges(); int Form_id = documentGroup.DocumentId; UsersId = db.UsersGroups.Where(a => a.GroupId == documentGroup.GroupId).Select(a => a.UserId).ToList(); string GroupName = db.Groups.Find(documentGroup.GroupId).Name; Notification notification = null; NotificationTime = DateTime.Now.ToString("dd/MM/yyyy-HH:mm:ss"); List <ApplicationUser> Users = db.Users.Where(a => UsersId.Contains(a.Id)).ToList(); foreach (ApplicationUser user in Users) { notification = new Notification() { CreatedAt = NotificationTime, Active = false, UserId = user.Id, Message = "تمت عملية " + ActiveMode + " في المجموعة " + GroupName + " رقم الوثيقة :" + (ManagedAes.CipherData ? ManagedAes.DecryptText(doc.DocumentNumber) : doc.DocumentNumber) + " موضوع الوثيقة :" + (ManagedAes.CipherData ? ManagedAes.DecryptText(doc.Subject) : doc.Subject) + " ،عنوان الوثيقة :" + (ManagedAes.CipherData ? ManagedAes.DecryptText(doc.Address) : doc.Address) + "،وصف الوثيقة :" + (ManagedAes.CipherData ? ManagedAes.DecryptText(doc.Description) : doc.Description) , NotificationOwnerId = UserId }; db.Notifications.Add(notification); } db.SaveChanges(); return(RedirectToAction("Index", new { @id = Form_id, @msg = "EditSuccess" })); }
public FileResult DisplayDocument(int?id) { var SealFiles = _context.SealFiles.Find(id); var fileName = SealFiles.FileName; if (!ManagedAes.IsSaveInDb) { if (ManagedAes.IsCipher) { SealFiles.FileUrl = ManagedAes.DecryptText(SealFiles.FileUrl); fileName = ManagedAes.DecryptText(fileName); } string filePath = Server.MapPath("~/Uploads/").Replace(@"\", "/") + SealFiles.FileUrl; if (ManagedAes.IsCipher) { var file = ManagedAes.DecryptFile(filePath); MemoryStream memStream = new MemoryStream(); BinaryFormatter binForm = new BinaryFormatter(); memStream.Write(file, 0, file.Length); memStream.Seek(0, SeekOrigin.Begin); // Images if (filePath.EndsWith("jpeg") || filePath.EndsWith("JPEG")) { return(new FileStreamResult(memStream, "image/jpeg")); } if (filePath.EndsWith("jpg") || filePath.EndsWith("JPG")) { return(new FileStreamResult(memStream, "image/jpg")); } if (filePath.EndsWith("png") || filePath.EndsWith("PNG")) { return(new FileStreamResult(memStream, "image/png")); } if (filePath.EndsWith("gif") || filePath.EndsWith("GIF")) { return(new FileStreamResult(memStream, "image/gif")); } // Files if (filePath.EndsWith("pdf") || filePath.EndsWith("PDF")) { return(new FileStreamResult(memStream, "application/pdf")); } if (filePath.EndsWith("doc") || filePath.EndsWith("DOC") || filePath.EndsWith("docx") || filePath.EndsWith("DOCX") || filePath.EndsWith("xlsx") || filePath.EndsWith("XLSX") || filePath.EndsWith("pptx") || filePath.EndsWith("PPTX")) { return(new FileStreamResult(memStream, "application/vnd.openxmlformats-officedocument.wordprocessingml.document")); } } var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read); // Images if (filePath.EndsWith("jpeg") || filePath.EndsWith("JPEG")) { return(new FileStreamResult(fileStream, "image/jpeg")); } if (filePath.EndsWith("jpg") || filePath.EndsWith("JPG")) { return(new FileStreamResult(fileStream, "image/jpg")); } if (filePath.EndsWith("png") || filePath.EndsWith("PNG")) { return(new FileStreamResult(fileStream, "image/png")); } if (filePath.EndsWith("gif") || filePath.EndsWith("GIF")) { return(new FileStreamResult(fileStream, "image/gif")); } // Files if (filePath.EndsWith("pdf") || filePath.EndsWith("PDF")) { return(new FileStreamResult(fileStream, "application/pdf")); } if (filePath.EndsWith("doc") || filePath.EndsWith("DOC") || filePath.EndsWith("docx") || filePath.EndsWith("DOCX") || filePath.EndsWith("xlsx") || filePath.EndsWith("XLSX") || filePath.EndsWith("pptx") || filePath.EndsWith("PPTX")) { return(new FileStreamResult(fileStream, "application/vnd.openxmlformats-officedocument.wordprocessingml.document")); } } else { var file = SealFiles.File; if (ManagedAes.IsCipher) { fileName = ManagedAes.DecryptText(SealFiles.FileName); file = ManagedAes.DecryptArrayByte(file); } // Images if (fileName.EndsWith("jpeg") || fileName.EndsWith("JPEG")) { return(File(file, "image/jpeg")); } if (fileName.EndsWith("jpg") || fileName.EndsWith("JPG")) { return(File(file, "image/jpg")); } if (fileName.EndsWith("png") || fileName.EndsWith("PNG")) { return(File(file, "image/png")); } if (fileName.EndsWith("gif") || fileName.EndsWith("GIF")) { return(File(file, "image/gif")); } // Pdf if (fileName.EndsWith("pdf") || fileName.EndsWith("PDF")) { return(File(file, "application/pdf")); } } return(DownloadDocument(id)); }
public ActionResult Create(int DocumentIdValue, List <string> Users) { ViewBag.Current = "Document"; string NotificationTime = string.Empty; string UserId = User.Identity.GetUserId(); Document doc = db.Documents.Find(DocumentIdValue); if (Users == null) { return(RedirectToAction("Index", new { @id = DocumentIdValue, @msg = "CreateError" })); } if (ModelState.IsValid) { DocumentUser documentUser = null; foreach (string i in Users) { documentUser = new DocumentUser() { UserId = i, DocumentId = DocumentIdValue, EnableEdit = true, EnableSeal = true, EnableReplay = true, EnableRelate = true, CreatedAt = DateTime.Now.ToString("dd/MM/yyyy-HH:mm:ss"), CreatedById = this.User.Identity.GetUserId() }; db.DocumentUsers.Add(documentUser); NotificationTime = DateTime.Now.ToString("dd/MM/yyyy-HH:mm:ss"); Notification notification = null; notification = new Notification() { CreatedAt = NotificationTime, Active = false, UserId = i, Message = "تم إضافة وثيقة جديدة :" + "" + "، رقم الوثيقة :" + (ManagedAes.CipherData ? ManagedAes.DecryptText(doc.DocumentNumber) : doc.DocumentNumber) + " موضوع الوثيقة :" + (ManagedAes.CipherData ? ManagedAes.DecryptText(doc.Subject) : doc.Subject) + " ،عنوان الوثيقة :" + (ManagedAes.CipherData ? ManagedAes.DecryptText(doc.Address) : doc.Address) + "،وصف الوثيقة :" + (ManagedAes.CipherData ? ManagedAes.DecryptText(doc.Description) : doc.Description) , NotificationOwnerId = UserId }; db.Notifications.Add(notification); } db.SaveChanges(); return(RedirectToAction("Index", new { @id = DocumentIdValue, @msg = "CreateSuccess" })); } return(RedirectToAction("Index", new { @id = DocumentIdValue })); }