public SuccessResponse <LabelDto> CreateLabel([FromBody] CreateLabelDto createLabelDto)
        {
            var label    = _mapper.Map <Label>(createLabelDto);
            var response = _labelService.CreateLabel(label);

            return(new SuccessResponse <LabelDto>(_mapper.Map <LabelDto>(response)));
        }
Exemple #2
0
        /// <summary>
        /// Adds the specified label dto.
        /// </summary>
        /// <param name="labelDto">The label dto.</param>
        /// <returns></returns>
        public async Task <LabelDto> Add(CreateLabelDto labelDto)
        {
            Label label = _mapper.Map <Label>(labelDto);

            label = _labelRepository.Add(label);
            await _labelRepository.Save();

            return(_mapper.Map <LabelDto>(label));
        }
Exemple #3
0
        /// <summary>
        /// adds label in Label table
        /// </summary>
        /// <param name="createLabelDto"></param>
        /// <returns> added label record Dto. </returns>
        public async Task <LabelDto> AddLabel(CreateLabelDto createLabelDto)
        {
            LabelDbModel labelDbDto = _mapper.Map <LabelDbModel>(createLabelDto);

            labelDbDto.CreatedBy = createLabelDto.CreatedBy;
            _toDoDbContext.Labels.Add(labelDbDto);
            await _toDoDbContext.SaveChangesAsync();

            return(_mapper.Map <LabelDto>(labelDbDto));
        }
Exemple #4
0
        /// <summary>
        /// Adds Label record
        /// </summary>
        /// <param name="createLabelDto"></param>
        /// <returns> added ToDoList record. </returns>
        public async Task <LabelDto> AddLabel(CreateLabelDto createLabelDto)
        {
            if (createLabelDto != null)
            {
                createLabelDto.CreatedBy = _userId;
            }
            LabelDto addedItem = await _labelDbOps.AddLabel(createLabelDto);

            return(addedItem);
        }
        public void CreateLabel_ShouldCallCreateLabel()
        {
            // Arrange
            var input = new CreateLabelDto();

            // Act
            controller.AssignLabel(input);

            // Assert
            todoItemLogic.Verify(u => u.CreateLabel(1, It.Is <CreateLabelDto>(c => c == input)));
        }
        public void CreateLabel_ShouldCallCreateLabel()
        {
            // Arrange
            var input = new CreateLabelDto();

            // Act
            logic.CreateLabel(1, input);

            // Assert
            todoItemRepository.Verify(t => t.CreateLabel(1, input));
        }
        public void CreateLabel_ShouldMapResultToDto()
        {
            // Arrange
            var input = new CreateLabelDto();

            // Act
            logic.CreateLabel(1, input);

            // Assert
            mapper.Verify(t => t.Map <LabelDto>(It.IsAny <Label>()));
        }
        public void CreateLabel_ShouldReturnBadRequestWhenCreateLabelReturnsNull()
        {
            // Arrange
            var input = new CreateLabelDto();

            // Act
            var result = controller.AssignLabel(input);

            // Assert
            Assert.IsType <BadRequestObjectResult>(result);
            var response = (result as BadRequestObjectResult).Value as ErrorResponse;

            Assert.Equal("User or item not found in the database.", response.Message);
        }
        public void CreateLabel_ShouldReturnCreatedLabel()
        {
            // Arrange
            var input = new CreateLabelDto();
            var model = new LabelDto();

            todoItemLogic.Setup(u => u.CreateLabel(1, It.Is <CreateLabelDto>(c => c == input))).Returns(model);

            // Act
            var result = controller.AssignLabel(input);

            // Assert
            Assert.IsType <CreatedAtActionResult>(result);
        }
Exemple #10
0
        public void CreateLabel_ShouldReturnNullIfItemIsNotFound()
        {
            // Arrange
            var dbContext  = SetupDatabase(nameof(CreateLabel_ShouldReturnNullIfItemIsNotFound));
            var repository = new TodoItemRepository(dbContext);
            var input      = new CreateLabelDto
            {
                ParentId = 20,
                Label    = "Cheese"
            };

            // Act
            var result = repository.CreateLabel(1, input);

            // Assert
            Assert.Null(result);
        }
