private void CreateReport(User user, Task task) { Report report = new Report { Task = task, ReportedOn = DateTime.Now, UserId = user.Id, Status = this.GetRandomStatus() }; this.db.Reports.Add(report); db.SaveChanges(); }
public bool RegisterUser(string username, string password, string email) { Role role = DecideRole(); bool userExists = this.db.Users.Any(u => u.Username == username); if (userExists || string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password)) { return(false); } var user = new User() { Username = username, Password = password, Email = email, Role = role }; this.db.Users.Add(user); db.SaveChanges(); return(true); }
private void SeedTasks() { using (var context = new TorshiaContext()) { var affectedSector = context.SectorTypes.FirstOrDefault(s => s.Name == "Customers"); for (int i = 0; i < 5; i++) { Random rand = new Random(); int randomSectors = rand.Next(1, context.SectorTypes.Count()); context.Tasks.Add(new Task() { Title = $"GeneratedTitle {new string(char.Parse(i.ToString()), 5)}", DueDate = DateTime.ParseExact("01-12-2018", "dd-MM-yyyy", CultureInfo.InstalledUICulture), IsReported = false, Participants = "Pesho, Gosho, User", Description = $"{new string('A', 10)}", AffectedSectors = $"{randomSectors}", }); } context.SaveChanges(); } }
public User RegisterUser(string username, string password, string confirmPassword, string email) { UserRole role = new UserRole(); if (!context.Users.Any()) { role = context.UserRoles.FirstOrDefault(r => r.Name == "Admin"); } else { role = context.UserRoles.FirstOrDefault(r => r.Name == "User"); } User user = new User() { Username = username, Password = password, Email = email, Role = role, }; context.Users.Add(user); context.SaveChanges(); return(user); }
public static void Main() { var context = new TorshiaContext(); for (int i = 0; i < 6; i++) { context.Reports.Add(new Report { Status = Status.Completed, TaskId = 2, ReporterId = 1, ReportedOn = DateTime.Now }); } context.SaveChanges(); WebHost.Start(new StartUp()); }
public void CreateTask(string title, string dueDate, string description, string participants, List <string> selectedSectors) { DateTime.TryParse(dueDate, out DateTime date); var task = new Task { Title = title, Due = date, Description = description, Participants = participants }; var taskSectors = new List <TaskSector>(); foreach (var selectedSector in selectedSectors) { if (selectedSector != null) { bool isValidSector = Enum.TryParse(typeof(Models.Enums.Sector), selectedSector.ToString(), out object sectorValue); if (isValidSector) { var sector = new Models.Sector { Name = (Models.Enums.Sector)sectorValue }; var taskSector = new TaskSector { Task = task, Sector = sector }; taskSectors.Add(taskSector); } } } task.AffectedSectors.AddRange(taskSectors); context.Tasks.Add(task); context.SaveChanges(); }
private void SeedDatabase() { using (var context = new TorshiaContext()) { context.UserRoles.Add(new UserRole { Name = "User" }); context.UserRoles.Add(new UserRole { Name = "Admin" }); context.SectorTypes.Add(new SectorType { Name = "Customers" }); context.SectorTypes.Add(new SectorType { Name = "Marketing" }); context.SectorTypes.Add(new SectorType { Name = "Finances" }); context.SectorTypes.Add(new SectorType { Name = "Internal" }); context.SectorTypes.Add(new SectorType { Name = "Management" }); context.ReportStatuses.Add(new ReportStatus { Name = "Completed" }); context.ReportStatuses.Add(new ReportStatus { Name = "Archived" }); context.SaveChanges(); } }
private static void SeedTasks() { var db = new TorshiaContext(); for (int i = 1; i <= 10; i++) { db.Tasks.Add(new Task { Title = $"Fix Business Agenda{i}", DueDate = new System.DateTime(2019 + i, 09, 11 + i), Description = $"The business agaenda of the company needs to be rethought.{i}", Participants = $"Todor Ivanov{i}, Jordan Draganov{i}, Dimitar Stefanov{i}", AffectedSectors = new List <TaskSector>() { new TaskSector() { Sector = Sector.Management }, new TaskSector() { Sector = Sector.Finances }, new TaskSector() { Sector = Sector.Management }, new TaskSector() { Sector = Sector.Internal } } }); } db.SaveChanges(); }
public void CreateTask(Task task) { this.context.Tasks.Add(task); context.SaveChanges(); }