Exemplo n.º 1
0
        public ActionResult Index()
        {
            NicknameName currentUser = UO.NickName.GetAll()
                                       .Where(m => m.UserName == HttpContext.User.Identity.Name)
                                       .FirstOrDefault();

            return(View(currentUser));
        }
Exemplo n.º 2
0
        public ActionResult AddFullName(string FullName, NicknameName currentUser)
        {
            //validation
            try
            {
                if (UO.NickName.GetAll().Where(x => x.Learner.LearnerName == FullName).First() != null)
                {
                    ModelState.AddModelError("", "This name is already used");
                }
            }
            catch (NullReferenceException) { }//if we got it fits

            if (String.IsNullOrEmpty(FullName))
            {
                ModelState.AddModelError("", "Please enter your full name");
            }

            if (FullName.All(x => !(char.IsLetter(x) || char.IsWhiteSpace(x) || x == '-')))
            {
                ModelState.AddModelError("", "Unacceptable symbols detected");
            }

            if (ModelState.IsValid)
            {
                var learner = new Learner()
                {
                    IsBlocked   = false,
                    LearnerName = FullName
                };
                //creating new record to the DB
                currentUser = new NicknameName()
                {
                    UserName = HttpContext.User.Identity.Name,
                    Learner  = learner
                };
                UO.NickName.Create(currentUser);
                UO.Save();
                return(View("Index", currentUser));
            }
            // If we got this far, something failed, redisplay form
            return(View("Index"));
        }