Exemple #1
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}");
        }
 public TViewModel GetGenreById <TViewModel>(int id)
 {
     return(genresRepository.All()
            .Where(x => x.Id == id)
            .To <TViewModel>()
            .SingleOrDefault());
 }
Exemple #3
0
        public async Task Update(SubjectEditModel model)
        {
            Subject subject = repository.All().Where(x => x.Id == model.Id).FirstOrDefault();

            subject.Name = model.Name;
            repository.Update(subject);
        }
Exemple #4
0
        public async Task EditAsync(StudentModifyInputModel modifiedModel)
        {
            var student = _studentsRepository.All().FirstOrDefault(s => s.Id == modifiedModel.Id);

            if (student != null)
            {
                var inputModel = modifiedModel.Student;
                student.FirstName = inputModel.FirstName;
                student.LastName  = inputModel.LastName;
                student.BirthDate = inputModel.BirthDate;
                student.PersonalIdentificationNumber = inputModel.PersonalIdentificationNumber;

                var schoolId = int.Parse(inputModel.SchoolId);
                var school   = _schoolsRepository.All().FirstOrDefault(s => s.Id == schoolId);
                if (school != null)
                {
                    student.School = school;
                    var classId = int.Parse(inputModel.ClassId);
                    if (school.Classes.Any(c => c.Id == classId))
                    {
                        student.Class = school.Classes.FirstOrDefault(c => c.Id == classId);
                    }
                }

                _studentsRepository.Update(student);
                await _studentsRepository.SaveChangesAsync();
            }
        }
Exemple #5
0
        public IEnumerable <T> GetAllByStudentId <T>(int studentId)
        {
            var studentSubjects = _studentSubjectRepository.All().Where(s => s.StudentId == studentId);
            var subjects        = studentSubjects.Select(s => s.Subject);

            return(subjects.To <T>().ToList());
        }
Exemple #6
0
        public PackageViewModel GetPackage(string id)
        {
            var model = _packageRepository.All()
                        .Where(p => p.Id.Equals(id))
                        .To <PackageViewModel>()
                        .SingleOrDefault();

            if (model != null)
            {
                if (model.StatusName.Equals("Pending"))
                {
                    model.EstimatedDeliveryDate = "N/A";
                }
                else if (model.StatusName.Equals("Delivered") || model.StatusName.Equals("Acquired"))
                {
                    model.EstimatedDeliveryDate = "Delivered";
                }
                else
                {
                    model.EstimatedDeliveryDate = DateTime.Parse(model.EstimatedDeliveryDate).ToString("dd/MM/yyyy", new DateTimeFormatInfo());
                }
            }

            return(model);
        }
Exemple #7
0
        public void AddCategoriesForSportCenter(IEnumerable <string> categoriesNames, string sportCenterName)
        {
            var sportCenter = sportCentesDb.All().FirstOrDefault(x => x.Name == sportCenterName);

            foreach (var name in categoriesNames)
            {
                var currentCategory = this.sportCategoriesDb.All().FirstOrDefault(x => x.Name == name);

                if (currentCategory != null)
                {
                    currentCategory.SportCenters.Add(sportCenter);
                }
                else
                {
                    if (string.IsNullOrWhiteSpace(name))
                    {
                        continue;
                    }
                    sportCategoriesDb.Add(new SportCategory()
                    {
                        Name = name.Trim(), SportCenters = new List <SportCenter>()
                        {
                            sportCenter
                        }
                    });
                }
            }
            sportCategoriesDb.SaveChanges();
        }
Exemple #8
0
        public async Task <IActionResult> Edit(int?id)
        {
            var deal = dealRepository.All().Where(d => d.Id == id).FirstOrDefault();//await context.Deals

            //.Include(d => d.User)
            //FirstOrDefaultAsync(m => m.Id == id);

            if (id == null || deal == null)
            {
                this.TempData["InfoMessage"] = "Deal not found!";
                return(this.Redirect("/Deals/GetAll"));
            }

            if (!this.User.IsInRole(GlobalConstants.AdministratorRoleName) || this.User.FindFirstValue(ClaimTypes.NameIdentifier) != deal.UserId)
            {
                return(this.RedirectToAction("GetAll"));
            }

            if (deal == null)
            {
                return(NotFound());
            }
            ViewData["UserId"]    = new SelectList(context.Users, "Id", "FirstName", deal.UserId);
            ViewData["AccountId"] = context.Accounts.Select(x => new SelectListItem(x.AccountName, x.Id.ToString()));
            //ViewData["AccountId"] = new SelectList(context.Accounts, "Id", "AccountName", deal.AccountId); Питай Ники и Стоян защо не работи
            return(View(deal));
        }
Exemple #9
0
        public async Task <int> GetCountByVideoIdAndRateTypeAsync(string videoId, RateType type)
        {
            var likesCount = await repository.All()
                             .Where(c => c.VideoId == videoId && c.Rating == type)
                             .CountAsync();

            return(likesCount);
        }
