public async Task <IActionResult> OnGetAsync([FromServices] UserManager <CitizenUser> userMgr) { Authority = User.Identity.Name; ILevelDbContext levelDbContext = null; if (User.IsInRole("ѕерв”ровень")) { levelDbContext = HttpContext.RequestServices.GetService(typeof(FirstLevelDbContext)) as ILevelDbContext; } else if (User.IsInRole("—ред”ровень")) { levelDbContext = HttpContext.RequestServices.GetService(typeof(MidLevelDbContext)) as ILevelDbContext; } else if (User.IsInRole("“оп”ровень")) { levelDbContext = HttpContext.RequestServices.GetService(typeof(TopLevelDbContext)) as ILevelDbContext; } if (levelDbContext == null) { return(RedirectToPage("Error")); } OpenBlocks = await Task.Run(() => levelDbContext.Blocks.Where(block => block.To == Authority && block.Type == BlockType.Open && levelDbContext.Blocks.Where(bl => bl.DocId == block.DocId).Count() == 1).ToArray()); Employees = await Task.Run(() => userMgr.Users.Where(user => user.Dispatcher == User.Identity.Name).ToArray()); return(Page()); }
public async Task <IActionResult> OnPostRedirectBlockAsync([FromServices] UserLevelDbContext userDbContex, string blockId, ushort authorityLevel, string to, string authorityType) { Block block = await userDbContex.Blocks.FindAsync(blockId); Block newBlock = new Block(); newBlock.AuthorityType = authorityType; newBlock.DocId = Guid.NewGuid().ToString(); newBlock.From = User.Identity.Name; newBlock.To = to; newBlock.Type = BlockType.Open; newBlock.City = block.City; newBlock.PreviousHash = block.Hash; newBlock.Document = block.Document; newBlock.Lock(); ILevelDbContext levelDbContext = null; switch (authorityLevel) { case 1: levelDbContext = HttpContext.RequestServices.GetService(typeof(FirstLevelDbContext)) as ILevelDbContext; break; case 2: levelDbContext = HttpContext.RequestServices.GetService(typeof(MidLevelDbContext)) as ILevelDbContext; break; case 3: levelDbContext = HttpContext.RequestServices.GetService(typeof(TopLevelDbContext)) as ILevelDbContext; break; } await userDbContex.Blocks.AddAsync(newBlock); await userDbContex.SaveChangesAsync(); await levelDbContext.Blocks.AddAsync(newBlock); await((DbContext)levelDbContext).SaveChangesAsync(); newBlock = new Block(); newBlock.DocId = block.DocId; newBlock.isClosed = true; newBlock.From = User.Identity.Name; newBlock.To = User.Identity.Name; newBlock.Type = BlockType.Close; newBlock.PreviousHash = block.Hash; newBlock.City = block.City; newBlock.AuthorityType = block.AuthorityType; newBlock.Document = block.Document; newBlock.Lock(); await userDbContex.Blocks.AddAsync(newBlock); await userDbContex.SaveChangesAsync(); return(RedirectToPage("Active")); }
public async Task <IActionResult> OnPostAssignAsync([FromServices] UserManager <CitizenUser> userMgr, string userName, string blockId) { ILevelDbContext levelDbContext = null; if (User.IsInRole("ѕерв”ровень")) { levelDbContext = HttpContext.RequestServices.GetService(typeof(FirstLevelDbContext)) as ILevelDbContext; } else if (User.IsInRole("—ред”ровень")) { levelDbContext = HttpContext.RequestServices.GetService(typeof(MidLevelDbContext)) as ILevelDbContext; } else if (User.IsInRole("“оп”ровень")) { levelDbContext = HttpContext.RequestServices.GetService(typeof(TopLevelDbContext)) as ILevelDbContext; } if (levelDbContext == null) { return(RedirectToPage("Error")); } Block block = await levelDbContext.Blocks.FindAsync(blockId); Block newBlock = new Block(); newBlock.From = block.From; newBlock.To = userName; newBlock.AuthorityType = block.AuthorityType; newBlock.DocId = block.DocId; newBlock.Document = block.Document; newBlock.City = block.City; newBlock.Replies = block.Replies; newBlock.Type = BlockType.Accept; var accept = new Accept { AgentFullName = userName, Position = userMgr.Users.Where(u => u.UserName == userName).Select(n => n.Position).FirstOrDefault() }; newBlock.TypeMessage = Newtonsoft.Json.JsonConvert.SerializeObject(accept); newBlock.PreviousHash = block.Hash; newBlock.Lock(); levelDbContext.Blocks.Add(newBlock); await((DbContext)levelDbContext).SaveChangesAsync(); UserLevelDbContext userDbContext = HttpContext.RequestServices.GetService(typeof(UserLevelDbContext)) as UserLevelDbContext; userDbContext.Blocks.Add(newBlock); await userDbContext.SaveChangesAsync(); return(RedirectToPage("Dispatcher")); }
public async Task <IActionResult> OnPostRedirectAsync(string city, string authorityType, string blockId, string comment) { ILevelDbContext levelDbContext = null; if (User.IsInRole("ѕерв”ровень")) { levelDbContext = HttpContext.RequestServices.GetService(typeof(FirstLevelDbContext)) as ILevelDbContext; } else if (User.IsInRole("—ред”ровень")) { levelDbContext = HttpContext.RequestServices.GetService(typeof(MidLevelDbContext)) as ILevelDbContext; } else if (User.IsInRole("“оп”ровень")) { levelDbContext = HttpContext.RequestServices.GetService(typeof(TopLevelDbContext)) as ILevelDbContext; } if (levelDbContext == null) { return(RedirectToPage("Error")); } Block block = await levelDbContext.Blocks.FindAsync(blockId); Authority authority = Models.Authority.Cities[city][authorityType][0]; Block newBlock = new Block(); newBlock.From = User.Identity.Name; newBlock.To = block.From; newBlock.DocId = block.DocId; newBlock.City = block.City; newBlock.Document = block.Document; newBlock.AuthorityType = block.AuthorityType; newBlock.Type = BlockType.Redirect; newBlock.TypeMessage = Newtonsoft.Json.JsonConvert.SerializeObject(new Redirect { AuthorityLevel = authority.Level, AuthorityType = authorityType, To = authority.Name, Comment = comment }); newBlock.PreviousHash = block.Hash; newBlock.Lock(); levelDbContext.Blocks.Add(newBlock); await((DbContext)levelDbContext).SaveChangesAsync(); UserLevelDbContext userLevelDb = HttpContext.RequestServices.GetService(typeof(UserLevelDbContext)) as UserLevelDbContext; userLevelDb.Blocks.Add(newBlock); await userLevelDb.SaveChangesAsync(); return(RedirectToPage("Dispatcher")); }
public void OnGet() { Header = User.Identity.Name; ILevelDbContext levelDbContext = null; if (User.IsInRole("ѕерв”ровень")) { levelDbContext = HttpContext.RequestServices.GetService(typeof(FirstLevelDbContext)) as ILevelDbContext; } else if (User.IsInRole("—ред”ровень")) { levelDbContext = HttpContext.RequestServices.GetService(typeof(MidLevelDbContext)) as ILevelDbContext; } else if (User.IsInRole("“оп”ровень")) { levelDbContext = HttpContext.RequestServices.GetService(typeof(TopLevelDbContext)) as ILevelDbContext; } OpenBlocks = levelDbContext.Blocks.Where(block => block.To == User.Identity.Name && block.Type == BlockType.Accept && !levelDbContext.Blocks.Any(ab => ab.DocId == block.DocId && ab.Type == BlockType.Close)).ToList(); string authType = OpenBlocks.Select(s => s.AuthorityType).FirstOrDefault(); if (authType != null) { var _list = levelDbContext.Blocks.Where(block => block.Type == BlockType.Close && block.AuthorityType == authType).AsEnumerable(); if (_list != null) { Dictionary <string, string> dict = new Dictionary <string, string>(); foreach (var item in _list) { var text = ((Document)Newtonsoft.Json.JsonConvert.DeserializeObject(item.Document, typeof(Document))).Text; dict.Add(item.Id, text); } if (dict.Count() > 0) { for (int i = 0; i < OpenBlocks.Count(); i++) { var result = TemplatesFinder.FindTemplates(((Document)Newtonsoft.Json.JsonConvert.DeserializeObject(OpenBlocks[i].Document, typeof(Document))).Text, dict); Reply[] repl = ((Reply[])Newtonsoft.Json.JsonConvert.DeserializeObject(_list.Where(t => t.Id == result[0]).FirstOrDefault().Replies, typeof(Reply[]))); TemplateList.Add(repl[0].Body); } } } } }
public async Task <IActionResult> OnPostCloseAsync(string blockId, string reply, string comment) { ILevelDbContext levelDbContext = null; if (User.IsInRole("ѕерв”ровень")) { levelDbContext = HttpContext.RequestServices.GetService(typeof(FirstLevelDbContext)) as ILevelDbContext; } else if (User.IsInRole("—ред”ровень")) { levelDbContext = HttpContext.RequestServices.GetService(typeof(MidLevelDbContext)) as ILevelDbContext; } else if (User.IsInRole("“оп”ровень")) { levelDbContext = HttpContext.RequestServices.GetService(typeof(TopLevelDbContext)) as ILevelDbContext; } if (levelDbContext == null) { return(RedirectToPage("Error")); } Block block = await levelDbContext.Blocks.FindAsync(blockId); Block newBlock = new Block(); newBlock.From = User.Identity.Name; newBlock.To = block.From; newBlock.DocId = block.DocId; newBlock.Document = block.Document; newBlock.City = block.City; newBlock.AuthorityType = block.AuthorityType; Document doc = (Document)Newtonsoft.Json.JsonConvert.DeserializeObject(block.Document, typeof(Document)); Reply[] replies; if (string.IsNullOrEmpty(block.Replies)) { replies = new Reply[] { new Reply { From = User.Identity.Name, Body = reply, Comment = comment, To = doc.From } }; } else { replies = (Reply[])Newtonsoft.Json.JsonConvert.DeserializeObject(block.Replies, typeof(Reply[])); List <Reply> listReplies = new List <Reply>(replies); listReplies.Add(new Reply { From = User.Identity.Name, Body = reply, Comment = comment, To = doc.From }); replies = listReplies.ToArray(); } newBlock.Replies = Newtonsoft.Json.JsonConvert.SerializeObject(replies); newBlock.Type = BlockType.Close; newBlock.PreviousHash = block.Hash; newBlock.Lock(); UserLevelDbContext userDbContext = HttpContext.RequestServices.GetService(typeof(UserLevelDbContext)) as UserLevelDbContext; levelDbContext.Blocks.Add(newBlock); await((DbContext)levelDbContext).SaveChangesAsync(); userDbContext.Blocks.Add(newBlock); await userDbContext.SaveChangesAsync(); return(RedirectToPage("Dispatcher")); }
public async Task <IActionResult> OnPostAsync([FromServices] UserLevelDbContext userDbContext, [FromServices] UserManager <CitizenUser> userMgr, string blockId, string reply, string comment) { var user = userMgr.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); Block block = await userDbContext.Blocks.FindAsync(blockId); Reply _reply = new Reply { AgentFullName = User.Identity.Name, Body = reply, Comment = comment, From = user.UserName, Position = user.Position, To = block.From }; Block newBlock = new Block(); newBlock.AuthorityType = block.AuthorityType; newBlock.City = block.City; newBlock.DocId = block.DocId; newBlock.Document = block.Document; newBlock.From = User.Identity.Name; newBlock.PreviousHash = block.Hash; if (string.IsNullOrEmpty(block.Replies)) { Reply[] replies = new Reply[] { _reply }; newBlock.Replies = Newtonsoft.Json.JsonConvert.SerializeObject(replies); } else { List <Reply> list = new List <Reply>((Reply[])Newtonsoft.Json.JsonConvert.DeserializeObject(block.Replies, typeof(Reply[]))); list.Add(_reply); newBlock.Replies = Newtonsoft.Json.JsonConvert.SerializeObject(list.ToArray()); } newBlock.To = block.From; newBlock.Type = BlockType.Close; newBlock.Lock(); ILevelDbContext levelDbContext = null; if (User.IsInRole("ѕерв”ровень")) { levelDbContext = HttpContext.RequestServices.GetService(typeof(FirstLevelDbContext)) as ILevelDbContext; } else if (User.IsInRole("—ред”ровень")) { levelDbContext = HttpContext.RequestServices.GetService(typeof(MidLevelDbContext)) as ILevelDbContext; } else if (User.IsInRole("“оп”ровень")) { levelDbContext = HttpContext.RequestServices.GetService(typeof(TopLevelDbContext)) as ILevelDbContext; } if (levelDbContext == null) { return(RedirectToPage("Error")); } await levelDbContext.Blocks.AddAsync(newBlock); await((DbContext)levelDbContext).SaveChangesAsync(); await userDbContext.Blocks.AddAsync(newBlock); await userDbContext.SaveChangesAsync(); return(RedirectToPage("Agent")); }
public async Task <IActionResult> OnPostAppealAsync([FromServices] UserLevelDbContext userDbContex, string blockId) { Block block = await userDbContex.Blocks.FindAsync(blockId); if (string.IsNullOrEmpty(block.Replies)) { return(RedirectToPage("Error")); } Reply[] replies = (Reply[])Newtonsoft.Json.JsonConvert.DeserializeObject(block.Replies, typeof(Reply[])); Authority authority = null; try { authority = Authority.Cities[block.City][block.AuthorityType][replies.Length]; } catch { } Block newBlock = new Block(); newBlock.DocId = block.DocId; newBlock.isClosed = true; newBlock.From = User.Identity.Name; newBlock.To = User.Identity.Name; newBlock.Type = BlockType.Close; newBlock.City = block.City; newBlock.PreviousHash = block.Hash; newBlock.AuthorityType = block.AuthorityType; newBlock.Document = block.Document; newBlock.Lock(); await userDbContex.Blocks.AddAsync(newBlock); await userDbContex.SaveChangesAsync(); if (authority != null) { var newBlock2 = new Block(); newBlock2.AuthorityType = block.AuthorityType; newBlock2.City = block.City; newBlock2.DocId = Guid.NewGuid().ToString(); newBlock2.Document = block.Document; newBlock2.From = User.Identity.Name; newBlock2.PreviousHash = newBlock.Hash; newBlock2.Replies = block.Replies; newBlock2.To = authority.Name; newBlock2.Type = BlockType.Open; newBlock2.Lock(); ILevelDbContext levelDbContext = null; switch (authority.Level) { case 1: levelDbContext = HttpContext.RequestServices.GetService(typeof(FirstLevelDbContext)) as ILevelDbContext; break; case 2: levelDbContext = HttpContext.RequestServices.GetService(typeof(MidLevelDbContext)) as ILevelDbContext; break; case 3: levelDbContext = HttpContext.RequestServices.GetService(typeof(TopLevelDbContext)) as ILevelDbContext; break; } if (levelDbContext == null) { return(RedirectToPage("Error")); } await userDbContex.Blocks.AddAsync(newBlock2); await userDbContex.SaveChangesAsync(); await levelDbContext.Blocks.AddAsync(newBlock2); await((DbContext)levelDbContext).SaveChangesAsync(); } return(RedirectToPage("Active")); }