Пример #1
0
        public async Task <ServiceResult <CatFeedingModel> > FeedAsync(CatFeedingCreateModel info)
        {
            CatInDbModel cat = await catDatabase.GetAsync(info.CatId);

            if (cat == null)
            {
                return(new ServiceResult <CatFeedingModel>(ServiceResultStatus.ItemNotFound, "Cat is not found"));
            }

            UserInDbModel user = await userDatabase.GetAsync(info.UserId);

            if (user == null)
            {
                return(new ServiceResult <CatFeedingModel>(ServiceResultStatus.ItemNotFound, "User is not found"));
            }

            if (!await catSharingDatabase.IsCatSharedWithUserAsync(info.UserId, info.CatId))
            {
                return(new ServiceResult <CatFeedingModel>(ServiceResultStatus.ActionNotAllowed, "You cannot feed this cat"));
            }

            await catFeedingdatabase.CreateAsync(mapper.Map <CatFeedingCreateInDbModel, CatFeedingCreateModel>(info));

            return(new ServiceResult <CatFeedingModel>(ServiceResultStatus.NoContent));
        }
Пример #2
0
 public async Task <bool> IsCatSharedWithUser(int userId, int catId)
 {
     return(await catSharingDatabase.IsCatSharedWithUserAsync(userId, catId));
 }