コード例 #1
0
        public async Task <IActionResult> AddOffer(int schoolId, OfferForCreateDto offerForCreateDto)
        {
            var school = await database.SchoolRepository.Get <School>(schoolId);

            int currentUserId = int.Parse(HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value);

            if (currentUserId != school.OwnerId)
            {
                return(this.Forbidden("Nie jesteś właścicielem tej szkółki"));
            }

            var offer   = mapper.Map <Offer>(offerForCreateDto);
            var package = mapper.Map <Package>(offerForCreateDto.PackageForCreateDto);

            if (await schoolService.AddOffer(offer, school, package))
            {
                var offerToReturn = mapper.Map <OfferDetailsDto>(offer);

                await notificationSystem.PushNotificationToUsersByFollows(StaticExpressions.OfferCreated(school.Name, offer.Name), school);

                return(Ok(offerToReturn));
            }

            return(BadRequest("Nie udało się dodać oferty"));
        }