示例#1
0
        // GET: /<controller>/
        public IActionResult Index()
        {
            var user    = GetCurrentUserAsync().Result;
            var profile = _profileRepo.GetSingle(p => p.UserId == user.Id);

            if (profile == null)
            {
                profile = new Profile()
                {
                    DisplayName      = "",
                    Firstname        = "",
                    Lastname         = "",
                    Phone            = "",
                    DisplayPhotoPath = "images/user.png",
                    UserId           = user.Id
                };

                _profileRepo.Create(profile);
            }

            ProfileIndexViewModel vm = new ProfileIndexViewModel()
            {
                DisplayName      = profile.DisplayName,
                Firstname        = profile.Firstname,
                Lastname         = profile.Lastname,
                Phone            = profile.Phone,
                DisplayPhotoPath = profile.DisplayPhotoPath
            };

            return(View(vm));
        }
示例#2
0
        public async Task <IActionResult> Index(string groupId = "", string Title = "", string Status = "", int?page = null)
        {
            if (string.IsNullOrWhiteSpace(groupId))
            {
                groupId = "general";
            }

            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageGroupProfile, (object)groupId))
            {
                return(Unauthorized());
            }

            var profile = await _profileService.GetProfileAsync();

            if (profile.UserName != User.Identity.Name || profile.UserRoles == null)
            {
                profile.UserName  = User.Identity.Name;
                profile.UserRoles = ((ClaimsIdentity)User.Identity).Claims.Where(c => c.Type == ClaimTypes.Role).Select(c => c.Value).ToList();
                await _profileService.UpdateProfileAsync(profile);
            }
            profile.Title  = Title;
            profile.Status = Status;
            profile.Page   = page;

            var viewModel = new ProfileIndexViewModel
            {
                GroupId = groupId,
                Shape   = await _profileDisplayManager.BuildEditorAsync(profile, this, false, groupId)
            };

            return(View(viewModel));
        }
示例#3
0
        public async Task <IActionResult> Index()
        {
            if (User.Claims.Count() == 0)
            {
                return(RedirectToAction(nameof(AccountController.Login), "Account"));
            }
            else
            {
                var user = await _userManager.GetUserAsync(User);

                if (user == null)
                {
                    throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
                }

                var model = new ProfileIndexViewModel
                {
                    FirstName   = user.FirstName,
                    LastName    = user.LastName,
                    Email       = user.Email,
                    PhoneNumber = user.PhoneNumber,
                    Nationality = user.Nationality,
                    DOB         = user.DOB,
                    Height      = user.Height,
                    Weight      = user.Weight,
                };
                return(View(model));
            }
        }
示例#4
0
        /**
         * Purpose: Method that is used to return the /Profile view and sets properties of the ProfileIndexViewModel
         * Arguments:
         *      int id - the userId of the profile being visited
         * Return:
         *      the view for the profile index view
         */
        public IActionResult Index([FromRoute] int id)
        {
            User         ProfileUser  = context.User.Where(u => u.UserId == id).SingleOrDefault();
            User         SignedInUser = ActiveUser.Instance.User;
            Notification ProfileSeenNotificationExists = context.Notification.Where(c => c.NotificationType == "ProfileView" && c.RecievingUserId == ProfileUser.UserId && c.SenderUserId == SignedInUser.UserId && c.Seen == false).SingleOrDefault();

            if (ProfileUser.UserId != SignedInUser.UserId && ProfileSeenNotificationExists == null)
            {
                Notification NewNotification = new Notification
                {
                    NotificationText = $"{SignedInUser.FirstName} {SignedInUser.LastName}, viewed your profile page!",
                    NotificationType = "ProfileView",
                    NotificatonDate  = DateTime.Now,
                    RecievingUserId  = ProfileUser.UserId,
                    Seen             = false,
                    SenderUserId     = SignedInUser.UserId
                };

                context.Notification.Add(NewNotification);
                context.SaveChanges();
            }

            int UserId = ActiveUser.Instance.User.UserId;

            List <Post> posts = context.Post.Where(p => p.UserId == id || p.RecievingUserId == id).ToList();

            List <Post> ProfileUserTagPosts = (from t in context.Tag
                                               join p in context.Post on t.PostId equals p.PostId
                                               where t.PersonBeingTaggedId == id
                                               select p).ToList();

            ProfileUserTagPosts.ForEach(TaggedPost => posts.Add(TaggedPost));

            posts.ForEach(p => p.User     = context.User.Where(u => u.UserId == p.UserId).SingleOrDefault());
            posts.ForEach(p => p.Comments = context.Comment.Where(c => c.PostId == p.PostId).ToList());
            foreach (Post p in posts)
            {
                if (p.Comments != null)
                {
                    foreach (Comment c in p.Comments)
                    {
                        c.User = context.User.Where(u => u.UserId == c.UserId).SingleOrDefault();
                    }
                }

                if (p.RecievingUserId != null)
                {
                    p.RecievingUser = context.User.Where(u => u.UserId == p.RecievingUserId).SingleOrDefault();
                }
            }

            ProfileIndexViewModel model = new ProfileIndexViewModel(context, id);

            model.Posts = posts.OrderByDescending(p => p.TimePosted).ToList();
            model.Posts.ForEach(p => p.TaggedUsers = context.Tag.Where(t => t.PostId == p.PostId).ToList());
            model.Posts.ForEach(p => p.TaggedUsers.ForEach(u => u.PersonBeingTagged = context.User.Where(us => us.UserId == u.PersonBeingTaggedId).SingleOrDefault()));

            return(View(model));
        }
