private List <IdentityRole> UserRoles(List <IdentityUserRole> identityUserRoles) { using (var context = new DBContextWFManagementSystem()) { var allRoles = context.Roles.ToList(); var roles = allRoles.Where(role => identityUserRoles.Any(iur => iur.RoleId == role.Id)).ToList(); return(roles); } }
public List <BlockType> GetAll() { using (var dbContext = new DBContextWFManagementSystem()) { var res = dbContext.BlockTypes .ToList(); return(res); } }
public List <Workflow> GetAll() { using (var dbContext = new DBContextWFManagementSystem()) { var res = dbContext.Workflows .Where(x => x.IsActual == true) .ToList(); return(res); } }
public List <Workflow> GetAllByUser(string userId) { using (var dbContext = new DBContextWFManagementSystem()) { var res = dbContext.Workflows .Where(x => x.UserCreated.Id == userId) .Where(x => x.IsActual == true) .ToList(); return(res); } }
public Workflow GetById(int id) { using (var dbContext = new DBContextWFManagementSystem()) { var res = dbContext.Workflows .Include(x => x.Blocks.Select(y => y.BlockType)) .Include(x => x.Blocks.Select(y => y.NextBlocks)) .FirstOrDefault(x => x.ID == id); return(res); } }
public async System.Threading.Tasks.Task <ActionResult> Edit(string id) { var user = await UserManager.FindByIdAsync(id); ViewBag.User = user; List <IdentityRole> userRoles; using (var context = new DBContextWFManagementSystem()) { userRoles = context.Roles.ToList(); } ViewBag.UserRoles = new SelectList(userRoles, "Id", "Name", userRoles.FirstOrDefault(role => role.Id == user.Roles.First().RoleId).Id); return(View()); }
public Block Insert(Block block) { try { using (var dbContext = new DBContextWFManagementSystem()) { var res = dbContext.Blocks.Add(block); dbContext.SaveChanges(); return(res); } } catch (Exception e) { throw new Exception("Problem pridat block: {0}", e); } }
public Workflow Delete(int idWorkflow) { try { using (var dbContext = new DBContextWFManagementSystem()) { var temp = dbContext.Workflows.FirstOrDefault(x => x.ID == idWorkflow); if (temp != null) { temp.IsActual = false; } dbContext.SaveChanges(); return(temp); } } catch (Exception e) { throw new Exception("Problem odebrat workflow: {0}", e); } }
public Workflow Update(Workflow newWorkflow, int oldWorkflowId, string userId) { try { var workflowAdded = Insert(newWorkflow, userId); using (var dbContext = new DBContextWFManagementSystem()) { var temp = dbContext.Workflows.FirstOrDefault(x => x.ID == oldWorkflowId); if (temp != null) { temp.IsActual = false; } dbContext.SaveChanges(); return(workflowAdded); } } catch (Exception e) { throw new Exception("Problem upravit workflow: {0}", e); } }
public async System.Threading.Tasks.Task <ActionResult> Edit(string id, string oldPassword, ManageUsersViewModel model) { if (!ModelState.IsValid) { return(View(model)); } try { var user = await UserManager.FindByIdAsync(id); IdentityResult result = null; if (!user.Roles.Any(role => role.RoleId == model.UserRole)) { var currentRole = UserManager.GetRoles(id).ToList().First(); using (var context = new DBContextWFManagementSystem()) { var roleToAdd = context.Roles.FirstOrDefault(x => x.Id == model.UserRole).Name; result = await UserManager.AddToRoleAsync(id, roleToAdd); } var resultRemoveRole = UserManager.RemoveFromRole(id, currentRole); if (!result.Succeeded || !resultRemoveRole.Succeeded) { return(RedirectToAction("Index", new { Message = "Uživatel nebyl změnen: Problem s přiřazením role." })); } } if (model.NewPassword != null) { string resetToken = await UserManager.GeneratePasswordResetTokenAsync(id); result = await UserManager.ResetPasswordAsync(id, resetToken, model.NewPassword); if (result.Succeeded) { if (result.Succeeded) { user = await UserManager.FindByIdAsync(User.Identity.GetUserId()); if (user != null) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); } } else { return(RedirectToAction("Index", new { Message = "Uživatel nebyl změnen: Problém s přiřazením hesla." })); } } } if (result == null || result.Succeeded) { user = await UserManager.FindByIdAsync(id); user.Email = model.Email; user.UserName = model.Email; result = await UserManager.UpdateAsync(user); } if (result.Succeeded) { return(RedirectToAction("Index", new { Message = "Uživatel v pořádku změněn" })); } else { return(RedirectToAction("Index", new { Message = "Uživatel nebyl změnen: Problém s aktualizací uživatele." })); } } catch { return(View(model)); } }
public Workflow Insert(Workflow workflow, string userId) { try { using (var dbContext = new DBContextWFManagementSystem()) { var user = dbContext.Users.FirstOrDefault(x => x.Id == userId); workflow.UserCreated = user; //var tempWorkflow = new Workflow(); //tempWorkflow.DateTimeCreated = workflow.DateTimeCreated; //tempWorkflow.IsActual = workflow.IsActual; //tempWorkflow.Name = workflow.Name; //tempWorkflow.UserCreated = workflow.UserCreated; //dbContext.Workflows.Add(tempWorkflow); for (int i = workflow.Blocks.Count - 1; i > -1; i--) { var tracked = dbContext.ChangeTracker.Entries <BlockType>().Any(e => e.Entity.ID == workflow.Blocks[i].BlockType.ID); if (!tracked) { dbContext.BlockTypes.Attach(workflow.Blocks[i].BlockType); } else { var id = workflow.Blocks[i].BlockType.ID; workflow.Blocks[i].BlockType = dbContext.BlockTypes.FirstOrDefault(x => x.ID == id); } //foreach (var workflowBlockNextBlock in workflowBlock.NextBlocks) //{ // var tracked2 = dbContext.ChangeTracker.Entries<BlockType>().Any(e => e.Entity.ID == workflowBlockNextBlock.BlockType.ID); // if (!tracked2) // dbContext.BlockTypes.Attach(workflowBlockNextBlock.BlockType); // else // { // workflowBlockNextBlock.BlockType = // dbContext.BlockTypes.FirstOrDefault(x => x.ID == workflowBlockNextBlock.BlockType.ID); // } //} if (workflow.Blocks[i].NextBlocks.Count > 0) { for (int j = 0; j < workflow.Blocks[i].NextBlocks.Count; j++) { var trackedNextBlock = dbContext.ChangeTracker.Entries <Block>().Any(e => e.Entity.ID == workflow.Blocks[i].NextBlocks[j].ID); if (!trackedNextBlock) { dbContext.Blocks.Attach(workflow.Blocks[i].NextBlocks[j]); } else { var id = workflow.Blocks[i].NextBlocks[j].ID; workflow.Blocks[i].NextBlocks[j] = dbContext.Blocks.FirstOrDefault(x => x.ID == id); } } } var javascriptId = workflow.Blocks[i].ID; workflow.Blocks[i].ID = dbContext.Blocks.Add(workflow.Blocks[i]).ID; foreach (var block in workflow.Blocks) { if (block.NextBlocks.Count > 0) { for (int j = 0; j < block.NextBlocks.Count; j++) { if (block.NextBlocks[j].ID == javascriptId) { block.NextBlocks[j] = workflow.Blocks[i]; } } } } dbContext.SaveChanges(); } var res = dbContext.Workflows.Add(workflow); dbContext.SaveChanges(); return(res); } } catch (Exception e) { throw new Exception("Problem pridat workflow: {0}", e); } }