public void CreateUser(string userName, string roleName) { var unitOfwork = new ProjectUnitOfWork(); var userRole = unitOfwork.RoleRepository.Where(r => r.Name == roleName).FirstOrDefault(); var newUser = new Users() { Id = Guid.NewGuid().ToString(), Email = userName + "@mytasks.cl", EmailConfirmed = true, PasswordHash = "ADggy6naWtPgOdgAWhwGKQj1EUtBWuRkpYXnUpYXN5+ac2D+2AieripppwYT4jiKIA==", SecurityStamp = "78b9c51e-a6ff-47d3-b54b-84ab7223b157", PhoneNumber = "32323111", PhoneNumberConfirmed = true, TwoFactorEnabled = false, LockoutEndDateUtc = new DateTime(2016, 03, 18), LockoutEnabled = false, AccessFailedCount = 0, UserName = userName, FullName = userName, Address = null, DNI = "", Language = "en-us", }; var newUserRole = new UserRoles { UserId = newUser.Id, RoleId = userRole.Id }; unitOfwork.UserRepository.Add(newUser); unitOfwork.SaveChanges(); unitOfwork.UserRoleRepository.Add(newUserRole); unitOfwork.SaveChanges(); }
public void InsertNewProject(string projectName) { Random r = new Random(); var unitOfwork = new ProjectUnitOfWork(); var userUnitOfWork = new UserUnitOfWork(); var projectManagers = userUnitOfWork.GetProjectManagers(); var projectManagersCount = projectManagers.Count; var customers = unitOfwork.CustomerRepository.All().ToList(); var customerCount = customers.Count; var customerIndex = r.Next(0, customerCount); var projectManagerIndex = r.Next(0, projectManagersCount); var newProject = new Project { CustomerId = customers[customerIndex].CustomerId, ProjectManagerId = projectManagers[projectManagerIndex].Id, Description = projectName, ProjectName = projectName, Areas = new List <Area> { new Area { Name = "Area A" } } }; unitOfwork.ProjectRepository.Add(newProject); unitOfwork.SaveChanges(); }
public static void CreateNew100Project() { string connectionString = "port=3306;server=localhost;user id=Developer;password=holamundo;database=mytasks"; using (MySqlConnection connection = new MySqlConnection(connectionString)) { using (WorkinghoursDataContext context = new WorkinghoursDataContext(connection, false)) { var unitOfwork = new ProjectUnitOfWork(context); var firstCustomer = unitOfwork.CustomerRepository.All().First(); for (int i = 0; i < 1000; i++) { var newProject = new Project { CustomerId = firstCustomer.CustomerId, Description = "project " + i, ProjectName = "project " + i }; unitOfwork.ProjectRepository.Add(newProject); } unitOfwork.SaveChanges(); } } }
public void AddDemoCustomer(string customerName) { var unitOfwork = new ProjectUnitOfWork(); var newCustomer = new Customer { Name = customerName, }; unitOfwork.CustomerRepository.Add(newCustomer); unitOfwork.SaveChanges(); }
//[ValidateAntiForgeryToken] public JsonResult Create(Project proj) { Data.Validators.ValidationStatus status = null; try { status = unitOfWork.Validate(proj); if (status.IsValid) { unitOfWork.AddProject(proj); unitOfWork.SaveChanges(); } return(new JsonResult { Data = new { status = status } }); } catch (Exception ex /* dex */) { return(new JsonResult { Data = new { status = new Data.Validators.ValidationStatus { IsValid = false, ErrorMessage = Localization.Desktop.Desktop.UnableToSaveChanges } } }); } }