public async Task <IActionResult> PutTodoCategory(int id, TodoCategory todoCategory) { if (id != todoCategory.Id) { return(BadRequest()); } _context.Entry(todoCategory).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TodoCategoryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <TodoCategory> > PostTodoCategory(TodoCategory todoCategory) { _context.TodoCategories.Add(todoCategory); await _context.SaveChangesAsync(); return(CreatedAtAction("GetTodoCategory", new { id = todoCategory.Id }, todoCategory)); }
public void CreateTodo( TodoText text, TodoCategory category, TodoStatus status) { Apply(new TaskCreated(EventSourceId, text, category, status)); }
private void init() { mockLogger = new Mock <ILogger <TodosController> >(); mockServiceLogger = new Mock <ILogger <TodosService> >(); service = new TodosService(mockRepo.Object, mockServiceLogger.Object); mockMapper = new Mock <IMapper>(); //var mappings = new MapperConfigurationExpression(); //mappings.AddProfile<DomainProfile>(); //Mapper.Initialize(mappings); Mapper.Initialize(cfg => { cfg.CreateMap <Todo, TodoView>(); cfg.CreateMap <TodoCategory, TodoCategoryView>(); cfg.CreateMap <TodoView, Todo>(); cfg.CreateMap <TodoCategoryView, TodoCategory>(); }); controller = new TodosController(mockMapper.Object, service, mockLogger.Object); TodoCategory category = new TodoCategory(1, "Bevásárlás", 127); TodoCategory category1 = new TodoCategory(2, "Teendõk", 156565); testTodos.Add(new Todo(1, "Korte", category)); testTodos.Add(new Todo(2, "Szilva", category)); testTodos.Add(new Todo(3, "Kitakarítani", category1)); testTodos.ElementAt(0).Archived = true; }
public async Task <ActionResult <IEnumerable <Todo> > > GetTodos(TodoCategory category) { if (!Enum.TryParse <TodoCategory>($"{category}", out TodoCategory outCategory)) { return(NotFound()); } return(await todoService.ListByCategoryAsync(category)); }
private List <Todo> GetTestTodos() { TodoCategory category = new TodoCategory(1, "Bevásárlás", 127); List <Todo> todos = new List <Todo>(); todos.Add(new Todo(1, "Alma", category)); todos.Add(new Todo(1, "Korte", category)); todos.Add(new Todo(1, "Szilva", category)); return(todos); }
public DbSet <TodoCategory> AddCategory([FromBody] TodoCategory category) { if (category.Id > 0 || category.Text != "") { _context.Add(new TodoCategory(category.Text)); _context.SaveChanges(); } return(_context.Categories); }
public void Insert(TodoCategoryDTO dto) { var entity = new TodoCategory() { Title = dto.Title, Created = DateTime.Now, Updated = DateTime.Now }; _repository.Insert(entity); }
async Task <List <Todo> > ITodosService.GetTodos(string todoType, SortingType sortingType) { TodoCategory todoCategory = _todoRepository.FindCategoryByName(todoType); if (todoCategory == null) { var ex = new CategoryNotFoundException(404, "Nem található ilyen kategória: " + todoType); _logger.LogError($"Nem található ilyen kategória : {todoType}"); throw ex; } return(await _todoRepository.GetTodos(todoCategory, sortingType)); }
public IHttpActionResult Add(TodoCategory newCategory) { try { return Ok(_service.Add(newCategory)); } catch (Exception) { return NotFound(); } }
private List <Todo> GetTestArchivedTodos() { TodoCategory category = new TodoCategory(1, "Bevásárlás", 127); List <Todo> todos = new List <Todo>(); todos.Add(new Todo(1, "Alma", category)); todos.Add(new Todo(2, "Korte", category)); todos.Add(new Todo(3, "Szilva", category)); foreach (var todo in todos) { todo.Archived = true; } return(todos); }
public IActionResult Edit(int id, TodoCategory category) { var categoryToEdit = _todoRepo.GetCategory(id); categoryToEdit.Name = category.Name; _todoRepo.UpdateCategory(categoryToEdit); _todoRepo.Save(); return(RedirectToRoute(new { controller = "Todo", action = "List" })); }
public IActionResult Create(TodoCategory category) { if (ModelState.IsValid) { _todoRepo.AddCategory(category); _todoRepo.Save(); return(RedirectToRoute(new { controller = "Todo", action = "List" })); } return(View(category)); }
public async Task <List <Todo> > GetTodos(TodoCategory todoType, SortingType sortingType = SortingType.TimeDESC) { var todos = await _context.Todos .Include(todo => todo.Type) .Where(t => t.Type.Equals(todoType)) .OrderByDescending(t => t.CreationDate) .ToListAsync(); if (todos == null) { _logger.LogWarning("Zero todo found!"); return(null); } _logger.LogDebug($"Got Todos sorting by : {sortingType} TodoType : {todoType}"); return(todos); }
public IQueryable DeleteCategory([FromBody] TodoCategory category) { var categoryToBeDeleted = _context.Categories.SingleOrDefault(e => e.Id == category.Id); if (categoryToBeDeleted != null) { var itemsToBeDeleted = _context.TodoItems.Where(e => e.Category == category.Id).ToArray(); if (itemsToBeDeleted.Length > 0) { _context.RemoveRange(itemsToBeDeleted); _context.SaveChanges(); } _context.Remove(categoryToBeDeleted); _context.SaveChanges(); } return(_context.Categories); }
public IActionResult OnPostAddNewCategory() { var catName = Request.Form["catName"]; if (String.IsNullOrEmpty(catName)) { return(new JsonResult(new ResponseMessage(500, "Invalid inut", null))); } this.TodoCats = _todoCatServices.GetTodoCategoryList(); // Check name dupplicate foreach (var cat in this.TodoCats) { if (cat.Name.Equals(catName)) { return(new JsonResult(new ResponseMessage(500, "Existed category", null))); } } TodoCategory newCat = new TodoCategory(); newCat.Name = catName; _todoCatServices.AddNewTodoCategory(newCat); return(new JsonResult(new ResponseMessage(200, "Added successfully", newCat))); }
public async Task <int> Handle(CreateTodoCategoryCommand request, CancellationToken cancellationToken) { var entity = new TodoCategory { CategoryTitle = request.CategoryTitle, UserPropertyId = request.UserPropertyId, }; var titleValidation = _context.TodoCategories .Where(x => x.UserPropertyId == request.UserPropertyId) .Any(x => x.CategoryTitle == request.CategoryTitle); if (titleValidation) { throw new AppException(); } _context.TodoCategories.Add(entity); await _context.SaveChangesAsync(cancellationToken); return(entity.Id); }
public void UpdateCategory(TodoCategory category) { _context.TodoCategories.Update(category); }
public static void Initialize(ApplicationDbContext context) { context.Database.EnsureCreated(); if (context.Events.Any()) { return; } var categories = new TodoCategory[] { new TodoCategory { Name = "All" }, new TodoCategory { Name = "Home" }, new TodoCategory { Name = "Work" }, new TodoCategory { Name = "Other" }, new TodoCategory { Name = "Studies" } }; foreach (TodoCategory category in categories) { context.TodoCategories.Add(category); } context.SaveChanges(); var todoItems = new TodoItem[] { new TodoItem { Title = "Buy bananas", Complete = false, Date = new DateTime(2017, 12, 10), CategoryId = 2 }, new TodoItem { Title = "Buy some food", Complete = false, Date = new DateTime(2017, 12, 10), CategoryId = 2 }, new TodoItem { Title = "Do Homework", Complete = true, Date = new DateTime(2017, 12, 10), CategoryId = 5 }, new TodoItem { Title = "Do Extra Task", Complete = false, Date = new DateTime(2017, 12, 10), CategoryId = 5 }, new TodoItem { Title = "Go to the gym", Complete = false, Date = new DateTime(2017, 12, 10), CategoryId = 4 } }; foreach (TodoItem item in todoItems) { context.TodoItems.Add(item); } context.SaveChanges(); var budgets = new Budget[] { new Budget { Name = "January budget", Amount = 300, StartDate = new DateTime(2018, 1, 1), EndDate = new DateTime(2018, 1, 31) }, new Budget { Name = "February budget", Amount = 300, StartDate = new DateTime(2018, 2, 1), EndDate = new DateTime(2018, 2, 28) }, }; foreach (Budget budget in budgets) { context.Budgets.Add(budget); } context.SaveChanges(); var events = new Event[] { new Event { Name = "Play PS4 with friends", Description = "Gaming party", Location = "Home", StartDate = new DateTime(2017, 11, 10), StartTime = "20:00:00", EndDate = new DateTime(2017, 11, 11), EndTime = "06:00:00" }, new Event { Name = "Drink beer with friends", Description = "Beer party", Location = "Bar", StartDate = new DateTime(2017, 11, 15), StartTime = "20:00:00", EndDate = new DateTime(2017, 11, 16), EndTime = "03:00:00" }, }; foreach (Event evt in events) { context.Events.Add(evt); } context.SaveChanges(); }
public void RemoveCategory(TodoCategory category) { _context.TodoCategories.Remove(category); }
public async Task <List <Todo> > ListByCategoryAsync(TodoCategory todoCategory) { return(await context.Todos.Where(t => t.Category == todoCategory).ToListAsync()); }
public TodoCategory Add(TodoCategory item) { return _repository.AddCategory(item); }
/// <summary> /// Add new category /// </summary> /// <param name="newCategory"> new category object</param> public TodoCategory AddCategory(TodoCategory newCategory) { _context.TodoCategories.Add(newCategory); _context.SaveChanges(); return _context.TodoCategories.FirstOrDefault(c => c.Name.Equals(newCategory.Name)); }
public void AddCategory(TodoCategory category) { _context.TodoCategories.Add(category); }