Beispiel #1
0
        private async Task <string> CreateUserAsync(string email, string name, string lastName, IDeletableEntityRepository <ApplicationUser> repo)
        {
            var user = new ApplicationUser()
            {
                FirstName        = name,
                LastName         = lastName,
                Email            = email,
                UserName         = email,
                ProfilePicture   = "Test.com",
                ModelInformation = new ModelInformation
                {
                    Age       = 13,
                    Bust      = 14,
                    Waist     = 16,
                    Hips      = 14,
                    Height    = 15,
                    Gender    = Gender.Male,
                    Ethnicity = Ethnicity.Chinese,
                },
                UserImages = new List <UserImage>
                {
                    new UserImage {
                        ImageUrl = "Test"
                    },
                },
            };
            await repo.AddAsync(user);

            await repo.SaveChangesAsync();

            return(user.Id);
        }
Beispiel #2
0
        //private async Task<string> CreateUserImages(string userId, IDeletableEntityRepository<UserImage> imageRepo, IDeletableEntityRepository<ApplicationUser> repo)
        //{
        //    var userImages = new List<UserImage>
        //    {
        //        new UserImage { UserId = userId, ImageUrl = "testUrl1" },
        //        new UserImage { UserId = userId, ImageUrl = "testUrl2" },
        //        new UserImage { UserId = userId, ImageUrl = "testUrl3" },
        //    };
        //    foreach (var image in userImages)
        //    {
        //        await imageRepo.AddAsync(image);
        //        await repo.SaveChangesAsync();
        //    }

        //    return userId;
        //}

        private async Task <string> CreateUserWithImage(string email, string name, string lastName, IDeletableEntityRepository <ApplicationUser> repo)
        {
            var user = new ApplicationUser()
            {
                FirstName  = name,
                LastName   = lastName,
                Email      = email,
                UserName   = email,
                UserImages = new List <UserImage>
                {
                    new UserImage {
                        ImageUrl = "testUrl1"
                    },
                    new UserImage {
                        ImageUrl = "testUrl2"
                    },
                    new UserImage {
                        ImageUrl = "testUrl3"
                    },
                },
            };
            await repo.AddAsync(user);

            await repo.SaveChangesAsync();

            return(user.Id);
        }
Beispiel #3
0
        public async Task Add(SubjectInputModel model)
        {
            Subject subject = model.To <Subject>();
            await repository.AddAsync(subject);

            await repository.SaveChangesAsync();
        }
Beispiel #4
0
        public async Task <int> Create(string id, string userId)
        {
            var package = _packageRepository.All()
                          .SingleOrDefault(p => p.Id.Equals(id) && p.RecipientId.Equals(userId));

            if (package == null)
            {
                return(0);
            }

            var price = (decimal)package.Weight * 2.67M;

            var receipt = new Receipt
            {
                Fee         = price,
                RecipientId = package.RecipientId,
                Recipient   = package.Recipient,
                PackageId   = package.Id,
                Package     = package,
            };

            var status = _statusRepository.All().SingleOrDefault(s => s.Name.Equals("Acquired"));

            package.Status = status;

            _packageRepository.Update(package);
            await _packageRepository.SaveChangesAsync();

            await _receiptRepository.AddAsync(receipt);

            return(await _receiptRepository.SaveChangesAsync());
        }
Beispiel #5
0
        public async Task Create(SchoolInputModel inputModel, string principalUniqueId)
        {
            var principal = _usersService.GetPrincipalByUniqueId(principalUniqueId);
            var school    = new School
            {
                Name      = inputModel.Name,
                Address   = inputModel.Address,
                Type      = inputModel.Type,
                Principal = principal
            };

            if (inputModel.SchoolImage != null)
            {
                var fileName       = inputModel.SchoolImage.Name;
                var uniqueFileName = Guid.NewGuid() + fileName;

                await _fileManagementService.SaveImageAsync("schools", uniqueFileName, inputModel.SchoolImage);

                school.SchoolImageName = uniqueFileName;
            }

            await _schoolsRepository.AddAsync(school);

            await _schoolsRepository.SaveChangesAsync();
        }
        public async Task Add(QuestionTypeInputModel model)
        {
            QuestionType questionType = model.To <QuestionType>();
            await repository.AddAsync(questionType);

            await repository.SaveChangesAsync();
        }