示例#5
0
        public async Task <ActionResult> Register(RegisterViewModel model, ProfileIndexViewModel pModel, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                if (file != null)
                {
                    // Filändelsen kontrolleras
                    var splitFile = file.FileName.Split('.');
                    var extension = splitFile[splitFile.Length - 1];

                    bool validExtension = false;

                    if (extension.Equals("png") || extension.Equals("jpg") || extension.Equals("jpeg"))
                    {
                        validExtension = true;
                    }

                    if (validExtension)
                    {
                        string path = Path.Combine(Server.MapPath("~/Images"), Path.GetFileName(file.FileName));
                        file.SaveAs(path);
                        pModel.Image = "~/Images/" + file.FileName;
                    }
                    else
                    {
                        // Ändelsen är inte tillåten
                        ViewBag.ErrorMessage = "Image must be a .png, .jpg or .jpeg";
                        return(View());
                    }
                }
                else
                {
                    // Om användare inte har valt en bild, sätts default-bilden
                    pModel.Image = "~/Images/default-profile-picture.jpg";
                }

                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Create", "Profile", pModel));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
示例#6
0
        //returnerar edit-viewn
        public ActionResult Edit()
        {
            string userId    = User.Identity.GetUserId();
            var    model     = UnitOfWork.ProfileRepository.GetProfile(userId);
            var    viewModel = new ProfileIndexViewModel(model);

            return(View(viewModel));
        }
示例#7
0
        public ActionResult Edit(ProfileIndexViewModel viewModel, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                string fileName = "";

                if (file != null)
                {
                    // Kontrollerar filändelsen på bilden
                    var splitFile = file.FileName.Split('.');
                    var extension = splitFile[splitFile.Length - 1];

                    bool validExtension = false;

                    if (extension.Equals("png") || extension.Equals("jpg") || extension.Equals("jpeg"))
                    {
                        validExtension = true;
                    }

                    if (validExtension)
                    {
                        string path = Path.Combine(Server.MapPath("~/Images"), Path.GetFileName(file.FileName));
                        file.SaveAs(path);
                        fileName = "~/Images/" + file.FileName;
                    }
                    else
                    {
                        // Om filändelsen inte är tillåten
                        ViewBag.ErrorMessage = "Image must be a .png, .jpg or .jpeg";
                        return(View(viewModel));
                    }
                }

                string foreignKey = User.Identity.GetUserId();

                var model = UnitOfWork.ProfileRepository.GetProfile(UnitOfWork.ProfileRepository.GetProfileId(foreignKey));
                model.Name          = viewModel.Name;
                model.Age           = viewModel.Age;
                model.Gender        = viewModel.Gender;
                model.Biography     = viewModel.Biography;
                model.CSharp        = viewModel.CSharp;
                model.JavaScript    = viewModel.JavaScript;
                model.StackOverflow = viewModel.StackOverflow;

                if (!String.IsNullOrEmpty(fileName))
                {
                    model.Image = fileName;
                }

                UnitOfWork.ProfileRepository.EditProfile(model);

                UnitOfWork.Save();
                return(RedirectToAction("IndexMe", "Profile"));
            }

            return(View(viewModel));
        }
        // GET: TeamProfiles/Create
        // Team profile create page for administrators
        public ActionResult Create()
        {
            ProfileIndexViewModel editView = new ProfileIndexViewModel();

            editView.teamProfile     = new profile();
            editView.teamProfile.pic = "~/Images/no_image.jpg";

            return(View(editView));
        }
