public async Task <ReadOrderModel> AddOrderAsync(CreateOrderModel model, CancellationToken cancellationToken)
        {
            var order = _mapper.Map <Order>(model);

            order.IconId = await _fileService.AddOrUpdateFileByIdAsync(model.Icon, order.IconId, cancellationToken);

            foreach (var categoryId in model.CategoryIds)
            {
                var category = await _categoryRepository.GetByIdAsync(categoryId, cancellationToken);

                var orderCategory = new OrderCategory
                {
                    Order    = order,
                    Category = category
                };

                order.Categories.Add(orderCategory);
            }

            await _orderRepository.AddAsync(order, cancellationToken);

            await _unitOfWork.SaveChangesAsync(cancellationToken);

            return(_mapper.Map <ReadOrderModel>(order));
        }
        public async Task <ReadCategoryModel> AddCategoryAsync(CreateCategoryModel model, CancellationToken cancellationToken)
        {
            var category = _mapper.Map <Category>(model);

            category.IconId = await _fileService.AddOrUpdateFileByIdAsync(model.Icon, category.IconId, cancellationToken);

            await _categoryRepository.AddAsync(category, cancellationToken);

            await _unitOfWork.SaveChangesAsync(cancellationToken);

            return(_mapper.Map <ReadCategoryModel>(category));
        }
Exemple #3
0
        public async Task <ReadAchievementModel> AddAchievementAsync(CreateAchievementModel model, CancellationToken cancellationToken)
        {
            var achievement = new Achievement()
            {
                Name        = model.Name,
                Description = model.Description,
                XP          = model.XP
            };

            achievement.IconId = await _fileService.AddOrUpdateFileByIdAsync(model.Icon, achievement.IconId, cancellationToken);

            await _achievementRepository.AddAsync(achievement, cancellationToken);

            await _unitOfWork.SaveChangesAsync(cancellationToken);

            return(_mapper.Map <ReadAchievementModel>(achievement));
        }
        public async Task <ReadFullUserModel> AddUserAsync(CreateUserModel model, CancellationToken cancellationToken)
        {
            var user = _mapper.Map <User>(model);

            await SetRolesForUserModel(model.Roles, user, cancellationToken);

            user.AvatarId = await _fileService.AddOrUpdateFileByIdAsync(model.Avatar, user.AvatarId, cancellationToken);

            user.Password = _hasher.GetHash(model.Password);

            await _userRepository.AddAsync(user, cancellationToken);

            await _unitOfWork.SaveChangesAsync(cancellationToken);

            await SendEmail(model, cancellationToken);

            return(_mapper.Map <ReadFullUserModel>(user));
        }