public async Task <bool> CreateAgileItem(CreateAgileItemDto agileItem) { // Create item with necessary server side properties var fullItem = CreateServerSideAgileItem(agileItem); try { if (fullItem.AgileItemType != Models.Types.AgileItemType.SuperStory) { var parent = await _context.AgileItems.Where(i => i.Id == fullItem.ParentId).FirstOrDefaultAsync(); var board = await _context.Boards.Where(b => b.Id == fullItem.BoardId).FirstOrDefaultAsync(); if (parent == null || board == null) { throw new Exception("Invalid parent or board Id"); } } await _context.AgileItems.AddAsync(fullItem); await _context.SaveChangesAsync(); return(true); } catch (Exception e) { _logger.LogError("Exception when creating agile item, Exception:" + e + "Stack trace:" + e.StackTrace, "item: " + agileItem); } return(false); }
private AgileItemDto CreateServerSideAgileItem(CreateAgileItemDto agileItem) { // Create Dto in expected shape with some necessary server side generated properties such as createdOn return(new AgileItemDto { AgileItemType = agileItem.ItemType, AssigneeId = agileItem.AssigneeId, AssigneeName = agileItem.AssigneeName, Description = agileItem.Description, BoardId = agileItem.Board, CreatedBy = agileItem.CreatedBy, CreatedOn = DateTime.Now, DueBy = agileItem.DueBy, EstimatedTime = agileItem.EstimatedTime, IsActive = true, Id = Guid.NewGuid(), IsComplete = false, Order = agileItem.Order, ParentId = agileItem.ParentId, Priority = agileItem.Priority, Status = Models.Types.Status.Pending, StoryPoints = agileItem.StoryPoints, Title = agileItem.Title }); }
public async Task <IActionResult> CreateAgileItem([FromBody] CreateAgileItemDto agileItem) { var success = await _agileItemRepository.CreateAgileItem(agileItem); if (success) { return(Ok(success)); } return(new StatusCodeResult(500)); }
public void Setup() { _mockAgileItemsRepository = new Mock <IAgileItemRepository>(); _agileItemsController = new AgileItemsController(_mockAgileItemsRepository.Object); _stubShortVm = new AgileItemShortVm { Id = Guid.Parse("08a60a7f-6d09-438c-97f7-cef7426b1b83"), Order = 1, Title = "Stub Title" }; _stubCreateAgileItemDto = new CreateAgileItemDto { AssigneeId = Guid.Parse("0f294219-704d-40a5-afe9-a74fffa7003f"), AssigneeName = "Oli", Board = Guid.Parse("aada6f2a-8854-4a5e-a907-2244f43408a1"), CreatedBy = Guid.Parse("0f294219-704d-40a5-afe9-a74fffa7003f"), Description = "Stub create", DueBy = DateTime.Now.AddHours(1), EstimatedTime = 1, ItemType = Models.Types.AgileItemType.Story, Order = null, ParentId = Guid.Parse("5eb09b45-9c70-4465-b62d-535e28b16aed"), Priority = Models.Types.Priority.High, StoryPoints = 3, Title = "A stub creation of a story" }; _stubUpdateItemVm = new BoardTaskVm { Id = Guid.Parse("5eb09b45-9c70-4465-b62d-535e28b16aed"), AssigneeId = Guid.Parse("0f294219-704d-40a5-afe9-a74fffa7003f"), AssigneeName = "Oli", Description = "Updated", Order = 3, Priority = Models.Types.Priority.Low, Status = Models.Types.Status.Complete, Title = "Updated title" }; _stubFullAgileItemVm = new AgileItemVm { Id = Guid.Parse("5eb09b45-9c70-4465-b62d-535e28b16aee"), AssigneeId = Guid.Parse("0f294219-704d-40a5-afe9-a74fffa7003f"), AssigneeName = "Oli", CreatedBy = Guid.Parse("0f294219-704d-40a5-afe9-a74fffa7003f"), Description = "Stub Story", DueBy = DateTime.Now.AddHours(1), EstimatedTime = 1, AgileItemType = Models.Types.AgileItemType.Story, Order = null, Priority = Models.Types.Priority.High, Title = "A stub creation of a story", CreatedOn = DateTime.Now, IsActive = true, IsComplete = false, Status = Models.Types.Status.InProgress, ParentId = Guid.Parse("5eb09b45-9c70-4465-b62d-535e28b16aed"), BoardId = Guid.Parse("aada6f2a-8854-4a5e-a907-2244f43408a1"), }; _stubOverviewVm = new AgileItemOverviewVm { AssigneeName = "Oli", Description = "Stub Story", Order = null, Priority = Models.Types.Priority.High, Title = "A stub creation of a story", IsComplete = false, Status = Models.Types.Status.InProgress, }; _stubShortVmList = new List <AgileItemShortVm> { _stubShortVm }; _stubOverviewVmList = new List <AgileItemOverviewVm> { _stubOverviewVm }; }
public void Setup() { _stubCreateAgileItemDto = new CreateAgileItemDto { AssigneeId = Guid.Parse("0f294219-704d-40a5-afe9-a74fffa7003f"), AssigneeName = "Oli", Board = Guid.Parse("aada6f2a-8854-4a5e-a907-2244f43408a1"), CreatedBy = Guid.Parse("0f294219-704d-40a5-afe9-a74fffa7003f"), Description = "Stub create", DueBy = DateTime.Now.AddHours(1), EstimatedTime = 1, ItemType = Models.Types.AgileItemType.Story, Order = null, ParentId = Guid.Parse("5eb09b45-9c70-4465-b62d-535e28b16aed"), Priority = Models.Types.Priority.High, StoryPoints = 3, Title = "A stub creation of a story" }; _stubSuperStoryDto = new AgileItemDto { Id = Guid.Parse("5eb09b45-9c70-4465-b62d-535e28b16aed"), AssigneeId = Guid.Parse("0f294219-704d-40a5-afe9-a74fffa7003f"), AssigneeName = "Oli", CreatedBy = Guid.Parse("0f294219-704d-40a5-afe9-a74fffa7003f"), Description = "Stub Super Story", DueBy = DateTime.Now.AddHours(1), EstimatedTime = 1, AgileItemType = Models.Types.AgileItemType.SuperStory, Order = null, Priority = Models.Types.Priority.High, Title = "A stub creation of a story", CreatedOn = DateTime.Now, IsActive = true, IsComplete = false, Status = Models.Types.Status.InProgress, BoardId = Guid.Parse("aada6f2a-8854-4a5e-a907-2244f43408a1"), }; _stubStoryDto = new AgileItemDto { Id = Guid.Parse("5eb09b45-9c70-4465-b62d-535e28b16aee"), AssigneeId = Guid.Parse("0f294219-704d-40a5-afe9-a74fffa7003f"), AssigneeName = "Oli", CreatedBy = Guid.Parse("0f294219-704d-40a5-afe9-a74fffa7003f"), Description = "Stub Story", DueBy = DateTime.Now.AddHours(1), EstimatedTime = 1, AgileItemType = Models.Types.AgileItemType.Story, Order = null, Priority = Models.Types.Priority.High, Title = "A stub creation of a story", CreatedOn = DateTime.Now, IsActive = true, IsComplete = false, Status = Models.Types.Status.InProgress, ParentId = Guid.Parse("5eb09b45-9c70-4465-b62d-535e28b16aed"), BoardId = Guid.Parse("aada6f2a-8854-4a5e-a907-2244f43408a1"), }; _stubBoard = new BoardDto { Id = Guid.Parse("aada6f2a-8854-4a5e-a907-2244f43408a1"), BoardStart = DateTime.Now, BoardEnd = DateTime.Now.AddDays(7), BoardName = "Stub board", IsActive = true }; _mockLogger = new Mock <ILogger <AgileItemRepository> >(); _agileItemRepository = new AgileItemRepository(GetInMemoryContextWithSeedData(), _mockLogger.Object); }