Beispiel #7
0
        public async Task AddProduct(ProductCreateInputModel model, string imagePath)
        {
            Product product = new Product
            {
                Name        = model.Name,
                Price       = model.Price,
                CategoryId  = model.CategoryId,
                Description = model.Description,
            };

            Directory.CreateDirectory($"{imagePath}/products/");

            var extension = Path.GetExtension(model.Image.FileName).TrimStart('.');

            if (!this.allowedExtensions.Any(x => extension.EndsWith(x)))
            {
                throw new Exception($"Invalid image extension {extension}");
            }

            var dbImage = new Image
            {
                Extension = extension,
            };

            product.Image = dbImage;

            var physicalPath = $"{imagePath}/products/{dbImage.Id}.{extension}";

            using Stream fileStream = new FileStream(physicalPath, FileMode.Create);
            await model.Image.CopyToAsync(fileStream);

            await productRepository.AddAsync(product);

            await productRepository.SaveChangesAsync();
        }
Beispiel #8
0
        public async Task <T> CreateTeacher <T>(TeacherInputModel inputModel)
        {
            var schoolId = int.Parse(inputModel.SchoolId);
            var school   = _schoolsRepository.All().FirstOrDefault(s => s.Id == schoolId);

            if (school != null)
            {
                var teacher = new Teacher()
                {
                    FirstName = inputModel.FirstName,
                    LastName  = inputModel.LastName,
                    School    = school,
                    UniqueId  = _idGeneratorService.GenerateTeacherId()
                };

                await _teachersRepository.AddAsync(teacher);

                await _teachersRepository.SaveChangesAsync();

                BasePersonModel baseModel = _teachersRepository.All().FirstOrDefault(t => t.UniqueId == teacher.UniqueId);

                return(AutoMapperConfig.MapperInstance.Map <T>(baseModel));
            }

            throw new ArgumentException($"Sorry, we couldn't find school with id {schoolId}");
        }
Beispiel #9
0
        public async Task CreateAsync(GradeInputModel inputModel)
        {
            var studentSubject = _studentSubjectsRepository.All().FirstOrDefault(s =>
                                                                                 s.StudentId == inputModel.StudentId && s.SubjectId == inputModel.SubjectId);

            if (studentSubject != null)
            {
                var teacher = _teachersRepository.All().FirstOrDefault(t => t.Id == inputModel.TeacherId);
                if (teacher != null)
                {
                    var grade = new Grade
                    {
                        Value          = inputModel.Value,
                        Period         = inputModel.Period,
                        Type           = inputModel.Type,
                        StudentSubject = studentSubject,
                        Teacher        = teacher
                    };

                    await _gradesRepository.AddAsync(grade);

                    await _gradesRepository.SaveChangesAsync();

                    return;
                }

                throw new ArgumentException($"Sorry, we couldn't find teacher with id {inputModel.TeacherId}");
            }

            throw new ArgumentException($"Sorry, we couldn't find pair of student ({inputModel.StudentId}) and subject({inputModel.SubjectId})");
        }
        public async Task <int> Create(ContactFormInputModel input)
        {
            var contactForm = AutoMapperConfig.MapperInstance.Map <ContactForm>(input);
            await contactFormsRepository.AddAsync(contactForm);

            await contactFormsRepository.SaveChangesAsync();

            return(contactForm.Id);
        }
Beispiel #11
0
        public async Task CreateCategory(string name)
        {
            var category = new Category
            {
                Name = name,
            };
            await categoryRepository.AddAsync(category);

            await categoryRepository.SaveChangesAsync();
        }
Beispiel #12
0
        public async Task CreateAsync(ExperienceCreateInputModel inputModel, int cvId)
        {
            var experience = _mapper.Map <Experience>(inputModel);

            experience.CVId = cvId;

            await _experienceRepository.AddAsync(experience);

            await _experienceRepository.SaveChangesAsync();
        }
Beispiel #13
0
        public async Task CreateAsync(SkillCreateInputModel inputModel, int cvId)
        {
            var skill = _mapper.Map <Skill>(inputModel);

            skill.CVId = cvId;

            await _skillsRepository.AddAsync(skill);

            await _skillsRepository.SaveChangesAsync();
        }
Beispiel #14
0
        public async Task CreateAsync(EducationCreateInputModel inputModel, int cvId)
        {
            var education = _mapper.Map <Education>(inputModel);

            education.CVId = cvId;

            await _educationEntityRepository.AddAsync(education);

            await _educationEntityRepository.SaveChangesAsync();
        }
