private void CreateHostRoleAndUsers() { //Admin role for host var adminRoleForHost = _context.Roles.FirstOrDefault(r => r.TenantId == null && r.Name == StaticRoleNames.Host.Admin); if (adminRoleForHost == null) { adminRoleForHost = _context.Roles.Add(new Role { Name = StaticRoleNames.Host.Admin, DisplayName = StaticRoleNames.Host.Admin, IsStatic = true }); _context.SaveChanges(); //Grant all tenant permissions var permissions = PermissionFinder .GetAllPermissions(new TaskManagerAuthorizationProvider()) .Where(p => p.MultiTenancySides.HasFlag(MultiTenancySides.Host)) .ToList(); foreach (var permission in permissions) { if (!permission.IsGrantedByDefault) { _context.Permissions.Add( new RolePermissionSetting { Name = permission.Name, IsGranted = true, RoleId = adminRoleForHost.Id }); } } _context.SaveChanges(); } //Admin user for tenancy host var adminUserForHost = _context.Users.FirstOrDefault(u => u.TenantId == null && u.UserName == User.AdminUserName); if (adminUserForHost == null) { adminUserForHost = _context.Users.Add( new User { UserName = User.AdminUserName, Name = "System", Surname = "Administrator", EmailAddress = "*****@*****.**", IsEmailConfirmed = true, Password = new PasswordHasher().HashPassword(User.DefaultPassword) }); _context.SaveChanges(); _context.UserRoles.Add(new UserRole(null, adminUserForHost.Id, adminRoleForHost.Id)); _context.SaveChanges(); } }
private void CreateRolesAndUsers() { //Admin role var adminRole = _context.Roles.FirstOrDefault(r => r.TenantId == _tenantId && r.Name == StaticRoleNames.Tenants.Admin); if (adminRole == null) { adminRole = new Role(_tenantId, StaticRoleNames.Tenants.Admin, StaticRoleNames.Tenants.Admin) { IsStatic = true }; adminRole.SetNormalizedName(); _context.Roles.Add(adminRole); _context.SaveChanges(); //Grant all permissions to admin role var permissions = PermissionFinder .GetAllPermissions(new TaskManagerAuthorizationProvider()) .Where(p => p.MultiTenancySides.HasFlag(MultiTenancySides.Tenant)) .ToList(); foreach (var permission in permissions) { _context.Permissions.Add( new RolePermissionSetting { TenantId = _tenantId, Name = permission.Name, IsGranted = true, RoleId = adminRole.Id }); } _context.SaveChanges(); } //admin user var adminUser = _context.Users.FirstOrDefault(u => u.TenantId == _tenantId && u.UserName == User.AdminUserName); if (adminUser == null) { adminUser = User.CreateTenantAdminUser(_tenantId, "*****@*****.**", User.DefaultPassword); adminUser.IsEmailConfirmed = true; adminUser.IsActive = true; _context.Users.Add(adminUser); _context.SaveChanges(); //Assign Admin role to admin user _context.UserRoles.Add(new UserRole(_tenantId, adminUser.Id, adminRole.Id)); _context.SaveChanges(); } }
public ActionResult Create([Bind(Include = "CustomerId,CompanyName,Phone,Address,Email")] Customer customer) { if (ModelState.IsValid) { db.Customer.Add(customer); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customer)); }
public ActionResult Create([Bind(Include = "ProjectId,CustomerDemandId,CustomerId,Demand,DemandType")] CustomerDemand customerDemand) { if (ModelState.IsValid) { db.CustomerDemand.Add(customerDemand); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ProjectId = new SelectList(db.Project, "ProjectId", "Name", customerDemand.ProjectId); return(View(customerDemand)); }
public ActionResult Create( [Bind(Include = "ProjectId,CustomerId,Name,Description,PlannedStartingDate,PlannedEndingDate,StartingDate,EndingDate")] Project project) { if (ModelState.IsValid) { db.Project.Add(project); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CustomerId = new SelectList(db.Customer, "CustomerId", "CompanyName", project.CustomerId); return(View(project)); }
public static void AddTasks(List <Task> tasks) { TaskManagerDbContext taskManagerDbContext = new TaskManagerDbContext(); taskManagerDbContext.Tasks.AddRange(tasks); taskManagerDbContext.SaveChanges(); }
public static void AddTask(Task task) { TaskManagerDbContext taskManagerDbContext = new TaskManagerDbContext(); taskManagerDbContext.Tasks.Add(task); taskManagerDbContext.SaveChanges(); }
public static void AddUsers(List <User> users) { TaskManagerDbContext taskManagerDbContext = new TaskManagerDbContext(); taskManagerDbContext.Users.AddRange(users); taskManagerDbContext.SaveChanges(); }
public async Task EnsureSeedData() { _context.Database.EnsureCreated(); _context.Tasks.RemoveRange(_context.Tasks); _context.SaveChanges(); var task = new TaskEntity { Title = "Read a book", TaskDetails = "Read Sadguru books" }; _context.Add(task); var task2 = new TaskEntity { Title = "Go to temple", TaskDetails = "Go to temple" }; _context.Add(task2); await _context.SaveChangesAsync(); }
private void TaskValidateButton_Click(object sender, EventArgs e) { if (ValidateInput()) { var ID = Guid.Empty; if (String.IsNullOrEmpty(TaskIDTextBox.Text)) { ID = Guid.NewGuid(); } else { ID = Guid.Parse(TaskIDTextBox.Text); } var newTask = new Models.Task { ID = ID, Description = TaskDescriptionTextBox.Text, DueDate = DueDateDateTimePicker.Value, StartDate = StartDateDateTimePicker.Value, TaskPriority = (TaskPriority)Enum.Parse(typeof(TaskPriority), TaskPriorityComboBox.Text), TaskState = (TaskState)Enum.Parse(typeof(TaskState), TaskStateComboBox.Text), Title = TaskTitleTextBox.Text, Comments = TaskCommentTextBox.Text, User = UserComboBox.Text }; context.Tasks.AddOrUpdate(newTask); TaskAdded.Invoke(this, null); context.SaveChanges(); } else { MessageBox.Show("Please verify your inputs!"); } }
public static void AddUser(User user) { TaskManagerDbContext taskManagerDbContext = new TaskManagerDbContext(); taskManagerDbContext.Users.Add(user); taskManagerDbContext.SaveChanges(); }
public static void DeleteUser(int userId) { TaskManagerDbContext taskManagerDbContext = new TaskManagerDbContext(); User user = taskManagerDbContext.Users.Find(userId); taskManagerDbContext.Users.Remove(user); taskManagerDbContext.SaveChanges(); }
public Project Post([FromBody] Project project) { TaskManagerDbContext db = new TaskManagerDbContext(); db.Projects.Add(project); db.SaveChanges(); return(project); }
public static void UpdateUser(int userId, string name) { TaskManagerDbContext taskManagerDbContext = new TaskManagerDbContext(); User user = taskManagerDbContext.Users.Find(userId); user.Name = name; taskManagerDbContext.SaveChanges(); }
public static void ChangeStatusTask(int taskId) { TaskManagerDbContext taskManagerDbContext = new TaskManagerDbContext(); Task task = taskManagerDbContext.Tasks.Find(taskId); task.Status = !task.Status; taskManagerDbContext.SaveChanges(); }
public static void DeleteTask(int taskId) { TaskManagerDbContext taskManagerDbContext = new TaskManagerDbContext(); Task task = taskManagerDbContext.Tasks.Find(taskId); taskManagerDbContext.Tasks.Remove(task); taskManagerDbContext.SaveChanges(); }
public void Update(T entity) { _context.Set <T>().Attach(entity); var entry = _context.Entry(entity); entry.State = EntityState.Modified; _context.SaveChanges(); }
private static void Seed(TaskManagerDbContext dbContext) { //var parentTask = GetParentTasks() var tasks = GetTasks(); dbContext.Tasks.AddRange(tasks); dbContext.SaveChanges(); }
public void StartDbContext() { _logger.LogInformation("Starting DB"); if (_dbContext.Database.ProviderName != "Microsoft.EntityFrameworkCore.InMemory") { _migrator.MigrateDB(); } _dbContext.Database.EnsureCreated(); _logger.LogInformation("DB has been initialized properly"); if (!_dbContext.Accounts.Any()) { _logger.LogInformation("creating basic users"); DummyDataHelper.AddDummyAccount(_dbContext); _dbContext.SaveChanges(); DummyDataHelper.AddTaskAccount(_dbContext); _dbContext.SaveChanges(); } }
private void AddSettingIfNotExists(string name, string value, int?tenantId = null) { if (_context.Settings.Any(s => s.Name == name && s.TenantId == tenantId && s.UserId == null)) { return; } _context.Settings.Add(new Setting(tenantId, null, name, value)); _context.SaveChanges(); }
public ActionResult Create([Bind(Include = "EmployeeId,FirstName,LastName,Email,Address,IdentityNumber,DateOfBirth,HiringDate")] Employee employee) { if (ModelState.IsValid) { var typeOfUser = GetUserType(); var obj = Activator.CreateInstance(typeOfUser); FillEmployeeProperties(obj as Employee, employee); if (obj != null) { db.Entry(obj).State = EntityState.Added; db.SaveChanges(); } } return(RedirectToAction("Index")); }
private void AddLanguageIfNotExists(ApplicationLanguage language) { if (_context.Languages.Any(l => l.TenantId == language.TenantId && l.Name == language.Name)) { return; } _context.Languages.Add(language); _context.SaveChanges(); }
private void CreateUserAndRoles() { //Default tenant var defaultTenant = _context.Tenants.FirstOrDefault(t => t.TenancyName == "Default"); if (defaultTenant == null) { _context.Tenants.Add(new Tenant { TenancyName = "Default", Name = "Default" }); _context.SaveChanges(); } }
public ActionResult Register([FromBody] UserViewModel userViewModel) { UserModel _user = taskManagerDbContext.Users.FirstOrDefault(x => x.Username == userViewModel.Username); if (_user == null) { UserModel _newUser = new UserModel(); _newUser.Username = userViewModel.Username; _newUser.Password = userViewModel.Password; taskManagerDbContext.Users.Add(_newUser); taskManagerDbContext.SaveChanges(); taskManagerDbContext.SaveChanges(); return(new JsonResult("successful")); } else { return(new JsonResult("usernamexist")); } }
private void CreateEditions() { var defaultEdition = _context.Editions.FirstOrDefault(e => e.Name == EditionManager.DefaultEditionName); if (defaultEdition == null) { defaultEdition = new Edition { Name = EditionManager.DefaultEditionName, DisplayName = EditionManager.DefaultEditionName }; _context.Editions.Add(defaultEdition); _context.SaveChanges(); //TODO: Add desired features to the standard edition, if wanted! } }
public string AddTask(Task task) { TaskManagerDbContext dbContext = new TaskManagerDbContext(); dbContext.Tasks.Add(task); if (dbContext.SaveChanges() > 0) { return("Record added Successfully"); } else { return("Failed. Plese try again later"); } }
public void AddNewTask([FromBody] Task task) { int userId = 0; CookieHeaderValue cookie = Request.Headers.GetCookies("UserId").FirstOrDefault(); if (cookie != null) { userId = int.Parse(cookie["UserId"].Value); task.UserId = userId; task.LustUpdate = DateTime.Now; if (Context.Tasks.AsNoTracking().Where(c => c.UserId == userId).Count() > 0) { task.TaskId = Context.Tasks.AsNoTracking().Where(c => c.UserId == userId).Select(c => c.TaskId).Max() + 1; } else { task.TaskId = 1; } Context.Tasks.Add(task); Context.SaveChanges(); } }
public string DeleteTask(int id) { TaskManagerDbContext dbContext = new TaskManagerDbContext(); Task task = dbContext.Tasks.Find(id); dbContext.Tasks.Remove(task); if (dbContext.SaveChanges() > 0) { return("Record deleted Successfully"); } else { return("Failed. Plese try again later"); } }
public int Delete(int ProjectID) { TaskManagerDbContext db = new TaskManagerDbContext(); Project existingProject = db.Projects.Where(temp => temp.ProjectID == ProjectID).FirstOrDefault(); if (existingProject != null) { db.Projects.Remove(existingProject); db.SaveChanges(); return(ProjectID); } else { return(-1); } }
public Project Put([FromBody] Project project) { TaskManagerDbContext db = new TaskManagerDbContext(); Project existingProject = db.Projects.Where(temp => temp.ProjectID == project.ProjectID).FirstOrDefault(); if (existingProject != null) { existingProject.ProjectName = project.ProjectName; existingProject.DateOfStart = project.DateOfStart; existingProject.TeamSize = project.TeamSize; db.SaveChanges(); return(existingProject); } else { return(null); } }