Exemple #11
0
        /// <summary>
        /// Creates a label for todo item.
        /// </summary>
        /// <param name="userId">User id</param>
        /// <param name="createLabelDto">label for todo item to be created</param>
        /// <returns>Label dto</returns>
        public Label CreateLabel(int userId, CreateLabelDto createLabelDto)
        {
            var user = dbContext.Users.FirstOrDefault(u => u.UserId == userId);

            if (user == null)
            {
                return(null);
            }

            var existingItem = dbContext.TodoItems
                               .Include(l => l.Labels)
                               .FirstOrDefault(u => u.Id == userId && u.Id == createLabelDto.ParentId);

            if (existingItem == null)
            {
                return(null);
            }

            // if label already exists return that label instead of creating new
            var existingLabel = existingItem.Labels.FirstOrDefault(l => l.Name == createLabelDto.Label);

            if (existingLabel != null)
            {
                return(existingLabel);
            }

            var label = new Label
            {
                Name         = createLabelDto.Label,
                user         = user,
                LastModified = DateTime.Now
            };

            if (existingItem.Labels == null)
            {
                existingItem.Labels = new List <Label>();
            }

            existingItem.Labels.Add(label);

            dbContext.SaveChanges();

            return(label);
        }
        public async Task <IActionResult> CreateLabel(CreateLabelModel createLabelModel, ApiVersion version)
        {
            long userId = long.Parse(HttpContext.Items["UserId"].ToString());

            if (createLabelModel == null || string.IsNullOrWhiteSpace(createLabelModel.Description))
            {
                return(BadRequest(new ApiResponse <string>
                {
                    IsSuccess = false,
                    Result = "Not Updated.",
                    Message = "Please enter correct values. Description should not be empty."
                }));
            }
            createLabelModel.CreatedBy = userId;
            CreateLabelDto createLabelDto = _mapper.Map <CreateLabelDto>(createLabelModel);
            LabelDto       createdLabel   = await _labelContract.AddLabel(createLabelDto);

            return(CreatedAtAction(nameof(GetLabelById), new { createdLabel.LabelId, version = $"{version}" }, createdLabel));
        }
        public async Task <IActionResult> Add(CreateLabelDto labelDto, ApiVersion version)
        {
            int userId = int.Parse(HttpContext.Items["UserId"].ToString());

            if (labelDto == null || string.IsNullOrWhiteSpace(labelDto.Description))
            {
                return(BadRequest(new ResponseModel <string>
                {
                    IsSuccess = false,
                    Result = "Not Updated.",
                    Message = "Invalid request, Mandatory fields not provided in request."
                }));
            }
            labelDto.CreatedBy = userId;
            labelDto.UserId    = userId;
            LabelDto createdLabel = await _labelService.Add(labelDto);

            return(CreatedAtAction(nameof(GetById), new { id = createdLabel.LabelId, version = $"{version}" }, createdLabel));
        }
Exemple #14
0
        public void CreateLabel_ShouldCreateLabel()
        {
            // Arrange
            var dbContext  = SetupDatabase(nameof(CreateLabel_ShouldCreateLabel));
            var repository = new TodoItemRepository(dbContext);
            var input      = new CreateLabelDto
            {
                ParentId = 1,
                Label    = "Test label"
            };

            // Act
            var result = repository.CreateLabel(1, input);

            // Assert
            Assert.NotNull(result);
            var item = dbContext.Labels.FirstOrDefault(t => t.Name == "Test label");

            Assert.NotNull(item);
        }
        public IActionResult AssignLabel(CreateLabelDto input)
        {
            var userId = int.Parse(httpContextAccessor.HttpContext.User.FindFirst(Constants.UserIdClaim)?.Value);
            var result = todoItemLogic.CreateLabel(userId, input);

            if (result == null)
            {
                return(BadRequest(new ErrorResponse
                {
                    Status = false,
                    Message = "User or item not found in the database."
                }));
            }
            else
            {
                return(CreatedAtAction(nameof(GetItemById), new { result.Id }, new Response <LabelDto>
                {
                    Status = true,
                    Model = result
                }));
            }
        }
Exemple #16
0
 /// <summary>
 /// adds label record to label table.
 /// </summary>
 /// <param name="createLabelDto"></param>
 /// <returns> Added Label record. </returns>
 public async Task <LabelDto> AddLabel(CreateLabelDto createLabelDto)
 {
     return(await _labelDbOps.AddLabel(createLabelDto));
 }
Exemple #17
0
 /// <summary>
 /// Adds the specified label dto.
 /// </summary>
 /// <param name="labelDto">The label dto.</param>
 /// <returns></returns>
 public async Task <LabelDto> Add(CreateLabelDto labelDto)
 {
     return(await _labelRepository.Add(labelDto));
 }
Exemple #18
0
        public Label AssignLabelToItem(CreateLabelDto createLabelDto)
        {
            var userId = CheckAuthentication();

            return(todoItemRepository.CreateLabel(userId, createLabelDto));
        }
        /// <summary>
        /// Creates a label for todo item.
        /// </summary>
        /// <param name="userId">User id</param>
        /// <param name="createLabelDto">label for todo List to be created</param>
        /// <returns>Label dto</returns>
        public LabelDto CreateLabel(int userId, CreateLabelDto createLabelDto)
        {
            var dbLabel = todoItemRepository.CreateLabel(userId, createLabelDto);

            return(mapper.Map <LabelDto>(dbLabel));
        }