public async Task AddSubject(SubjectModel subjectModel)
        {
            var result = _mapper.Map <Subject>(subjectModel);

            _repositoryManager.Subject.Add(result);
            await _repositoryManager.CompleteAsync();
        }
示例#2
0
        public async Task AddCourse(CourseModel courseModel)
        {
            var subject = _mapper.Map <Course>(courseModel);

            _repositoryManager.Course.Add(subject);
            await _repositoryManager.CompleteAsync();
        }
示例#3
0
        public async Task AddTeacher(TeacherModel teacherModel)
        {
            var result = _mapper.Map <Teacher>(teacherModel);

            _repositoryManager.Teacher.Add(result);
            await _repositoryManager.CompleteAsync();
        }
        public async Task AddStudent(StudentModel studentModel)
        {
            var result = _mapper.Map <Student>(studentModel);

            _repositoryManager.Student.Add(result);
            await _repositoryManager.CompleteAsync();
        }
示例#5
0
        public async Task <User> CreateAsync(User user, string password)
        {
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new LogicException("Password is required");
            }

            if (_repositoryManager.Users.Any(x => x.Username == user.Username))
            {
                throw new LogicException("Username \"" + user.Username + "\" is already taken");
            }

            byte[] passwordHash, passwordSalt;
            CreatePasswordHash(password, out passwordHash, out passwordSalt);

            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;

            _repositoryManager.Users.Add(user);
            await _repositoryManager.CompleteAsync();

            _eventBus.Publish(new AddUserIntegrationEvent
            {
                FirstName = user.FirstName,
                Username  = user.Username,
                Password  = password,
                LastName  = user.LastName
            });

            return(user);
        }
示例#6
0
        public async Task AddStudentCourse(StudentCourseModel studentCourseModel)
        {
            var sc = _mapper.Map <StudentCourse>(studentCourseModel);

            _repositoryManager.StudentCourse.Add(sc);
            await _repositoryManager.CompleteAsync();
        }
示例#7
0
        public async Task <UserChatRoom> CreateAsync(UserChatRoom chatRoom)
        {
            var chatRoomEntity = _repositoryManager.UserChatRooms.Add(chatRoom);
            await _repositoryManager.CompleteAsync();

            return(chatRoomEntity);
        }
示例#8
0
        public async Task AddOrder(OrderViewModel order, long userId)
        {
            var productIds = order.OrderProducts.Select(x => x.ProductId);

            var products = await _repositoryManager.Products.FindAsync(x => productIds.Contains(x.Id));

            var orderProducts = from product in products
                                join orderProduct in order.OrderProducts on product.Id equals orderProduct.ProductId
                                select new OrderProduct
            {
                UnitPrice = product.Price,
                ProductId = product.Id,
                Quantity  = orderProduct.Quantity
            };

            var orderTotalSum = orderProducts.Sum(x => x.Quantity * x.UnitPrice);

            var orderEntity = new Order
            {
                OrderProducts = orderProducts.ToList(),
                Total         = orderTotalSum,
                UserId        = userId,
            };

            _repositoryManager.Orders.Add(orderEntity);

            await _repositoryManager.CompleteAsync();
        }