示例#9
0
        public ActionResult IndexMe()
        {
            //Visar den nuvarande användarens profilsida
            string userId = User.Identity.GetUserId();
            var    model  = UnitOfWork.ProfileRepository.GetProfile(userId);

            var viewModel = new ProfileIndexViewModel(model);

            return(View(viewModel));
        }
示例#10
0
        public ActionResult SelectProfile()
        {
            var ctx       = new BlogDbContext();
            var viewModel = new ProfileIndexViewModel
            {
                Profiles = ctx.Profiles.ToList(),
            };

            return(View(viewModel));
        }
示例#11
0
        public ActionResult AdminSettings()
        {
            var ctx       = new BlogDbContext();
            var viewModel = new ProfileIndexViewModel
            {
                Profiles = ctx.Profiles.ToList()
            };

            return(Index());
        }
示例#12
0
        // GET: Profile
        public ActionResult Index()
        {
            var views = ApplicationManager.BuildViews();

            var viewModel = new ProfileIndexViewModel();

            viewModel.Profiles = views.Profiles.GetAll();

            return(View(viewModel));
        }
示例#13
0
        public ActionResult ShowProfile()
        {
            var ctx       = new BlogDbContext();
            var viewModel = new ProfileIndexViewModel
            {
                Profiles       = ctx.Profiles.ToList(),
                ChosenCategory = ctx.SelectedCategories.ToList()
            };

            return(View(viewModel));
        }
示例#14
0
        public ActionResult ShowOthersProfile()
        {
            var ctx       = new BlogDbContext();
            var user      = User.Identity.GetUserId();
            var viewModel = new ProfileIndexViewModel
            {
                Profiles = ctx.Profiles.Where(x => x.ProfileID != user).ToList(),
            };

            return(View(viewModel));
        }
        public ActionResult List()
        {
            List <profile> profileList            = (from pro in db.profile where pro.status == 1 select pro).ToList();
            List <ProfileIndexViewModel> viewList = new List <ProfileIndexViewModel>();

            foreach (var pro in profileList)
            {
                ProfileIndexViewModel tp = new ProfileIndexViewModel();
                tp.teamProfile = pro;
                viewList.Add(tp);
            }
            return(View(viewList.ToList()));
        }
示例#16
0
        public ActionResult Index(int userId)
        {
            //visar profilsidan på användaren med id:t som skickas in
            var model = UnitOfWork.ProfileRepository.GetProfile(userId);

            //Kollar om profilen tillhör den nuvarande användaren
            if (UnitOfWork.ProfileRepository.GetProfileId(User.Identity.GetUserId()) == model.Id)
            {
                return(RedirectToAction("IndexMe"));
            }

            var visitorModel = new VisitorModel()
            {
                ProfileId = model.Id,
                VisitorId = UnitOfWork.ProfileRepository.GetProfileId(User.Identity.GetUserId())
            };

            // Hämtar alla besökare
            var visitorModels = UnitOfWork.VisitorRepository.GetVisitorProfiles(model.Id);

            bool duplicate = false;

            // Kollar om den inloggade användaren finns på besökarlistan
            foreach (var visitor in visitorModels)
            {
                if (visitor.VisitorId == UnitOfWork.ProfileRepository.GetProfileId(User.Identity.GetUserId()))
                {
                    duplicate = true;
                }
            }

            // om besökaren inte redan finns i besökarlistan och listan är mindre än 5
            if ((visitorModels.Count < 5) && (!duplicate))
            {
                UnitOfWork.VisitorRepository.AddVisitor(visitorModel);
            }
            // om besökaren inte redan finns i besökarlistan, men listan är full
            else if (!duplicate)
            {
                // den äldsta besökaren tas bort och den nya läggs till
                UnitOfWork.VisitorRepository.RemoveOldestVisitor();
                UnitOfWork.VisitorRepository.AddVisitor(visitorModel);
            }

            var viewModel = new ProfileIndexViewModel(model);

            UnitOfWork.Save();

            return(View(viewModel));
        }
        public ActionResult Index()
        {
            var userId = User.Identity.GetUserId();
            var ctx    = new MVCDbContext();
            //Hämtar ut alla profiler förutom användaren som är inloggad, och randomizar listan)
            var chosenProfiles = ctx.Profile.Where(p => p.ProfileId != userId).OrderBy(p => Guid.NewGuid()).ToList();
            var viewModel      = new ProfileIndexViewModel
            {
                Profiles = chosenProfiles,
            };

            viewModel.Profiles.RemoveAll(x => x.IsActive == false);

            return(View(viewModel));
        }
