public IActionResult Completed(int tasknotifyId)
        {
            TaskNotify task = taskRepo.GetTask(tasknotifyId);

            task.TaskCompleted  = true;
            task.CompletionDate = DateTime.Now;
            taskRepo.Update(task);
            return(RedirectToAction("Index"));
        }
        public IActionResult Index(int tasknotifyId)
        {
            TaskNotify task = taskRepo.GetTask(tasknotifyId);

            if (!task.TaskViewed)
            {
                task.TaskViewed = true;
            }
            taskRepo.Update(task);
            return(RedirectToAction("Index", "UserTasks"));
        }
Пример #3
0
        public async Task <IActionResult> TaskForm(TaskViewModel taskVm)
        {
            if (orderRepo.DoesOrderExist(taskVm.OrderId))
            {
                if (ModelState.IsValid)
                {
                    UserIdentity userId = new UserIdentity();
                    User         user   = userRepo.GetUser(taskVm.UserId);
                    Order        order  = orderRepo.GetOrder(taskVm.OrderId);
                    TaskNotify   task   = new TaskNotify
                    {
                        DueDate      = taskVm.DueDate,
                        Body         = taskVm.Body,
                        CreationDate = DateTime.Now,
                        Title        = taskVm.Title,
                        TaskFor      = user,
                        Order        = order
                    };
                    string name = HttpContext.User.Identity.Name;
                    userId = await userManager.FindByNameAsync(name);

                    task.PostedBy = userRepo.GetUser(userId.UserName);
                    taskRepo.Create(task);
                    return(RedirectToAction("Index", "Task"));
                }
                else
                {
                    return(View(taskVm));
                }
            }
            else
            {
                ModelState.AddModelError(nameof(taskVm.OrderId), "OrderId Does Not Exist");

                return(View(taskVm));
            }
        }
Пример #4
0
 public int Update(TaskNotify task)
 {
     context.TaskNotifies.Update(task);
     return(context.SaveChanges());
 }
Пример #5
0
 public int Create(TaskNotify task)
 {
     context.TaskNotifies.Add(task);
     return(context.SaveChanges());
 }
Пример #6
0
        public static async Task EnsurePopulated(IApplicationBuilder app)
        {
            UserManager <UserIdentity> userManager = app.ApplicationServices.GetRequiredService <UserManager <UserIdentity> >();
            RoleManager <IdentityRole> roleManager = app.ApplicationServices.GetRequiredService <RoleManager <IdentityRole> >();

            ApplicationDbContext context = app.ApplicationServices.GetRequiredService <ApplicationDbContext>();

            if (!context.TaskNotifies.Any())
            {
                Customer customer = new Models.Customer {
                    Company = "9Wood", ContactName = "Woody Wonkers", PhoneNumber = "541-999-2222", Address = "177 West 128th Ave, Boring, Oregon 98115", Email = "*****@*****.**"
                };
                context.Customers.Add(customer);
                Order order = new Order {
                    Customer = customer, CreationDate = DateTime.Now, DueDate = DateTime.Parse("5/15/17"), Title = "Business Cards"
                };
                context.Orders.Add(order);
                customer = new Customer {
                    Company = "Smith Family", ContactName = "Sam Mckracken", PhoneNumber = "541-999-2852", Address = "20 West 5th Ave, Eugene, Oregon 98115", Email = "*****@*****.**"
                };
                context.Customers.Add(customer);
                order = new Order {
                    Customer = customer, CreationDate = DateTime.Now, DueDate = DateTime.Parse("5/20/17"), Title = "Bookmarks"
                };
                context.Orders.Add(order);

                User user = new User {
                    Name = "Chris Lemon", FirstName = "Chris", LastName = "Lemon", Password = "******", Email = "*****@*****.**"
                };
                context.Users.Add(user);
                User user2 = new User {
                    Name = "John Hamm", FirstName = "John", LastName = "Hamm", Password = "******", Email = "*****@*****.**"
                };
                context.Users.Add(user2);
                TaskNotify task = new TaskNotify {
                    TaskFor       = user2,
                    PostedBy      = user,
                    Body          = "Send business card proof by the 9th",
                    CreationDate  = DateTime.Now,
                    DueDate       = DateTime.Parse("5/9/17"),
                    Order         = order,
                    Title         = "9Wood Proof",
                    TaskViewed    = false,
                    TaskCompleted = false
                };
                context.TaskNotifies.Add(task);

                customer = new Models.Customer {
                    Company = "Willamette Family", ContactName = "Kathy Kay", PhoneNumber = "541-111-2222", Address = "744 River Ave, Eugene, Oregon 97401", Email = "kath@willfam"
                };
                context.Customers.Add(customer);
                order = new Order {
                    Customer = customer, CreationDate = DateTime.Now, DueDate = DateTime.Parse("5/20/17"), Title = "Presentation Folder"
                };
                context.Orders.Add(order);
                user = new User {
                    Name = "Jack White", FirstName = "Jack", LastName = "White", Password = "******", Email = "*****@*****.**"
                };
                context.Users.Add(user);
                user2 = new User {
                    Name = "Henry Rollins", FirstName = "Henry", LastName = "Rollins", Password = "******", Email = "*****@*****.**"
                };
                context.Users.Add(user2);
                task = new TaskNotify
                {
                    TaskFor       = user2,
                    PostedBy      = user,
                    Body          = "Order copper die for Willamette Family Folder",
                    CreationDate  = DateTime.Now,
                    DueDate       = DateTime.Parse("5/6/17"),
                    Order         = order,
                    Title         = "Die",
                    TaskViewed    = true,
                    TaskCompleted = true
                };
                context.TaskNotifies.Add(task);

                foreach (User m in context.Users)
                {
                    UserIdentity userId = new UserIdentity {
                        UserName = m.Email
                    };



                    string         password = m.Password;
                    string         role     = "User";
                    IdentityResult result   = await userManager.CreateAsync(userId, password);

                    if (await roleManager.FindByNameAsync(role) == null)
                    {
                        await roleManager.CreateAsync(new IdentityRole(role));

                        if (result.Succeeded)
                        {
                            await userManager.AddToRoleAsync(userId, role);
                        }
                    }
                }
                User userAdmin = new User {
                    Name = "Flim Flam", FirstName = "Flim", LastName = "Flam", Password = "******", Email = "*****@*****.**"
                };
                string role2 = "Administrator";
                context.Users.Add(userAdmin);
                UserIdentity userIdAdmin = new UserIdentity {
                    UserName = userAdmin.Email
                };
                string         password2 = userAdmin.Password;
                IdentityResult result2   = await userManager.CreateAsync(userIdAdmin, password2);

                if (await roleManager.FindByNameAsync(role2) == null)
                {
                    await roleManager.CreateAsync(new IdentityRole(role2));

                    if (result2.Succeeded)
                    {
                        await userManager.AddToRoleAsync(userIdAdmin, role2);
                    }
                }
                context.SaveChanges();
            }
        }