public IActionResult ResponseForCreate(Result result, int userId, FeedCollectionDtoForCreate feedCollectionDtoForCreate) { switch (result.IsFailure) { case true: return(new BadRequestObjectResult(result.Message)); default: return(new CreatedAtRouteResult("GetFeedCollection", new { feedCollectionId = ((Result <int>)result).Value, userId }, feedCollectionDtoForCreate)); } }
public async Task <Result> AddAsync(int userId, FeedCollectionDtoForCreate feedCollectionDtoForCreate) { if (!await _unitOfWork.Users.ContainsEntityWithId(userId)) { return(Result.Fail("User doesn't exist")); } if (string.IsNullOrEmpty(feedCollectionDtoForCreate.Name)) { return(Result.Fail("Invalid name")); } if (await _unitOfWork.FeedCollections.ContainsFeedCollectionWithName(feedCollectionDtoForCreate.Name, userId)) { return(Result.Fail("Feed collection with this name already exists")); } var feedCollection = _mapper.Map <FeedCollection>(feedCollectionDtoForCreate); feedCollection.UserId = userId; await _unitOfWork.FeedCollections.AddAsync(feedCollection); await _unitOfWork.SaveChangesAsync(); return(Result.Ok(feedCollection.Id)); }