Example #1
0
        public ActionResult CreateMethod(TaskObject task)
        {
            TasksContext context = HttpContext.RequestServices.GetService(typeof(TasksContext)) as TasksContext;

            context.InsertTask(task);
            return(RedirectToAction("Index", new { moduleID = task.ModuleID }));
        }
 public ActionResult <IEnumerable <Task> > Get()
 {
     using (var context = new TasksContext())
     {
         return(context.Tasks.ToList());
     }
 }
        public async Task Read_Returns_Result()
        {
            Random rand = new Random();
            int    initialCount;

            using (var context = new TasksContext(_options))
            {
                initialCount = context.Todos.Count();

                context.Todos.Add(new Todo()
                {
                    ID = rand.Next(), Description = "First", Completed = true
                });
                context.Todos.Add(new Todo()
                {
                    ID = rand.Next(), Description = "Second", Completed = true
                });
                context.Todos.Add(new Todo()
                {
                    ID = rand.Next(), Description = "Third", Completed = true
                });
                context.SaveChanges();
            }

            using (var context = new TasksContext(_options))
            {
                var service = new TodoService(context);
                var todos   = await service.Read();

                Assert.AreEqual(initialCount + 3, todos.Count());
            }
        }
Example #4
0
        public ActionResult EditMethod(TaskObject task)
        {
            TasksContext context = HttpContext.RequestServices.GetService(typeof(TasksContext)) as TasksContext;

            context.UpdateTask(task);
            return(RedirectToAction("Index"));
        }
Example #5
0
        public async Task <IActionResult> Edit(int id,
                                               [Bind("Id,Title,Description,Status,CreationDate,EditDate,ConcludedDate")]
                                               TaskViewModel taskViewModel)
        {
            if (id != taskViewModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    TasksContext.UpdateTask(_mapper.Map <Task>(taskViewModel));
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!await TaskExists(taskViewModel.Id))
                    {
                        throw;
                    }
                }

                return(RedirectToAction(nameof(Index)));
            }

            return(View(taskViewModel));
        }
Example #6
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, TasksContext tasksContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            tasksContext.SeedData();

            AutoMapper.Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <Day, DayDto>()
                .ForMember(dest => dest.Tasks, opt => opt.MapFrom(src => src.ToDoItems));

                cfg.CreateMap <ToDoItem, ToDoItemDto>()
                .ForMember(dest => dest.TaskDay, opt => opt.MapFrom(src => src.DayId));

                cfg.CreateMap <ToDoItemForCreationDto, ToDoItem>();
                cfg.CreateMap <ToDoItemForUpdateDto, ToDoItem>();
                cfg.CreateMap <ToDoItem, ToDoItemForUpdateDto>();
            });

            app.UseHttpsRedirection();
            app.UseMvc();
        }
Example #7
0
        public UsuarioValidator(TasksContext context)
        {
            _context = context;
            RuleFor(c => c.Apelido)
            .NotNull()
            .WithMessage("O Apelido deve ser preenchido")
            .NotEmpty()
            .WithMessage("O Apelido deve ser preenchido")
            .MaximumLength(80)
            .WithMessage("O Apelido deve ter no máximo 80 caracteres");

            RuleFor(x => x.Email)
            .NotNull()
            .WithMessage("O Email deve ser preenchido")
            .NotEmpty()
            .WithMessage("O Email deve ser preenchido")
            .MaximumLength(120)
            .WithMessage("O Email deve ter no máximo 120 caracteres")
            .Must((o, email) => EmailJaCadastrado(o.Id, email))
            .WithMessage("Esse e-mail já esta em uso.");

            RuleFor(x => x.Senha)
            .NotNull()
            .WithMessage("A Senha deve ser preenchido")
            .NotEmpty()
            .WithMessage("A Senha deve ser preenchido");
        }
Example #8
0
 public HomeController(ILogger <HomeController> logger,
                       IConfiguration configuration,
                       TasksContext tasksContext)
 {
     _logger        = logger;
     _configuration = configuration;
     _tasksContext  = tasksContext;
 }
 public void Post([FromBody] Task task)
 {
     using (var context = new TasksContext())
     {
         context.Tasks.Add(task);
         context.SaveChanges();
     }
 }
