Exemplo n.º 1
0
        public async Task <VisitDto> Handle(CreateVisitCommand request, CancellationToken cancellationToken)
        {
            var visit = Visit.Create(request.VisitDate, request.UserId, request.PlaceId);
            await _visitRepository.CreateAsync(visit);

            return(new VisitDto(visit.VisitId));
        }
Exemplo n.º 2
0
        public async Task <IHttpActionResult> Add(AddVisitBindingModel model)
        {
            try
            {
                VisitTerm visitTerm = await _unitOfWork.VisitTermRepository.AddVisitTermOrReturnIfExists(model.StartDate);

                Visit visit = Visit.Create(model.ServiceId, visitTerm.Id, User.Identity.GetUserId(), model.StartDate);
                visit = _mapper.Map(model, visit);

                await _unitOfWork.VisitRepository.Add(visit);

                await _unitOfWork.CompleteAsync();

                var addedVisit = await _unitOfWork.VisitRepository.FindWithCustomerAndServiceAsync(visit.Id);

                var result = _mapper.Map <VisitInfoBindingModel>(addedVisit);

                return(Ok(result));
            }
            catch (VisitCurrentlyReservedException e)
            {
                ModelState.AddModelError("model.StartDate", "Podana data została już zarezerwowana!");
                return(BadRequest(ModelState));
            }
            catch (Exception e)
            {
                _logger.Error(e);
                return(InternalServerError());
            }
        }
Exemplo n.º 3
0
 public List <Visit> GetVisits()
 {
     return(new List <Visit>()
     {
         Visit.Create(1, 1, 1, "custo_id", DateTime.Now),
         Visit.Create(2, 2, 2, "custo2_id", DateTime.Now.AddYears(1)),
         Visit.Create(3, 3, 3, "custo3_id", DateTime.Now.AddYears(-2))
     });
 }
        private IEnumerable <Visit> PrepareVisitsForTest(string customerId)
        {
            List <Visit> visits = new List <Visit>();

            for (int i = 1; i <= GetServicesForTest().Count(); i++)
            {
                visits.Add(Visit.Create(i, 1, customerId, GetVsisitTermForTest().StartDate.AddMinutes(Constants.Constants.VISIT_TIME)));
            }
            return(visits);
        }
Exemplo n.º 5
0
        public async Task IsReserved_ShouldReturnFalseIfTermNotReserved()
        {
            // Arrange
            Visit visit = Visit.Create(1, 1, "custId", DateTime.Now);

            // Act
            var reserved = await _unitOfWork.VisitRepository.IsReserved(visit.StartDate);

            // Assert
            Assert.IsFalse(reserved);
        }
        private IEnumerable <Visit> GetVisits(IEnumerable <VisitTerm> visitTerms, IEnumerable <Customer> users, IEnumerable <Service> services)
        {
            List <Visit> visits = new List <Visit>();

            foreach (var v in visitTerms)
            {
                DateTime date = v.StartDate;
                foreach (var u in users)
                {
                    date.AddMinutes(Constants.Constants.VISIT_TIME);
                    visits.Add(Visit.Create(1, v.Id, u.Id, date));
                }
            }
            return(visits);
        }
Exemplo n.º 7
0
        public async Task Add_ShouldAddVisitIfCorrect()
        {
            // Arrange
            var visitTerm = await _context.VisitTerms.FirstAsync();

            var service = await _context.Services.FirstAsync();

            var user = await _context.Users.FirstAsync();

            Visit visit = Visit.Create(service.Id, visitTerm.Id, user.Id, visitTerm.EndDate.AddHours(-Constants.Constants.VISIT_TIME));

            // Act
            await _unitOfWork.VisitRepository.Add(visit);

            await _unitOfWork.CompleteAsync();

            // Assert
            Assert.AreNotEqual(visit.Id, 0);
            Assert.AreNotEqual(visit.Id, Guid.Empty);
        }
Exemplo n.º 8
0
 public Visit GetVisit()
 {
     return(Visit.Create(1, GetService().Id, GetCustomer().Id, GetVisitTerm().StartDate));
 }