Ejemplo n.º 1
0
        public void CreateVisit(IVisitDto visit)
        {
            if (visit == null)
            {
                throw new ArgumentNullException("visit");
            }

            _context.Visits.Add((VisitDto) visit);
            _context.SaveChanges();
        }
Ejemplo n.º 2
0
        public async Task UpdateVisitAsync(IVisitDto visit)
        {
            if (visit == null)
            {
                throw new ArgumentNullException("visit");
            }

            VisitDto oldVisit = await _context.Visits.SingleOrDefaultAsync(v => v.LessonId == visit.LessonId && v.UserId == visit.UserId);
            oldVisit.Status = visit.Status;
            oldVisit.Note = visit.Note;
            
            await _context.SaveChangesAsync();
        }
        public void AddVisit(IVisitDto visitDto)
        {
            Guard.WhenArgument(visitDto, "VisitDto can not be null").IsNull().Throw();

            var visitToAdd = this.mapper.Map <Visit>(visitDto);

            if (!this.dbContext.Visits.Any(v => v.ClientId == visitDto.ClientId && v.CreatedOn.Day == visitDto.CreatedOn.Day))
            {
                this.dbContext.Visits.Add(visitToAdd);
                this.dbContext.SaveChanges();
            }
            else
            {
                throw new ArgumentException("A client with this ClientId has already used his daily visit!");
            }
        }
        public string Execute(IList <string> parameters)
        {
            string clientFirstName;
            string clientLastName;
            Guid   clientId;
            string companyName;
            Guid   companyId;
            string sportshallName;
            Guid   sportshallId;
            string sportName;
            Guid   sportId;

            try
            {
                clientFirstName = parameters[0];
                clientLastName  = parameters[1];
                companyName     = parameters[2];
                sportshallName  = parameters[3];
                sportName       = parameters[4];
            }
            catch
            {
                throw new ArgumentException("Failed to parse AddVisit command parameters.");
            }

            Guard.WhenArgument(companyName, "Company name").IsNullOrEmpty().Throw();
            companyId = this.clientService.GetCompanyGuidByName(companyName);

            Guard.WhenArgument(clientFirstName, "Client's first name").IsNullOrEmpty().Throw();
            Guard.WhenArgument(clientLastName, "Client's last name").IsNullOrEmpty().Throw();
            clientId = this.visitService.GetClientGuidByNamesAndCompanyId(clientFirstName, clientLastName, companyId);

            Guard.WhenArgument(sportshallName, "Sportshall name").IsNullOrEmpty().Throw();
            sportshallId = this.visitService.GetSportshallGuidByName(sportshallName);

            Guard.WhenArgument(sportName, "Sport name").IsNullOrEmpty().Throw();
            sportId = this.visitService.GetSportGuidByName(sportName);

            IVisitDto visit = this.SportscardFactory.CreateVisitDto(clientId, sportshallId, sportId);

            visitService.AddVisit(visit);

            return($"The visit was added to database.");
        }