Example #10
0
 public UsuarioServices(TasksContext context,
                        IMapper mapper,
                        IValidator <UsuarioDto> usuarioValidator)
 {
     _context          = context;
     _mapper           = mapper;
     _usuarioValidator = usuarioValidator;
 }
Example #11
0
 public BaseTest(TasksFixture fixture, string url)
 {
     Request          = fixture.Request;
     EntitiesFactory  = fixture.EntitiesFactory;
     DbContext        = fixture.DbContext;
     SessionDeveloper = fixture.SessionDeveloper;
     Uri = new Uri($"{fixture.Client.BaseAddress}/{url}");
 }
Example #12
0
 public void Should_Create_Database_From_TasksContext()
 {
     using (var ctx = new TasksContext())
     {
         ctx.Categories.Add(new Category() {Color = Color.Red, Name = "ISEL"});
         ctx.SaveChanges();
     }
 }
Example #13
0
 public BuilderFactory(
     TEntity entity,
     TasksContext context
     )
 {
     _context = context;
     _entity  = entity;
 }
 public void Delete(int id)
 {
     using (var context = new TasksContext())
     {
         Task taskToDelete = context.Tasks.Find(id);
         context.Remove(taskToDelete);
         context.SaveChanges();
     }
 }
 public void Put(int id, [FromBody] Task task)
 {
     using (var context = new TasksContext())
     {
         Task taskToChange = context.Tasks.Find(id);
         taskToChange.State = task.State;
         context.SaveChanges();
     }
 }
Example #16
0
        public TasksFixture()
        {
            var builder = new DbContextOptionsBuilder <TasksContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .EnableSensitiveDataLogging()
                          .EnableDetailedErrors();

            DbContext = new TasksContext(builder.Options);
        }
Example #17
0
 /// <summary>
 /// Initializes the singleton application object.  This is the first line of authored code
 /// executed, and as such is the logical equivalent of main() or WinMain().
 /// </summary>
 public App()
 {
     this.InitializeComponent();
     this.Suspending += OnSuspending;
     using (var db = new TasksContext())
     {
         db.Database.Migrate();
     }
 }
Example #18
0
 public MainWindow()
 {
     InitializeComponent();
     using (var context = new TasksContext())
     {
         context.Tasks.ToList();
         context.SaveChanges();
     }
 }
Example #19
0
 public static void Main(string[] args)
 {
     using (var ctx = new TasksContext(GetDbOptions()))
     {
         CreateInitialData(ctx);
         ShowTasksWithCategories(ctx);
         MoveTaskToDoneById(ctx, 3);
         ShowDoneTasksWithCategories(ctx);
     }
 }
        public async Task Create_Returns_ViewModel()
        {
            using (var context = new TasksContext(_options))
            {
                var service       = new TodoService(context);
                var todoViewModel = await service.Create("sample descr");

                Assert.AreEqual("sample descr", todoViewModel.Description);
            }
        }
        public async Task Create_Adds_ID_To_Entity()
        {
            using (var context = new TasksContext(_options))
            {
                var service       = new TodoService(context);
                var todoViewModel = await service.Create("sample descr");

                Assert.IsNotNull(todoViewModel.ID);
            }
        }
Example #22
0
        public void Setup()
        {
            // Create fake of DB (InMemory) by context factory
            var contextFactory = FakeDbContext.Get("TestDBContext");

            // Call factory to create new context
            _context = contextFactory();
            // Init _tasks
            _tasks = new List <Context.Models.Task>();
        }
Example #23
0
        public IActionResult Index(int moduleid)
        {
            if (moduleid == -1)
            {
                return(RedirectToAction("Error"));
            }

            TasksContext context = HttpContext.RequestServices.GetService(typeof(TasksContext)) as TasksContext;

            return(View(context.GetTaskContainer(moduleid)));
        }