Exemple #10
0
        public void DeletePicture(int id)
        {
            var pic = pictures.All().Where(x => x.Id == id).FirstOrDefault();

            pic.IsDeleted = true;
            pic.DeletedOn = DateTime.Now;

            pictures.SaveChanges();
        }
        public double GetAverageRatingOfGame(int gameId)
        {
            var games = reviewsRepository.All()
                        .Where(x => x.GameId == gameId)
                        .Select(x => x.Rating)
                        .ToList();

            return(games.Count > 0 ? games.Average() : 0);
        }
Exemple #12
0
        public void DeleteVideo(int id)
        {
            var vid = videos.All().Where(x => x.Id == id).FirstOrDefault();

            vid.IsDeleted = true;
            vid.DeletedOn = DateTime.Now;

            videos.SaveChanges();
        }
Exemple #13
0
        public void DeleteUser(string guid)
        {
            var user = users.All().Where(x => x.Id == guid).FirstOrDefault();

            user.IsDeleted = true;
            user.DeletedOn = DateTime.Now;

            users.SaveChanges();
        }
Exemple #14
0
        public IEnumerable <T> GetAll <T>(int?count = null)
        {
            IQueryable <Category> query = _categoriesRepository.All().OrderBy(x => x.Name);

            if (count.HasValue)
            {
                query = query.Take(count.Value);
            }

            return(query.To <T>().ToList());
        }
Exemple #15
0
        public IEnumerable <T> GetAll <T>(int cvId)
        {
            var allEntities = _commentsRepository.All();
            var result      = allEntities
                              .Where(c => c.CVId == cvId)
                              .OrderByDescending(c => c.CreatedOn)
                              .Select(e => _mapper.Map <T>(e))
                              .ToArray();

            return(result);
        }
Exemple #16
0
        public void AddCommentToSportCenter(int sportCenterId, string authorId, string content)
        {
            var sportCenter = sportCentersDb.All().FirstOrDefault(x => x.Id == sportCenterId);
            var user        = usersDb.All().FirstOrDefault(x => x.Id == authorId);

            sportCenter.Comments.Add(new Comment()
            {
                SportCenterId = sportCenterId, Content = content, Author = user
            });
            sportCentersDb.SaveChanges();
        }
Exemple #17
0
        public void AddAddressForUser(string userId, int neighbourId)
        {
            var address = addressesDb.All()
                          .FirstOrDefault(x => neighbourId == x.Id);

            var user = usersDb.All().FirstOrDefault(x => x.Id == userId);

            user.AddressId = address.Id;

            usersDb.SaveChanges();
        }
Exemple #18
0
        public async Task <List <Comment> > Get10ByVideoIdAsync(int page, string videoId)
        {
            var comments = await repository.All()
                           .Where(c => c.VideoId == videoId)
                           .Include(c => c.Author)
                           .OrderByDescending(c => c.CreatedOn)
                           .Skip(10 * page)
                           .Take(10)
                           .ToListAsync();

            return(comments);
        }
Exemple #19
0
        public async Task <ApplicationUser> GetByUsernameAsync(string username)
        {
            var user = await userRepository.All()
                       .Include(u => u.Ratings)
                       .ThenInclude(r => r.Video)
                       .ThenInclude(v => v.Author)
                       .Include(u => u.Uploads)
                       .SingleOrDefaultAsync(u => u.UserName == username);



            return(user);
        }
Exemple #20
0
        public async Task DeleteAsync(int id)
        {
            var student = _studentsRepository.All().FirstOrDefault(s => s.Id == id);

            if (student != null)
            {
                var parentIds = student.StudentParents.Select(sp => sp.ParentId).ToList();
                foreach (var parentId in parentIds)
                {
                    var parent = _parentRepository.All().FirstOrDefault(p => p.Id == parentId);
                    var parentStudentsCount = parent?.StudentParents.Count;
                    if (parentStudentsCount == 1) // delete parent if current student is their only child with active account
                    {
                        _parentRepository.Delete(parent);
                        await _parentRepository.SaveChangesAsync();
                    }

                    var mapping = _studentParentsMappingRepository.All()
                                  .FirstOrDefault(sp => sp.StudentId == id && sp.ParentId == parentId);
                    _studentParentsMappingRepository.Delete(mapping);
                }

                await _studentParentsMappingRepository.SaveChangesAsync();

                // ToDo: Decide if StudentSubject should be handled here as well
                _studentsRepository.Delete(student);
                await _studentsRepository.SaveChangesAsync();
            }
        }
Exemple #21
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());
        }
 public IEnumerable <T> GetAll <T>()
 {
     return(_settingsRepository
            .All()
            .To <T>() //magic mapping through automapper   Setting => T
            .ToList());
 }
