/// <summary> /// Gets Label item by Id from database. /// </summary> /// <param name="labelId"></param> /// <param name="userId"></param> /// <returns>Label item by Id for logged in user</returns> public async Task <LabelDto> GetLabelById(long labelId, long userId) { LabelDbModel LabelDbDto = await _toDoDbContext.Labels .FirstOrDefaultAsync(p => p.LabelId == labelId && p.CreatedBy == userId); return(_mapper.Map <LabelDto>(LabelDbDto)); }
/// <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)); }
/// <summary> /// Delete Label record based on LabelId passed. /// </summary> /// <param name="labelId"></param> /// <param name="userId"></param> /// <returns> 1 if success else -1. </returns> public async Task <int> DeleteLabel(long labelId, long userId) { LabelDbModel labelDbDto = await _toDoDbContext.Labels .FirstOrDefaultAsync(p => p.LabelId == labelId && p.CreatedBy == userId); if (labelDbDto == null) { return(0); } _toDoDbContext.Labels.Remove(labelDbDto); return(await _toDoDbContext.SaveChangesAsync()); }