Beispiel #15
0
        private async Task CreateBlogContentForTests(string title, string content, int blogId, IDeletableEntityRepository <BlogContent> cRepo)
        {
            var blogContent = new BlogContent
            {
                BlogId  = blogId,
                Title   = title,
                Content = content,
            };

            await cRepo.AddAsync(blogContent);

            await cRepo.SaveChangesAsync();
        }
Beispiel #16
0
        public async Task CreateAsync(string content, int cvId, string userId)
        {
            var comment = new Comment
            {
                CVId    = cvId,
                UserId  = userId,
                Content = content
            };

            await _commentsRepository.AddAsync(comment);

            await _commentsRepository.SaveChangesAsync();
        }
Beispiel #17
0
        public async Task <IActionResult> InsertSetting()
        {
            var random  = new Random();
            var setting = new Setting {
                Name = $"Name_{random.Next()}", Value = $"Value_{random.Next()}"
            };

            await repository.AddAsync(setting);

            await repository.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Beispiel #18
0
        public async Task <T> CreateParentAsync <T>(ParentInputModel inputModel)
        {
            var studentIds = inputModel.StudentIds.Select(int.Parse);
            var students   = _studentsRepository.All().Where(s => studentIds.Contains(s.Id));

            if (students.Any())
            {
                var parent = new Parent
                {
                    FirstName   = inputModel.FirstName,
                    LastName    = inputModel.LastName,
                    PhoneNumber = inputModel.PhoneNumber,
                    UniqueId    = _idGeneratorService.GenerateParentId()
                };

                await _parentsRepository.AddAsync(parent);

                await _parentsRepository.SaveChangesAsync();

                foreach (var student in students)
                {
                    var studentParentPair = new StudentParent
                    {
                        Student = student,
                        Parent  = parent
                    };

                    await _studentParentsMappingRepository.AddAsync(studentParentPair);
                }

                await _studentParentsMappingRepository.SaveChangesAsync();

                BasePersonModel baseModel = _parentsRepository.All().FirstOrDefault(p => p.UniqueId == parent.UniqueId);

                return(AutoMapperConfig.MapperInstance.Map <T>(baseModel));
            }

            throw new ArgumentException($"Sorry, we couldn't any student with id in the following list:  [{string.Join(", ", studentIds)}]");
        }
        public async Task Create(ReviewInputModel input)
        {
            var review = AutoMapperConfig.MapperInstance.Map <Review>(input);

            if (reviewsRepository.AllAsNoTracking().Any(x => x.GameId == input.GameId && x.AuthorId == input.AuthorId))
            {
                await Task.FromException <int>(
                    new InvalidOperationException("A review for this user already exists."));
            }

            await reviewsRepository.AddAsync(review);

            await reviewsRepository.SaveChangesAsync();
        }
Beispiel #20
0
        private async Task <int> CreateImageForTest(string url, string userId, IDeletableEntityRepository <UserImage> repo)
        {
            var userImages = new UserImage
            {
                UserId   = userId,
                ImageUrl = url,
            };

            await repo.AddAsync(userImages);

            await repo.SaveChangesAsync();

            return(userImages.Id);
        }
        public async Task <int> Create(GenreInputModel input)
        {
            var genre = new Genre()
            {
                Description = input.Description,
                Name        = input.Name,
            };

            await genresRepository.AddAsync(genre);

            await genresRepository.SaveChangesAsync();

            return(genre.Id);
        }
Beispiel #22
0
        // Create user with no profile picture and modelInformation
        private async Task <string> CreateUserWithNoInformationAsync(string email, string name, string lastName, IDeletableEntityRepository <ApplicationUser> repo)
        {
            var user = new ApplicationUser()
            {
                FirstName = name,
                LastName  = lastName,
                Email     = email,
                UserName  = email,
            };
            await repo.AddAsync(user);

            await repo.SaveChangesAsync();

            return(user.Id);
        }
Beispiel #23
0
        public async Task CreateAsync(ClassInputModel inputModel)
        {
            var teacherId = int.Parse(inputModel.TeacherId);
            var teacher   = _teachersRepository.All().FirstOrDefault(t => t.Id == teacherId);

            if (teacher != null)
            {
                if (teacher.Class != null)
                {
                    throw new ArgumentException($"Sorry, teacher with id {teacherId} is already registered as head of another class");
                }

                var isClassLetterNumberCombinationAlreadyOccupied = _classesRepository.All().Any(c =>
                                                                                                 c.Letter == inputModel.Letter &&
                                                                                                 c.YearCreated == inputModel.YearCreated &&
                                                                                                 c.Year == inputModel.Year &&
                                                                                                 c.Teacher.SchoolId == teacher.SchoolId);
                if (isClassLetterNumberCombinationAlreadyOccupied)
                {
                    throw new ArgumentException($"Sorry, there is already existing class for year {inputModel.YearCreated} that's currently in {inputModel.Year} grade and with letter {inputModel.Letter}");
                }

                var schoolClass = new Class
                {
                    Letter      = inputModel.Letter,
                    Year        = inputModel.Year,
                    YearCreated = inputModel.YearCreated,
                    Teacher     = teacher
                };

                await _classesRepository.AddAsync(schoolClass);

                await _classesRepository.SaveChangesAsync();

                var classEntity = _classesRepository.All().First(c =>
                                                                 c.Letter == schoolClass.Letter && c.YearCreated == schoolClass.YearCreated &&
                                                                 c.Year == schoolClass.Year);
                var school = teacher.School;
                school.Classes.Add(classEntity);

                _schoolsRepository.Update(school);
                await _schoolsRepository.SaveChangesAsync();

                return;
            }

            throw new ArgumentException($"Sorry, we couldn't find teacher with id {teacherId}");
        }
Beispiel #24
0
        public async Task <int> CreateAsync(string title, string content, int categoryId, string userId)
        {
            var post = new Post
            {
                CategoryId = categoryId,
                Title      = title,
                Content    = content,
                UserId     = userId
            };

            await _postsRepository.AddAsync(post);

            await _postsRepository.SaveChangesAsync();

            return(post.Id);
        }
Beispiel #25
0
        public async Task CreateOrder(Order order)
        {
            if (order.Delivery == true)
            {
                order.Status = GlobalConstants.Sent;
            }
            else
            {
                order.Status = GlobalConstants.Open;
            }
            orderRepository.AddAsync(order).Wait();

            await orderRepository.SaveChangesAsync();

            await orderItemService.CreateOrderItem(order);
        }
Beispiel #26
0
        public async Task AddReservation(ReservationCreateInputModel model)
        {
            var reservation = new Reservation
            {
                StartTime     = model.StartTime,
                NumberOfSeats = model.NumberOfSeats,
                Duration      = model.Duration,
                PersonEmail   = model.Email,
                PersonName    = model.Name,
                PersonNumber  = model.Number,
            };

            await reservationRepository.AddAsync(reservation);

            await reservationRepository.SaveChangesAsync();
        }
        private async Task <int> CreateContactForm
            (string name, string email, string subject, string message, IDeletableEntityRepository <ContactFormData> repo)
        {
            var contact = new ContactFormData
            {
                Name    = name,
                Email   = email,
                Subject = subject,
                Message = message,
            };
            await repo.AddAsync(contact);

            await repo.SaveChangesAsync();

            return(contact.Id);
        }
Beispiel #28
0
        private async Task <string> CreateUserForTests(
            string email, string name, string lastName, string url, IDeletableEntityRepository <ApplicationUser> repo)
        {
            var user = new ApplicationUser()
            {
                FirstName      = name,
                LastName       = lastName,
                Email          = email,
                UserName       = email,
                ProfilePicture = url,
            };

            await repo.AddAsync(user);

            await repo.SaveChangesAsync();

            return(user.Id);
        }
Beispiel #29
0
        public async Task <T> CreatePrincipal <T>(PrincipalInputModel inputModel)
        {
            var principal = new Principal
            {
                FirstName = inputModel.FirstName,
                LastName  = inputModel.LastName,
                UniqueId  = _idGeneratorService.GeneratePrincipalId()
            };

            await _principalsRepository.AddAsync(principal);

            await _principalsRepository.SaveChangesAsync();

            BasePersonModel baseModel = _principalsRepository.All().FirstOrDefault(p =>
                                                                                   p.FirstName == inputModel.FirstName && p.LastName == inputModel.LastName);

            return(AutoMapperConfig.MapperInstance.Map <T>(baseModel));
        }
Beispiel #30
0
        private async Task <int> CreateBlogForTest(
            string title,
            string imageUrl,
            string userId,
            IDeletableEntityRepository <Model4You.Data.Models.Blog> blogRepo)
        {
            var blog = new Model4You.Data.Models.Blog
            {
                UserId   = userId,
                Title    = title,
                ImageUrl = imageUrl,
            };

            await blogRepo.AddAsync(blog);

            await blogRepo.SaveChangesAsync();

            return(blog.Id);
        }