示例#18
0
        public async Task <IActionResult> Index()
        {
            AppUser user = await _userManager.FindByIdAsync(User.FindFirst("UserId").Value);

            ProfileIndexViewModel model = new ProfileIndexViewModel
            {
                UserName       = user.UserName,
                Email          = user.Email,
                FullName       = user.Name + " " + user.Surname,
                IsEmailConfirm = user.EmailConfirmed,
                Phone          = user.PhoneNumber
            };

            return(View(model));
        }
        public async Task <IActionResult> Index()
        {
            var userId = this.userManager.GetUserId(this.User);

            var userPayments = await this.paymentService.GetUserPaymentsListAsync(userId);

            var userRentals = await this.rentalService.GetUserRentalsListAsync(userId);

            var viewModel = new ProfileIndexViewModel
            {
                Payments = userPayments,
                Rentals  = userRentals,
            };

            return(this.View(viewModel));
        }
示例#20
0
        public ActionResult Index()
        {
            var currentProfileId = UnitOfWork.ProfileRepository.GetProfileId(User.Identity.GetUserId());

            // Hämtar en dictionary med alla användarens kontakter och kategorier
            var acceptedContactsAndCategories = UnitOfWork.ContactRepository.FindContactsAndCategories(currentProfileId);

            // Hämtar obesvarade kontaktförfrågningar
            var pendingContactIds       = UnitOfWork.ContactRepository.FindContactIds(currentProfileId, false);
            var profilesContactsPending = UnitOfWork.ProfileRepository.FindProfiles(pendingContactIds);

            var listOfProfileContactViewModel         = new List <ContactProfileViewModel>();
            var profilesIndexViewModelContactsPending = new ProfilesIndexViewModel();

            // Itererar igenom kontakter
            foreach (var item in acceptedContactsAndCategories)
            {
                // Om kontakten är aktiv, läggs den till en lista
                if (item.Key.Active == true)
                {
                    var profileContactViewModel = new ContactProfileViewModel(item.Key, item.Value);
                    listOfProfileContactViewModel.Add(profileContactViewModel);
                }
            }

            // Itererar igenom förfrågningar
            foreach (var model in profilesContactsPending)
            {
                if (model.Active == true)
                {
                    var profileIndexViewModelPending = new ProfileIndexViewModel(model);
                    profilesIndexViewModelContactsPending.Profiles.Add(profileIndexViewModelPending);
                }
            }

            // Skapar en viewmodel med både kontaktförfrågningar och kontakter
            var allContacts = new ContactsViewModel(listOfProfileContactViewModel, profilesIndexViewModelContactsPending);


            return(View(allContacts));
        }
示例#21
0
        public ActionResult Create(ProfileIndexViewModel profileModel)
        {
            var profile = new ProfileModel
            {
                Name          = profileModel.Name,
                Age           = profileModel.Age,
                Gender        = profileModel.Gender,
                Biography     = profileModel.Biography,
                Image         = profileModel.Image,
                UserId        = User.Identity.GetUserId(),
                Active        = true,
                CSharp        = profileModel.CSharp,
                JavaScript    = profileModel.JavaScript,
                StackOverflow = profileModel.StackOverflow
            };

            UnitOfWork.ProfileRepository.AddProfile(profile);
            UnitOfWork.Save();

            return(RedirectToAction("Index", "Home"));
        }
