public async Task <IActionResult> CreateApplication(CreateApplicationDto application)
        {
            UsersApplications app = await _mediator.Send(new CreateCommand(application.Name, application.Code, application.Description));

            ApplicationDTO response = new ApplicationDTO(app);

            return(Ok(response));
        }
示例#2
0
        public async Task CreateApplicationCommandHandler_Handel_ShouldReturnUpdatedValueOfApplication()
        {
            var createApplicationModel = new CreateApplicationDto
            {
                Description = "Application to store the feedback of users"
            };
            var createApplicationCommand = new CreateApplicationCommand(createApplicationModel);
            var updateApplication        =
                await _createApplicationCommandHandler.Handle(createApplicationCommand, CancellationToken.None);

            Assert.True(default(Guid) != updateApplication.Id);
        }
示例#3
0
        public async Task <ActionResult> ApplicationReject(CreateApplicationDto applicationDto)
        {
            var user = await _context.Users.SingleOrDefaultAsync(x => x.UserName == applicationDto.UserName);

            var app = await _context.Applications.SingleOrDefaultAsync(x => x.AppUserId == user.Id);

            app.ApplicationStatusId = 1;

            await _context.SaveChangesAsync();

            return(Ok());
        }
        public async Task It_should_create()
        {
            CreateApplicationDto testApp = new CreateApplicationDto()
            {
                Code = Guid.NewGuid().ToString(), Name = Guid.NewGuid().ToString()
            };

            using TestServer server = TestServer(UserRole.Administrator);
            using HttpClient client = server.CreateHttpClient();
            HttpResponseMessage result = await client.PostAsync("feature/application", testApp.Serialize());

            Assert.Equal(HttpStatusCode.OK, result.StatusCode);
        }
        public async Task It_should_Forbidden()
        {
            CreateApplicationDto testApp = new CreateApplicationDto()
            {
                Code = Guid.NewGuid().ToString(), Name = Guid.NewGuid().ToString()
            };

            using TestServer server = TestServer(UserRole.Administrator);
            using HttpClient client = server.CreateHttpClient();
            HttpResponseMessage result = await client.GetAsync("feature/application/notcode");

            Assert.Equal(HttpStatusCode.NotFound, result.StatusCode);
        }
示例#6
0
        public ActionResult <ApplicationDto> CreateApplication(Guid personId, [FromBody] CreateApplicationDto dto)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest());
                }
                if (!_db.Person.BelongsToUser(personId, HttpContext))
                {
                    return(Forbid());
                }

                var shift = _db.Shift
                            .FindByCondition(x => x.Id == dto.ShiftId)
                            .Include(x => x.Category)
                            .SingleOrDefault();
                if (shift == null)
                {
                    return(BadRequest());
                }
                if (_db.Participation.GetRole(personId, shift.Category.ProjectId)?.CalendarRead != true)
                {
                    return(Forbid());
                }
                if (_db.Participation.GetEligibilityByCategory(personId, shift.Category.ProjectId, shift.CategoryId)?.ShiftsRead != true)
                {
                    return(Forbid());
                }

                var application = _mapper.Map <Application>(dto);
                application.PersonId = personId;
                application.ShiftId  = dto.ShiftId;

                _db.Application.Create(application);
                _db.Save();

                var createdApplication = _db.Application
                                         .FindByCondition(x => x.Id == application.Id)
                                         .Include(x => x.Person).ThenInclude(x => x.Congregation)
                                         .Single();

                return(Ok(_mapper.Map <ApplicationDto>(createdApplication)));
            }
            catch (Exception e)
            {
                _logger.LogError($"ERROR in CreateApplication: {e.Message}");
                return(StatusCode(500, "Internal server error"));
            }
        }
示例#7
0
        public async Task <Result> Create(CreateApplicationDto dto)
        {
            await _applicationRepository.Insert(new Application()
            {
                AdvertId    = dto.AdvertId,
                DateCreated = DateTime.UtcNow,
                Phone       = dto.Phone,
                Email       = dto.Email
            });

            await _statisticRepository.Increment(dto.AdvertId, AdvertStatisticType.Filled);

            return(new());
        }
        public ValidationResult ValidateCreateApplicationDto(CreateApplicationDto dto)
        {
            if (dto == null)
            {
                throw new ArgumentNullException(ArgumentExceptionResources.CreateApplicationDtoNotFound);
            }
            var validationResult = new ValidationResult("Создание новой заявки");

            var car = _unitOfWork.Repository <IUserCarRepository>().Get(dto.CarId);

            if (car == null)
            {
                validationResult.AddError(ValidationErrorResources.UserCarNotFound);
            }

            var city = _unitOfWork.Repository <ICityRepository>().Get(dto.CityId);

            if (city == null)
            {
                validationResult.AddError(ValidationErrorResources.CityNotFound);
            }

            if (string.IsNullOrEmpty(dto.Description))
            {
                validationResult.AddError(ValidationErrorResources.ApplicationDescriptionIsEmpty);
            }

            if (dto.WorkTypes != null && dto.WorkTypes.Any())
            {
                var repository = _unitOfWork.Repository <IWorkTypeRepository>();
                foreach (var workTypeId in dto.WorkTypes)
                {
                    var workType = repository.Get(workTypeId);
                    if (workType == null)
                    {
                        validationResult.AddError(string.Format(ValidationErrorResources.WorkTypeNotFound, workType));
                    }
                }
            }

            return(validationResult);
        }
