Ejemplo n.º 1
0
        public async Task <IActionResult> UpdateOffer(int schoolId, int offerId, OfferForUpdateDto offerForUpdateDto)
        {
            var school = await database.SchoolRepository.Get <School>(schoolId);

            var offer = school.Offers.FirstOrDefault(o => o.Id == offerId);

            if (offer == null)
            {
                throw new EntityNotFoundException("Oferta");
            }

            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"));
            }

            offer = mapper.Map <OfferForUpdateDto, Offer>(offerForUpdateDto, offer);

            if (await database.Complete())
            {
                await notificationSystem.PushNotificationToUsersByFollows(StaticExpressions.OfferUpdated(school.Name, offer.Name), school);

                return(NoContent());
            }

            return(BadRequest("Nie udało się zaktualizować ofery"));
        }