public async Task <IActionResult> Index(int?id)
        {
            User user = null;

            if (id.HasValue)
            {
                user = await _context.User
                       .FirstOrDefaultAsync(m => m.Id == id.Value);
            }
            else
            {
                user = await _context.User
                       .FirstOrDefaultAsync(m => m.Id == ClaimsExtension.GetUserId(HttpContext));
            }

            ViewData["MyProjects"]        = _context.Project.Where(proj => proj.OwnerId == user.Id && !proj.IsDeleted).ToList();
            ViewData["PurchasedProjects"] = _context.Sale.Where(sale => sale.BuyerId == user.Id).Include(sale => sale.Project).ToList();
            if (user == null)
            {
                return(NotFound());
            }

            ViewData["is_owner"] = user.Id == ClaimsExtension.GetUserId(HttpContext);


            return(View(user));
        }
        public IActionResult Buy(int id)
        {
            int userId = ClaimsExtension.GetUserId(HttpContext);

            var project = _context.Project
                          .Include(x => x.AcademicInstitute)
                          .Include(x => x.FieldOfStudy)
                          .Include(x => x.Owner)
                          .FirstOrDefault(m => m.Id == id);

            if (project == null)
            {
                return(NotFound());
            }

            var user = _context.User.Find(userId);

            if (user == null)
            {
                return(NotFound());
            }

            Sale sale = new Sale();

            sale.Buyer   = user;
            sale.Project = project;
            sale.Price   = project.Price;
            _context.Add(sale);
            _context.SaveChanges();
            return(View(sale));
        }
        public async Task <IActionResult> Filter(ProjectFilter filter)
        {
            bool includeDeleted = filter.IncludeDeleted && ClaimsExtension.IsAdmin(HttpContext);

            var projectsGroup =
                (from project in _context.Project
                 join user in _context.User on project.OwnerId equals user.Id
                 join sale in _context.Sale on project.Id equals sale.ProjectId into sales
                 from subsale in sales.DefaultIfEmpty()
                 where ((includeDeleted || (!project.IsDeleted && !user.IsDeleted)) &&
                        (!filter.UserId.HasValue || project.OwnerId == filter.UserId.Value) &&
                        project.Name.Contains(filter.Name ?? "") &&
                        (!filter.MaxPrice.HasValue || project.Price <= filter.MaxPrice.Value) &&
                        (!filter.MinPrice.HasValue || project.Price >= filter.MinPrice.Value) &&
                        (!filter.FieldOfStudyId.HasValue || project.FieldOfStudyId == filter.FieldOfStudyId.Value)
                        )
                 select new
            {
                Id = project.Id,
                Description = project.Description,
                Name = project.Name,
                Grade = subsale.Grade,
                Rank = subsale.Rank,
                OwnerName = user.FullName,
                OwnerId = user.Id
            })
                .GroupBy(x => new { x.Id, x.Description, x.Name, x.OwnerName, x.OwnerId });

            List <ProjectInStoreView> projects = new List <ProjectInStoreView>();

            foreach (var group in projectsGroup)
            {
                var proj = new ProjectInStoreView()
                {
                    Id          = group.Key.Id,
                    Description = group.Key.Description,
                    Name        = group.Key.Name,
                    OwnerName   = group.Key.OwnerName,
                    OwnerId     = group.Key.OwnerId
                };
                var grades = group.Where(x => x.Grade.HasValue);
                proj.AvgGrade = grades.Any() ? new double?(grades.Select(x => (double)x.Grade.Value).Average()) : null;
                var ranks = group.Where(x => x.Rank.HasValue);
                proj.Rank = ranks.Any() ? new double?(ranks.Select(x => (double)x.Rank.Value).Average()) : null;
                if (proj.AvgGrade.HasValue)
                {
                    proj.AvgGrade = (float)(Math.Round((double)proj.AvgGrade, 2));
                    proj.Rank     = (float)(Math.Round((double)proj.Rank, 2));
                }
                projects.Add(proj);
            }
            return(Json(projects));
        }
        public IActionResult Edit()
        {
            var currentUser    = _context.User.Find(ClaimsExtension.GetUserId(HttpContext));
            var currentDetails = new UpdateAccountDetails()
            {
                EMail     = currentUser.EMail,
                FirstName = currentUser.FirstName,
                LastName  = currentUser.LastName
            };

            return(View(currentDetails));
        }
        public IActionResult About()
        {
            ViewData["Message"] = "Your application description page.";

            var principal = HttpContext.User;

            ViewData["Message"] = ClaimsExtension.GetClaimValue(principal, ClaimTypes.Email) + ";  " +
                                  ClaimsExtension.GetClaimValue(principal, ClaimTypes.Name) + ";  " +
                                  ClaimsExtension.GetClaimValue(principal, "FullName");


            return(View());
        }
