public async Task IsUniqueOnCreate(string insertedInDb, string insertedInCommand)
        {
            var result = await _context.AddAsync(InstanciateEntity(insertedInDb));

            _context.SaveChanges();

            _mediator.Send(new CreateProfilOptionCommand <TProfilOption> {
                Name = insertedInCommand
            })
            .ShouldThrow(typeof(ValidationException));
        }
Exemple #2
0
        private async Task Log(CancellationToken cancellationToken, TRequest request, string info = null)
        {
            var    username = _httpContext.HttpContext?.User?.Identity.Name;
            string userId   = null;

            if (username != null)
            {
                if (!_cache.TryGetValue <string>(username, out userId))
                {
                    userId = (await _userManager.FindByNameAsync(username)).Id;
                    _cache.CreateEntry(username);
                    _cache.Set <string>(username, userId);
                }
            }

            await _context.AddAsync(new Log
            {
                UserId      = userId,
                UserName    = username,
                DateTime    = DateTime.Now,
                CommandName = CommandName(typeof(TRequest)),
                CommandJSON = JsonConvert.SerializeObject(request),
                Information = info
            });

            await _context.SaveChangesAsync(cancellationToken);
        }
Exemple #3
0
        public async Task <Unit> Handle(CreateWorkshopCommand request, CancellationToken cancellationToken)
        {
            var workshop = await _context.AddAsync(new Workshop
            {
                EndDate             = (DateTime)request.EndDate,
                SessionId           = request.SessionId,
                StartDate           = (DateTime)request.StartDate,
                WorkshopDescription = request.WorkshopDescription,
                WorkshopName        = request.WorkshopName,
                WorkshopTypeId      = (int)request.WorkshopTypeId,
                IsOpen = request.IsOpen.Value
            });

            if (request.SeanceCount != null && request.SeanceCount > 0)
            {
                DateTime dateIncrement = request.DateTimeFirstSeance.Value;

                for (int i = 0; i < request.SeanceCount; i++)
                {
                    workshop.Entity.Seances.Add(new Seance
                    {
                        SeanceDate     = dateIncrement,
                        SeanceName     = $"Seance {i+1}",
                        SeanceTimeSpan = request.SeanceLenght.Value
                    });

                    dateIncrement += TimeSpan.FromDays(request.IntervalNbDays.Value);
                }
            }

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
        public async Task <Unit> Handle(CreateProfilOptionCommand <IncomeSource> request, CancellationToken cancellationToken)
        {
            await _context.AddAsync(new IncomeSource { Name = request.Name });

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
        public async Task <Unit> Handle(CreateProfilOptionCommand <CitizenStatus> request, CancellationToken cancellationToken)
        {
            await _context.AddAsync(new CitizenStatus { Name = request.Name });

            await _context.SaveChangesAsync();

            return(Unit.Value);
        }
Exemple #6
0
        public async Task <Unit> Handle(CreateProfilOptionCommand <ChildrenAgeBracket> request, CancellationToken cancellationToken)
        {
            await _context.AddAsync(new ChildrenAgeBracket { Name = request.Name });

            await _context.SaveChangesAsync();

            return(Unit.Value);
        }
Exemple #7
0
        public async Task <Unit> Handle(CreateProfilOptionCommand <SkillToDevelop> request, CancellationToken cancellationToken)
        {
            await _context.AddAsync(new SkillToDevelop { Name = request.Name });

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
Exemple #8
0
        public async Task <Unit> Handle(CreateWorkshopTypeCommand request, CancellationToken cancellationToken)
        {
            await _context.AddAsync(new WorkshopType { Name = request.Name, Code = request.Code });

            await _context.SaveChangesAsync(cancellationToken);

            _memory.Remove("WorkshopTypeList");

            return(Unit.Value);
        }
Exemple #9
0
        public async Task <Unit> Handle(CreateProfilOptionCommand <TransportType> request, CancellationToken cancellationToken)
        {
            await _context.AddAsync(new TransportType
            {
                Name = request.Name,
            });

            await _context.SaveChangesAsync();

            return(Unit.Value);
        }
Exemple #10
0
        public async Task <Unit> Handle(CreateNoteCommand request, CancellationToken cancellationToken)
        {
            var note = new Note
            {
                Body            = request.Body,
                CreationDate    = DateTime.Now,
                CustomerId      = request.CustomerId,
                NoteName        = request.NoteName,
                SupervisorName  = request.SupervisorName,
                SupervisorTitle = request.SupervisorTitle,
                NoteTypeId      = request.NoteTypeId,
            };

            await _context.AddAsync(note);

            await _context.SaveChangesAsync();

            return(Unit.Value);
        }
        public async Task <Unit> Handle(CreateProfilOptionCommand <Availability> request, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(request.Name))
            {
                throw new InvalideNameException($"The name of the new {nameof(Availability)} is empty");
            }
            else if (string.IsNullOrWhiteSpace(request.Name))
            {
                throw new InvalideNameException("The name cannot be fill with witespace");
            }

            await _context.AddAsync(new Availability()
            {
                Name = request.Name
            });

            await _context.SaveChangesAsync();

            return(Unit.Value);
        }
        public async Task <Unit> Handle(CreateVolunteeringCommand request, CancellationToken cancellationToken)
        {
            var volunteering = new Volunteering
            {
                Customer = await _context.Customers.FindAsync(request.CustomerId),
                Type     = await _context.VolunteeringTypes.FindAsync(request.VolunteeringTypeId),

                Acknowledgment = request.Acknowledgment,
                Amount         = DecimalParser.Parse(request.Amount),
                Date           = request.Date,
                Details        = request.Details,
                HourCount      = request.HourCount,
                Title          = request.Title
            };

            await _context.AddAsync(volunteering);

            await _context.SaveChangesAsync();

            return(Unit.Value);
        }
Exemple #13
0
        public async Task <Unit> Handle(CreateSeanceCommand request, CancellationToken cancellationToken)
        {
            var seance = await _context.AddAsync(new Seance
            {
                SeanceDate        = request.SeanceDate.Value,
                SeanceName        = request.SeanceName,
                SeanceTimeSpan    = request.SeanceTimeSpan.Value,
                WorkshopId        = request.WorkshopId.Value,
                SeanceDescription = request.SeanceDescription
            });

            await _context.SaveChangesAsync(cancellationToken);

            var participants = _context.Participants
                               .Where(p => p.WorkshopId == request.WorkshopId.Value)
                               .Select(p => p.CustomerId);

            foreach (var customerId in participants)
            {
                if (!seance.Entity.Participants.Any(p => p.CustomerId == customerId))
                {
                    seance.Entity.Participants.Add(new Participant
                    {
                        WorkshopId = request.WorkshopId.Value,
                        CustomerId = customerId,
                        SeanceId   = seance.Entity.SeanceId
                    });
                }
            }

            await _context.SaveChangesAsync(cancellationToken);

            _memory.Remove(InMemoryKeyConstants.SEANCES_IN_WORKSHOP + request.WorkshopId);

            return(Unit.Value);
        }
Exemple #14
0
        public async Task <Unit> Handle(CreateSessionCommand request, CancellationToken cancellationToken)
        {
            DateTime startDate = new DateTime();

            switch (request.Season)
            {
            case (Season.Winter):
                startDate = new DateTime(request.Year.Value, SessionConstant.WINTER_START_MONTH, SessionConstant.WINTER_START_DAY);
                break;

            case (Season.Spring):
                startDate = new DateTime(request.Year.Value, SessionConstant.SPRING_START_MONTH, SessionConstant.SPRING_START_DAY);
                break;

            case (Season.Summer):
                startDate = new DateTime(request.Year.Value, SessionConstant.SUMMER_START_MONTH, SessionConstant.SUMMER_START_DAY);
                break;

            case (Season.Fall):
                startDate = new DateTime(request.Year.Value, SessionConstant.FALL_START_MONTH, SessionConstant.FALL_START_DAY);
                break;
            }

            await _context.AddAsync(new Session
            {
                Season    = request.Season.Value,
                Year      = request.Year.Value,
                StartDate = startDate
            });

            await _context.SaveChangesAsync(cancellationToken);

            _memory.Remove("SESSIONLIST");

            return(Unit.Value);
        }