Beispiel #1
0
        public async Task <IActionResult> EditProfilePicture(string Url, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (Url != null && Url != "")
            {
                TwoThorProfile TwoThor = null;
                foreach (TwoThorProfile t in _context.DbTwoThorProfileList) // looper gjennom TwoThors for å finne ut om den som er logget på er en TwoThor
                {
                    if (t.Email.Equals(User.Identity.Name))                 // hvis han/hun er det:
                    {
                        TwoThor = t;
                        break;
                    }
                }
                if (TwoThor != null)
                {
                    TwoThor.PictureUrl = Url;

                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Profile", new { chosenName = User.Identity.Name }));
                }
            }

            // If we got this far, something failed, send to front page
            return(RedirectToAction("Index", "Home"));
        }
Beispiel #2
0
        public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            model.Email           = User.Identity.Name;
            if (model != null && model.Name != null && model.Description != null)
            {
                var newTwoThor = new TwoThorProfile(model.Name, model.Email, model.Description);
                newTwoThor.PictureUrl = "null";

                foreach (string name in model.SubjectsKnown)
                {
                    foreach (Subject s in _context.DbSubjectList)
                    {
                        if (name.Length > 6 && s.SubjectName.Length > 6 && name.Substring(0, 6).Equals(s.SubjectName.Substring(0, 6)))
                        {
                            _context.DbTwoThorSubjectList.Add(new TwoThorSubjects(model.Email, name));
                        }
                    }
                }

                _context.DbTwoThorProfileList.Add(newTwoThor);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Profile", new { chosenName = model.Email }));
            }

            // If we got this far, something failed, redisplay form
            model.Subjects      = _context.DbSubjectList.ToList();
            model.SubjectsKnown = new string[_context.DbSubjectList.Count()];
            return(View(model));
        }
Beispiel #3
0
        public async Task <IActionResult> EditProfile(RegisterViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (model != null && model.Name != null && model.Description != null)
            {
                model.Email = User.Identity.Name;
                TwoThorProfile TwoThor = null;
                foreach (TwoThorProfile t in _context.DbTwoThorProfileList) // looper gjennom TwoThors for å finne ut om den som er logget på er en TwoThor
                {
                    if (t.Email.Equals(User.Identity.Name))                 // hvis han/hun er det:
                    {
                        TwoThor = t;
                        break;
                    }
                }
                if (TwoThor != null)
                {
                    TwoThor.Name        = model.Name;
                    TwoThor.Description = model.Description;

                    foreach (TwoThorSubjects s in _context.DbTwoThorSubjectList)
                    {
                        if (model.Email.Equals(s.TwoThorName))
                        {
                            _context.DbTwoThorSubjectList.Remove(s);
                        }
                    }
                    foreach (string name in model.SubjectsKnown)
                    {
                        foreach (Subject s in _context.DbSubjectList)
                        {
                            if (name.Length > 6 && s.SubjectName.Length > 6 && name.Substring(0, 6).Equals(s.SubjectName.Substring(0, 6)))
                            {
                                _context.DbTwoThorSubjectList.Add(new TwoThorSubjects(model.Email, name));
                            }
                        }
                    }
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Profile", new { chosenName = model.Email }));
                }
            }

            // If we got this far, something failed, send to front page
            return(RedirectToAction("Index", "Home"));
        }