Exemplo n.º 1
0
        public IActionResult Register(RegisterForm registerForm)
        {
            bool screenName = _userRepository.GetAll().Where(u => u.ScreenName == registerForm.ScreenName).FirstOrDefault() is null;
            bool email      = _userRepository.GetAll().Where(u => u.Email == registerForm.Email).FirstOrDefault() is null;

            if (!(registerForm is null) && ModelState.IsValid)
            {
                registerForm.Passwd = Convert.ToBase64String(_cryptoService.Crypter(registerForm.Passwd));

                try
                {
                    if (screenName && email)
                    {
                        _authRepository.Register(registerForm);
                        return(RedirectToAction("Login"));
                    }

                    else if (!screenName)
                    {
                        ViewBag.Message = "Screen Name already exists";
                    }

                    else
                    {
                        ViewBag.Message = "Email already used";
                    }
                }
                catch (Exception ex)
                {
                    return(View("Error"));
                }
            }

            return(View(registerForm.ToWeb()));
        }
Exemplo n.º 2
0
        public ActionResult Edit(int id, EditUser form)
        {
            User u          = _userRequester.Get(SessionManager.User.Id);
            bool canUpdate  = form.LastName != u.LastName || form.FirstName != u.FirstName || form.ScreenName != u.ScreenName || form.Email != u.Email || form.Address != u.Address;
            bool screenName = _userRequester.GetAll().Where(u => u.Id != SessionManager.User.Id && u.ScreenName == form.ScreenName).FirstOrDefault() is null;
            bool email      = _userRequester.GetAll().Where(u => u.Id != SessionManager.User.Id && u.Email == form.Email).FirstOrDefault() is null;

            try
            {
                if (ModelState.IsValid && (SessionManager.User.Id == id) && !(SessionManager.User.Token is null))
                {
                    if (canUpdate)
                    {
                        if (screenName && email)
                        {
                            _apiTokenRequester.UpdateWithToken(new User(id, form.LastName, form.FirstName, form.ScreenName, form.Email, form.Address)
                                                               , "user/" + id, SessionManager.User.Token);

                            ViewBag.Message = "Profile successfully updated";
                            return(RedirectToAction(nameof(Index)));
                        }

                        else if (!screenName)
                        {
                            ViewBag.Message = "Screen Name already used";
                        }

                        else
                        {
                            ViewBag.Message = "Email address not avilable";
                        }

                        return(View(form));
                    }

                    ViewBag.Message = "You changed nothing, nice try";
                    return(View(form));
                }

                ViewBag.Message = "Session has expired";
                return(RedirectToAction("Index", "Auth"));
            }
            catch
            {
                return(View("Error"));
            }
        }
Exemplo n.º 3
0
 public IEnumerable <User> GetAll()
 {
     return(_userRepository.GetAll());
 }
Exemplo n.º 4
0
        //private void OnDeleteUser(UserViewModel instance)  // *
        //{
        //    Items.Remove(instance);
        //}

        protected override ObservableCollection <UserViewModel> LoadItems()
        {
            return(new ObservableCollection <UserViewModel>(_userRequester.GetAll().Select(u => new UserViewModel(u))));
        }
Exemplo n.º 5
0
 public IEnumerable <Event> GetAll()
 {
     return(_eventRepository.GetAll());
 }
Exemplo n.º 6
0
 // GET: Event
 public ActionResult Index()
 {
     return(View(_eventRequester.GetAll()
                 .Where(e => e.Date >= DateTime.Now || e.Date is null)
                 .OrderBy(e => e.Date)));
 }
Exemplo n.º 7
0
        //private void OnDeleteEvent(EventViewModel instance)  // *
        //{
        //    Items.Remove(instance);
        //}

        protected override ObservableCollection <EventViewModel> LoadItems()
        {
            return(new ObservableCollection <EventViewModel>(_eventRequester.GetAll().Select(e => new EventViewModel(e))));
        }