Beispiel #6
0
        public async Task <IActionResult> Filter(UsersFilter filter)
        {
            bool includeDeleted = filter.IncludeDeleted && ClaimsExtension.IsAdmin(HttpContext);
            var  users          = (
                from u in _context.User
                where u.FirstName.Contains(filter.FirstName ?? "") &&
                u.LastName.Contains(filter.LastName ?? "") &&
                u.UserName.Contains(filter.UserName ?? "") &&
                (includeDeleted || !u.IsDeleted)
                select new { u.Id, u.UserName, u.FullName, u.EMail, u.IsAdmin, u.IsDeleted }
                );

            return(Json(users));
        }
        public static async Task ValidateAsync(CookieValidatePrincipalContext context)
        {
            var userPrincipal = context.Principal;

            ClaimsExtension.UpdateClaim(userPrincipal, ClaimTypes.Email, "*****@*****.**");

            ClaimsExtension.UpdateClaim(userPrincipal, ClaimTypes.Name, "test");

            ClaimsExtension.UpdateClaim(userPrincipal, "FullName", "test.test");

            context.ShouldRenew = true;

            context.ReplacePrincipal(userPrincipal);

            var s = ClaimsExtension.GetClaimValue(userPrincipal, "FullName");

            var r = ClaimsExtension.GetClaimValue(userPrincipal, ClaimTypes.Email);
        }
        public async Task <IActionResult> Index()
        {
            var principal = HttpContext.User;

            ClaimsExtension.UpdateClaim(principal, ClaimTypes.Email, "*****@*****.**");

            ClaimsExtension.UpdateClaim(principal, ClaimTypes.Name, "test");

            ClaimsExtension.UpdateClaim(principal, "FullName", "test.test");

            await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);

            await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal);

            var s = ClaimsExtension.GetClaimValue(principal, "FullName");

            var r = ClaimsExtension.GetClaimValue(principal, ClaimTypes.Email);

            return(View());
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Description,FieldOfStudyId,AcademicInstituteId,Address")] Project project)
        {
            int userId = ClaimsExtension.GetUserId(HttpContext);

            // No user id redirect to login
            if (userId < 0)
            {
                return(RedirectToAction("Login", "Account"));
            }

            project.OwnerId = userId;
            if (ModelState.IsValid)
            {
                _context.Add(project);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(project));
        }
Beispiel #10
0
        // GET: Users/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var user = await _context.User
                       .FirstOrDefaultAsync(m => m.Id == id && (!m.IsDeleted || ClaimsExtension.IsAdmin(HttpContext)));

            if (user == null)
            {
                return(NotFound());
            }
            IEnumerable <FieldOfStudy> fieldsOfStudy = _context.FieldOfStudy.ToList();

            ViewData["FieldsOfStudy"] = fieldsOfStudy;

            return(View(user));
        }
        public IActionResult Edit([Bind("FirstName,LastName,EMail")] UpdateAccountDetails updateAccountDetails)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var currentUser = _context.User.Find(ClaimsExtension.GetUserId(HttpContext));
                    currentUser.EMail     = updateAccountDetails.EMail;
                    currentUser.FirstName = updateAccountDetails.FirstName;
                    currentUser.LastName  = updateAccountDetails.LastName;
                    _context.Update(currentUser);
                    _context.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception)
            {
                ModelState.AddModelError(string.Empty, "שגיאה התרחשה בעת עדכון הפרטים האישיים");
            }

            return(View(updateAccountDetails));
        }
        // GET: Projects/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            // Machine learning is awesome!

            List <IGrouping <int, int> > projectIdsPerUsersGroups = _context.Sale.Include("Project").Where(x => !x.Project.IsDeleted).GroupBy(x => x.BuyerId, y => y.ProjectId).ToList();

            SortedSet <int>[] projectsPerUserDataset = new SortedSet <int> [projectIdsPerUsersGroups.Count];
            int idx = 0;

            foreach (var group in projectIdsPerUsersGroups)
            {
                projectsPerUserDataset[idx++] = new SortedSet <int>(group);
            }

            Apriori apriori = new Apriori(threshold: 3, confidence: 0);
            AssociationRuleMatcher <int> classifier = apriori.Learn(projectsPerUserDataset);

            AssociationRule <int>[] rules = classifier.Rules;

            ViewData["suggested"] = rules.Where(x => x.Y.First() != id).Select(x => _context.Project.First(y => y.Id == x.Y.First()));

            var project = await _context.Project
                          .Include(x => x.AcademicInstitute)
                          .Include(x => x.FieldOfStudy)
                          .Include(x => x.Owner)
                          .FirstOrDefaultAsync(m => m.Id == id &&
                                               ((!m.Owner.IsDeleted && !m.IsDeleted) || ClaimsExtension.IsAdmin(HttpContext)));

            if (project == null)
            {
                return(NotFound());
            }

            return(View(project));
        }
 private User UserForChangePassword(string password)
 {
     return(_context.User.FirstOrDefault(user => user.Id == ClaimsExtension.GetUserId(HttpContext) && user.Password == Models.User.HashPassword(password)));
 }