Exemple #23
0
        public async Task <ApplicationUser> Authenticate(string username, string password)
        {
            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
            {
                return(null);
            }

            var user = repository.All().FirstOrDefault(a => a.UserName == username);

            // check if username exists
            if (user == null)
            {
                return(null);
            }

            // check if password is correct
            if (!VerifyPasswordHash(password, Convert.FromBase64String(user.PasswordHash), Convert.FromBase64String(user.PasswordSalt)))
            {
                return(null);
            }


            // authentication successful
            return(user);
        }
Exemple #24
0
        public async Task ClosePosition(int accountId)
        {
            var account = await this.accountRepository
                          .All()
                          .FirstOrDefaultAsync(a => a.Id == accountId);

            var position          = account.Positions.FirstOrDefault(p => p.OpenClose == OpenClose.Open);
            var currentStockPrice = datasetsRepository
                                    .All()
                                    .OrderByDescending(d => d.DateAndTime)
                                    .Select(d => d.ClosePrice)
                                    .FirstOrDefault();

            if (position != null)
            {
                position.OpenClose  = OpenClose.Close;
                position.ClosePrice = currentStockPrice;
                account.Balance    -= account.TradeFee;
                account.Balance    += position.CountStocks * currentStockPrice;
                var tradeFee = new FeePayment
                {
                    Amount  = account.TradeFee,
                    TypeFee = TypeFee.TradeFee,
                };

                account.Fees.Add(tradeFee);
                await this.accountRepository.SaveChangesAsync();
            }
        }
Exemple #25
0
        public void AddCategoriesForUser(IEnumerable <string> categories, string userId)
        {
            var user = usersDb.All().FirstOrDefault(x => x.Id == userId);

            foreach (var name in categories)
            {
                var currentCategory = this.sportCategoriesDb.All().FirstOrDefault(x => x.Name == name);

                if (currentCategory != null)
                {
                    currentCategory.Users.Add(user);
                }
                else
                {
                    if (string.IsNullOrWhiteSpace(name))
                    {
                        continue;
                    }
                    sportCategoriesDb.Add(new SportCategory()
                    {
                        Name = name, Users = new List <User>()
                        {
                            user
                        }
                    });
                }
            }

            sportCategoriesDb.SaveChanges();
        }
Exemple #26
0
        public UserViewModel GetUserViewModelByIdWithPackages(string id)
        {
            var model = _userRepository.All()
                .Where(u => u.Id.Equals(id))
                .To<UserViewModel>()
                .SingleOrDefault();

            if (model != null)
            {
                model.Packages = _packageRepository.All()
                    .Where(p => p.RecipientId.Equals(model.Id) && !p.Status.Name.Equals("Acquired"))
                    .To<PackageViewModel>()
                    .ToList();
            }

            return model;
        }
Exemple #27
0
        public UserType GetUserTypeByUniqueId(string uniqueId)
        {
            if (!string.IsNullOrEmpty(uniqueId))
            {
                switch (uniqueId[0])
                {
                case GlobalConstants.PrincipalIdPrefix:
                    var principalRecord = _principalsRepository.All().FirstOrDefault(p => p.UniqueId == uniqueId);
                    if (principalRecord != null)
                    {
                        return(UserType.Principal);
                    }

                    break;

                case GlobalConstants.TeacherIdPrefix:
                    var teacherRecord = _teachersRepository.All().FirstOrDefault(p => p.UniqueId == uniqueId);
                    if (teacherRecord != null)
                    {
                        return(UserType.Teacher);
                    }

                    break;

                case GlobalConstants.StudentIdPrefix:
                    var studentRecord = _studentsRepository.All().FirstOrDefault(p => p.UniqueId == uniqueId);
                    if (studentRecord != null)
                    {
                        return(UserType.Student);
                    }

                    break;

                case GlobalConstants.ParentIdPrefix:
                    var parentRecord = _parentsRepository.All().FirstOrDefault(p => p.UniqueId == uniqueId);
                    if (parentRecord != null)
                    {
                        return(UserType.Parent);
                    }

                    break;
                }
            }

            return(UserType.None);
        }
Exemple #28
0
        public async Task <IEnumerable <FuelTypeDetails> > GetAllTypesAsync()
        {
            var result = await fuelTypeRepository
                         .All().To <FuelTypeDetails>()
                         .ToListAsync();

            return(result);
        }
Exemple #29
0
        public UserViewModel GetUserViewModelByIdWithReceipts(string id)
        {
            var model = _userRepository.All()
                        .Where(u => u.Id.Equals(id))
                        .To <UserViewModel>()
                        .SingleOrDefault();

            return(model);
        }
Exemple #30
0
        public ReceiptViewModel GetReceiptViewModel(string id)
        {
            var model = _receiptRepository.All()
                        .Where(r => r.Id.Equals(id))
                        .To <ReceiptViewModel>()
                        .SingleOrDefault();

            return(model);
        }