示例#22
0
 public ActionResult MyFriends()
 {
     try
     {
         var id        = User.Identity.GetUserId();
         var ctx       = new Gr8DbContext();
         var viewModel = new ProfileIndexViewModel
         {
             Users = ctx.Database.SqlQuery <User>("Select * From Users Where Users.Id in (Select ToUser From FriendRequests Where FromUser in (Select Id From Users Where IdentityID = '" + id + "' and Accepted = 'True')) or Users.Id in (Select FromUser From FriendRequests Where ToUser in (Select Id From Users Where IdentityID = '" + id + "' and Accepted = 'True')) and Active = 'True' order by FirstName")
                     .ToList(),
             FriendsRequests = ctx.Database.SqlQuery <User>("Select * From Users Where Users.Id in (Select FromUser From FriendRequests Where ToUser in (Select Id From Users Where IdentityID = '" + id + "' and Accepted = 'False')) and Active = 'True' order by FirstName")
                               .ToList()
         };
         return(View(viewModel));
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(View("Error"));
     }
 }
        public ActionResult Index()
        {
            var user = User.Identity.GetUserId();

            if (user == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            var ctx = new MVCDbContext();

            var profileActive = ctx.Profile.FirstOrDefault(p => p.ProfileId == user);

            if (!profileActive.IsActive)
            {
                return(RedirectToAction("EditProfileData", "Profile"));
            }

            var viewmodel = new ProfileIndexViewModel();

            // Hämtar de förfrågningar som hör till användaren.
            viewmodel.Requests = ctx.Request.Where(p => p.GetterId == user).ToList();
            var profiles = new List <Profile>();

            //Hämtar ut de profiler som skrivit meddelandena.
            foreach (var r in viewmodel.Requests)
            {
                if (r.GetterId.Equals(user))
                {
                    var profile = ctx.Profile.FirstOrDefault(p => p.ProfileId == r.AskerId);
                    profiles.Add(profile);
                }
            }

            // Tar bort de profiler som är avaktiverade.
            profiles.RemoveAll(x => x.IsActive == false);
            viewmodel.Profiles = profiles;

            return(View(viewmodel));
        }
示例#24
0
        /**
         * Purpose: To upload a new image into an album
         * Arguments:
         *      ProfileIndexViewModel model - Contains the albumId selected and all properties neccasary to create a new image
         * Return:
         *      Redirects to the list of albums view.
         */
        public async Task <IActionResult> AddImageToAlbum(ProfileIndexViewModel model)
        {
            IFormFile file          = model.image;
            var       uploads       = Path.Combine(_environment.WebRootPath, "images");
            User      u             = ActiveUser.Instance.User;
            Album     selectedAlbum = context.Album.Where(a => a.AlbumId == model.AlbumId).SingleOrDefault();

            if (file != null && file.ContentType.Contains("image"))
            {
                using (var fileStream = new FileStream(Path.Combine(uploads, file.FileName), FileMode.Create))
                {
                    await file.CopyToAsync(fileStream);
                }

                Image UploadedImage = new Image
                {
                    ImagePath = $"/images/{file.FileName}",
                    UserId    = u.UserId,
                    AlbumId   = model.AlbumId
                };

                Post NewImagePost = new Post
                {
                    UserId     = u.UserId,
                    Text       = $"{u.FirstName} added a new photo to their {selectedAlbum.AlbumName} album!",
                    TimePosted = DateTime.Now,
                    PostType   = "Status",
                    ImgUrl     = $"/images/{file.FileName}"
                };

                context.Image.Add(UploadedImage);
                context.Post.Add(NewImagePost);

                await context.SaveChangesAsync();

                return(RedirectToAction("AlbumImages", "Profile", new { id = u.UserId, id2 = model.AlbumId }));
            }

            return(RedirectToAction("Index", "Home"));
        }
        public async Task <ActionResult> Create(ProfileIndexViewModel editView)
        {
            if (ModelState.IsValid)
            {
                profile pro = editView.teamProfile;

                var validImageTypes = new string[]
                {
                    "image/gif",
                    "image/jpeg",
                    "image/jpg",
                    "image/png"
                };

                if (editView.picFile != null && editView.picFile.ContentLength > 0)
                {
                    if (!validImageTypes.Contains(editView.picFile.ContentType))
                    {
                        ModelState.AddModelError("ImageUpload", "Please choose either a GIF, JPG or PNG image.");
                    }

                    var uploadDir   = "~/images/teamprofile";
                    var newFileName = String.Format("{0}_{1}_{2}", "Profile", DateTime.Now.ToString("yyyyMMddHHmmssfff"), Path.GetFileName(editView.picFile.FileName));
                    var imagePath   = Path.Combine(Server.MapPath(uploadDir), newFileName);
                    editView.picFile.SaveAs(imagePath);

                    var imageUrl = Path.Combine(uploadDir, Path.GetFileName(imagePath));
                    pro.pic = "~/images/teamprofile/" + newFileName;
                }

                pro.status = 1;
                db.profile.Add(pro);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(editView));
        }
        public ViewModels.ProfileIndexViewModel GetProfileViewModel(string userName)
        {
            using (var db = new GainTrackerContext(ACTIVE_CONNECTION))
            {
                var vm = new ProfileIndexViewModel
                {
                    TrackedData = db.TrackedData.Where(u => u.UserName == userName).ToList()
                };

                foreach (var item in vm.TrackedData)
                {
                    item.DataPoints      = db.DataPoints.Where(d => d.TrackedDataId == item.Id).ToArray();
                    item.DataPointValues = item.DataPoints.Select(d => d.Value).ToArray();
                }

                vm.CreateTrackedViewModel = new CreateTrackedDataViewModel
                {
                    UserName = Membership.GetUser().UserName
                };

                return(vm);
            }
        }
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            profile pro = await db.profile.FindAsync(id);

            if (pro == null)
            {
                return(HttpNotFound());
            }
            else if (pro.status == 0)
            {
                return(HttpNotFound());
            }

            ProfileIndexViewModel editView = new ProfileIndexViewModel();

            editView.teamProfile = pro;

            return(View(editView));
        }
