Esempio n. 1
0
        public async Task <bool> SendReport(Report report, ReportMessage reportMessage, User user)
        {
            if (report == null || user == null || reportMessage == null)
            {
                throw new EntityNotFoundException();
            }

            if (user.Reports.Count == 3)
            {
                return(false);
            }

            user.Reports.Add(report);
            user.ReportMessages.Add(reportMessage);
            report.ReportMessages.Add(reportMessage);

            if (!await database.Complete())
            {
                return(false);
            }

            await notificationSystem.PushNotificationToUsersByRoles(StaticExpressions.NewReportCreated(user.UserName), AdminRoles);

            return(true);
        }
        public async Task <IActionResult> CreateSchool([FromForm] SchoolForCreateDto schoolForCreateDto)
        {
            if (schoolForCreateDto.Logo != null &&
                !filesUploader.IsValidExtension(schoolForCreateDto.Logo.FileName, PhotoExtensions))
            {
                return(BadRequest("Logo posiada niepoprawny format"));
            }

            int currentUserId = int.Parse(HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value);
            var currentUser   = await database.UserRepository.Get <User>(currentUserId);

            var school = mapper.Map <School>(schoolForCreateDto);

            if (currentUser.Rental != null)
            {
                school.SetRental(currentUser.Rental);
            }

            if (await schoolService.CreateSchool(school, currentUserId))
            {
                await SetLogoUrl(schoolForCreateDto.Logo, school);

                await notificationSystem.PushNotification(currentUserId, StaticExpressions.SchoolCreated(school.Name));

                await notificationSystem.PushNotificationToUsersByRoles(StaticExpressions.SchoolCreated(school.Owner.UserName, school.Name, school.Id),
                                                                        RolesPermitted, NotificationType.School);

                var schoolToReturn = mapper.Map <SchoolDetailsDto>(school);

                return(Ok(schoolToReturn));
            }

            return(BadRequest("Dodawanie szkółki nie powiodło się"));
        }