示例#9
0
        public async Task <ActionResult> ApplicationApproval(CreateApplicationDto applicationDto)
        {
            // APPLICATION DTO SHOULD MATCH EXACTLY AS CLIENT SIDE

            // string email = "*****@*****.**";
            // int inputmail = 4;
            //var acc = new AccountController(_context, _tokenService, _mapper);

            var user = await _context.Users.SingleOrDefaultAsync(x => x.UserName == applicationDto.UserName);

            var app = await _context.Applications.SingleOrDefaultAsync(x => x.AppUserId == user.Id);

            //user.FirstName = "Aoife";
            // if (await UserExists(registerDto.Email)) return BadRequest("Email already exists");

            // ApplicationDto applicationDto = new ApplicationDto();

            // var application = _mapper.Map<ApplicationData>(applicationDto);


            //application.ApplicationStatusId = 1;
            // application.Id = user.Id;

            user.ApplicationSubmitted = false;
            app.ApplicationStatusId   = 2;

            // _context.Applications.Add(application);
            await _context.SaveChangesAsync();

            // _userRepository.UpdateApplication(application);

            // return new CreateApplicationDto
            // {
            //     Issue = application.Issue,
            //     Course = application.Course,
            //     ApplicationStatusId = application.ApplicationStatusId,
            //     AppUserId = application.AppUserId

            // };

            return(Ok());
        }
        public void CreateApplication(CreateApplicationDto dto, string currentUserId)
        {
            UserManager.IsUserInRegularRole(currentUserId);

            var validationResult = _validationManager.ValidateCreateApplicationDto(dto);

            if (validationResult.HasErrors)
            {
                throw new BusinessFaultException(validationResult.GetErrors());
            }

            var application = Mapper.Map <Application>(dto);

            var car = UnitOfWork.Repository <IUserCarRepository>().Get(dto.CarId);

            if (!car.IsBelongToUser(currentUserId))
            {
                throw new BusinessFaultException(BusinessLogicExceptionResources.CarDoesNotBelongToUser);
            }

            application.Car  = car;
            application.City = UnitOfWork.Repository <ICityRepository>().Get(dto.CityId);

            if (application.Car.Applications == null)
            {
                application.Car.Applications = new List <Application>();
            }

            if (dto.WorkTypes != null && dto.WorkTypes.Any())
            {
                var repository = UnitOfWork.Repository <IWorkTypeRepository>();
                application.WorkTypes = new List <WorkType>();
                foreach (var work in dto.WorkTypes)
                {
                    application.WorkTypes.Add(repository.Get(work));
                }
            }

            application.Car.Applications.Add(application);
            UnitOfWork.SaveChanges();
        }
示例#11
0
        public async Task CreateApplicationCommandHandler_Handel_ShouldThrowAnExceptionIfApplicationNameIsAlreadyExistAndIgnoreCase()
        {
            var createApplicationDto = new CreateApplicationDto
            {
                Name = "Application"
            };

            Context.Applications.Add(new Domain.Entities.Application
            {
                Name = "appLication"
            });
            Context.Applications.Add(new Domain.Entities.Application
            {
                Name = "Application 1"
            });
            Context.SaveChanges();

            var createApplicationCommand = new CreateApplicationCommand(createApplicationDto);
            await Assert.ThrowsAsync <RecordAlreadyExistsException>(() =>
                                                                    _createApplicationCommandHandler.Handle(createApplicationCommand, CancellationToken.None));
        }
示例#12
0
        public async Task <ActionResult <UserDto> > Application(CreateApplicationDto applicationDto)
        {
            //var acc = new AccountController(_context, _tokenService, _mapper);

            var user = await _context.Users.SingleOrDefaultAsync(x => x.UserName == applicationDto.UserName);

            // if (await UserExists(registerDto.Email)) return BadRequest("Email already exists");

            var application = _mapper.Map <ApplicationData>(applicationDto);

            application.Issue  = applicationDto.Issue;
            application.Course = applicationDto.Course;
            application.ApplicationStatusId = 3;
            application.TutorId             = 1;
            application.AppUserId           = user.Id;
            user.ApplicationSubmitted       = true;

            _context.Applications.Add(application);
            await _context.SaveChangesAsync();

            // return new CreateApplicationDto
            // {
            //     Issue = application.Issue,
            //     Course = application.Course,
            //     ApplicationStatusId = application.ApplicationStatusId,
            //     AppUserId = application.AppUserId

            // };
            return(new UserDto
            {
                Id = user.Id,
                UserName = user.UserName,
                Token = _tokenService.CreateToken(user),
                FirstName = user.FirstName,
                LastName = user.LastName,
                UserType = user.UserTypeId,
                CheckEmail = user.Email,
                CheckApplicationStatus = true
            });
        }
示例#13
0
 public ApplicationCannotBeCreatedWithDuplicateNameBusinessRule(IQueryable <Application> applications, CreateApplicationDto createDto)
 {
     _applications = applications;
     _createDto    = createDto;
 }
示例#14
0
 public Task <CreateApplicationDto> Create(CreateApplicationDto createApplication)
 {
     return(Mediator.Send(new CreateApplicationCommand(createApplication)));
 }
示例#15
0
 public CreateApplicationCommand(CreateApplicationDto application)
 {
     ApplicationCreateDto = application;
 }
 public IHttpActionResult Create(CreateApplicationDto dto)
 {
     return(CallBusinessLogicAction(() => _manager.CreateApplication(dto, User.Identity.GetUserId())));
 }
        public async Task <IActionResult> CreateApplication([FromBody] CreateApplicationDto createDto)
        {
            var response = await _mediator.Send(new CreateApplicationCommand(createDto));

            return(Ok(response));
        }
示例#18
0
        public async Task <IActionResult> Post(CreateApplicationDto createApplication)
        {
            var savedApplication = await _applicationService.Create(createApplication);

            return(Ok(savedApplication));
        }