Exemple #1
0
        public async Task <BaseResult> CreateEvent(EventViewModel model, string organaizerId)
        {
            if (!dbRepository.Organizers.Any(x => x.OrganizerId == organaizerId))
            {
                return(new ErrorResult("Organizer not found"));
            }

            var _event = mapper.Map <Event>(model);

            _event.OrganizerId = organaizerId;

            await LoadFileToEvent(_event, model.ImageFile);

            var result = await dbRepository.CreateAndSaveEntityAsync(_event);

            if (!result)
            {
                return(new ErrorResult("Failed to save in DataBase"));
            }

            return(new OkResult());
        }
Exemple #2
0
        public async Task <RegisterResult> RegisterCompany(RegisterOrganaizerViewModel model, string userId)
        {
            var user = await userManager.FindByIdAsync(userId);

            if (user is null)
            {
                return(new RegisterResult("User not found"));
            }

            if (await repository.Organizers.AnyAsync(x => x.OrganizerId == userId))
            {
                return(new RegisterResult("You are organizer already!"));
            }

            var organaizer = new Organizer
            {
                User      = user,
                InstType  = model.InstType,
                PlaceName = model.PlaceName,
                Position  = model.Position,
                TelNumber = model.TelNumber
            };

            var complete = await repository.CreateAndSaveEntityAsync(organaizer);

            if (!complete)
            {
                return(new RegisterResult("Failed save to DataBase"));
            }

            await CheckRoleExists(AppRoles.organaizerRole);

            await userManager.AddToRoleAsync(user, AppRoles.organaizerRole);

            return(new RegisterResult());
        }