示例#28
0
        public ActionResult Index()
        {
            var viewModels = new ProfilesIndexViewModel();

            // Om ett konto precis inaktiverats, får viewbag:en en bekräftelse som skickas vidare till view
            ViewBag.Deactivated = TempData["Deactivated"];

            try
            {
                var profilesCount = UnitOfWork.ProfileRepository.CountProfiles();

                // Kontrollerar om det finns tillräckligt med profiler för att göra profilkorten på startsidan
                if (profilesCount > 3)
                {
                    foreach (var item in UnitOfWork.ProfileRepository.GetThreeNewestUsers())
                    {
                        var viewModel = new ProfileIndexViewModel(item);
                        viewModels.Profiles.Add(viewModel);
                    }

                    UnitOfWork.Dispose();

                    return(View(viewModels));
                }
                else
                {
                    UnitOfWork.Dispose();
                    return(View(viewModels));
                }
            }

            // Inga profiler kunde hämtas från databasen
            catch (InvalidOperationException)
            {
                return(View(viewModels));
            }
        }
        // GET: Profile
        public ActionResult Index(string msg)
        {
            switch (msg)
            {
            case "not-all":
                ModelState.AddModelError("not-all", "You can't complete a challenge without marking all books as read.");
                break;

            case "no-start":
                ModelState.AddModelError("no-start", "You can't start a challenge that you have marked as completed.");
                break;

            default:
                break;
            }
            GetUserRole();

            var userName = User.Identity.GetUserName();

            var       user            = _userRepository.GetUser(userName);
            Challenge activeChallenge = null;

            if (user.ChallengeId != null)
            {
                activeChallenge = _challengesRepository.Get((int)user.ChallengeId, userName, true);
            }
            var viewModel = new ProfileIndexViewModel()
            {
                ActiveChallenge     = activeChallenge,
                Name                = user.Name,
                CompletedChallenges = user.Challenges.Select(c => c.Challenge).ToList(),
                Location            = "Profile",
                IsCurrentChallenge  = true
            };

            return(View(viewModel));
        }
示例#30
0
        public ActionResult Index(int?idUser)
        {
            int        idCurrentUser = idUser == null ? (int)Session["userId"] : (int)idUser;
            bool       isMyProfile   = idUser == null ? true : false;
            UserDTO    user          = userLogic.Get(idCurrentUser);
            RoleDTO    role          = new RoleDTO();
            CompanyDTO company       = companyLogic.List().Find(c => c.Id == user.Id_Company);

            Session["notifs"] = notificationLogic.ListAllForUser(idCurrentUser).FindAll(n => n.IsRead == 0).Count;

            ProfileIndexViewModel vm = new ProfileIndexViewModel
            {
                CurrentUser          = new Tuple <UserDTO, CompanyDTO, RoleDTO>(user, company, role),
                isSessionUserProfile = isMyProfile
            };

            if (TempData["ErrorModal"] != null)
            {
                ViewBag.ErrorModal = TempData["ErrorModal"].ToString();
            }
            if (TempData["EditDrivingLicence"] != null)
            {
                ViewBag.EditDrivingLicence = TempData["EditDrivingLicence"].ToString();
            }
            ViewBag.RenderContactForm = "off";
            if (TempData["RenderContactForm"] != null)
            {
                ViewBag.RenderContactForm = TempData["RenderContactForm"].ToString();
            }
            ViewBag.RenderInformationsForm = "off";
            if (TempData["RenderInformationsForm"] != null)
            {
                ViewBag.RenderInformationsForm = TempData["RenderInformationsForm"].ToString();
            }
            return(View(vm));
        }