Example #24
0
        public ActionResult Move([FromBody] TaskMovingData data, int targetStatus = -1)
        {
            TasksContext context = HttpContext.RequestServices.GetService(typeof(TasksContext)) as TasksContext;

            if (targetStatus == -1)
            {
                targetStatus = Convert.ToInt32(data.currentTaskStatus) + 1;
            }
            int rowsAffected = context.MoveTask(Convert.ToInt32(data.taskID), Convert.ToInt32(data.currentTaskStatus), targetStatus);

            return(Json(String.Format("'RowsAffected':'{0}'", rowsAffected)));
        }
Example #25
0
        public async Task <IActionResult> Create(
            [Bind("Id,Title,Description,Status,CreationDate,EditDate,RemovedDate,ConcludedDate")]
            TaskViewModel task)
        {
            if (ModelState.IsValid)
            {
                await TasksContext.AddTask(_mapper.Map <Task>(task));

                return(RedirectToAction(nameof(Index)));
            }

            return(View(task));
        }
Example #26
0
        static void InsertProjectTask(string name, TasksContext context)
        {
            ProjectTask projectTask = new ProjectTask()
            {
                Id            = Guid.NewGuid(),
                Name          = name,
                IsProjectTask = true,
                ProjectName   = "My Project",
                PWAInstance   = "ILABS"
            };

            context.Tasks.Add(projectTask);
            context.SaveChanges();
        }
Example #27
0
        public static void ShowTasksWithCategories(TasksContext ctx)
        {
            var tasks = ctx.Tasks.Include(c => c.TaskCategories).ThenInclude(sc => sc.Category).ToList();

            foreach (var task in tasks)
            {
                Console.WriteLine($"\n Task: {task.Name}");
                var categories = task.TaskCategories.Select(sc => sc.Category).ToList();
                foreach (var category in categories)
                {
                    Console.WriteLine($"--- Category: {category.Name}");
                }
            }
        }
Example #28
0
        public static void CreateInitialData(TasksContext ctx)
        {
            Task task1 = new Task {
                Name = "task1"
            };
            Task task2 = new Task {
                Name = "task2"
            };
            Task task3 = new Task {
                Name = "task3"
            };

            ctx.Tasks.AddRange(new HashSet <Task> {
                task1, task2, task3
            });

            Category c1 = new Category {
                Name = "Category 1"
            };
            Category c2 = new Category {
                Name = "Category 2"
            };
            Category c3 = new Category {
                Name = "Category 3"
            };

            ctx.Categories.AddRange(new HashSet <Category> {
                c1, c2, c3
            });

            ctx.SaveChanges();

            task1.TaskCategories.Add(new TaskCategory {
                CategoryId = c1.Id, TaskId = task1.Id
            });
            task2.TaskCategories.Add(new TaskCategory {
                CategoryId = c1.Id, TaskId = task2.Id
            });
            task2.TaskCategories.Add(new TaskCategory {
                CategoryId = c2.Id, TaskId = task2.Id
            });
            task3.TaskCategories.Add(new TaskCategory {
                CategoryId = c2.Id, TaskId = task3.Id
            });
            task3.TaskCategories.Add(new TaskCategory {
                CategoryId = c3.Id, TaskId = task3.Id
            });
            ctx.SaveChanges();
        }
Example #29
0
        static void InsertTrelloTask(string name, TasksContext context)
        {
            TrelloTask trelloTask = new TrelloTask()
            {
                Id           = Guid.NewGuid(),
                Name         = name,
                Description  = "Description da trello task 1",
                IsTrelloTask = true,
                BoardName    = "Board teste",
                BoardId      = "xyz"
            };

            context.Tasks.Add(trelloTask);
            context.SaveChanges();
        }
Example #30
0
        static void Main(string[] args)
        {
            TasksContext context = new TasksContext();

            var task = context.Tasks.FirstOrDefault(t => t.Name == "ProjecTask");

            if (task != null)
            {
                Console.WriteLine("task exist");
            }

            Console.WriteLine("Task is project? ", task is ProjectTask);

            Console.ReadKey();
        }
Example #31
0
        // GET: Tasks/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var task = await TasksContext.GetTask(id.Value);

            if (task == null)
            {
                return(NotFound());
            }

            return(View(_mapper.Map <TaskViewModel>(task)));
        }