Exemple #1
0
 /// <summary>
 /// Contructor fills list of groups and assigns event hanlders
 /// </summary>
 public YourGroupsForm()
 {
     InitializeComponent();
     currUser = Globals.CurrentUser;
     UpdateGridView();
     groupsGridView.CellContentClick += EditGroupClick;
     groupsGridView.CellDoubleClick += SeeGroupDetailsClick;
 }
Exemple #2
0
 /// <summary>
 /// Updates binding source
 /// </summary>
 public async void UpdateGridView()
 {
     Application.UseWaitCursor = true;
     currUser = Globals.CurrentUser;
     var repo = new HttpGroupsRepository();
     groupsBindingSource.Clear();
     foreach (var groupDetail in currUser.GroupDetails)
     {
         var group = await repo.GetOne(groupDetail.group_id);
         groupsBindingSource.Add(group);
     }
     groupsGridView.Update();
     Application.UseWaitCursor = false;
 }
Exemple #3
0
        /// <summary>
        /// Form constructor
        /// </summary>
        /// <param name="user">User that is logged in</param>
        public SettingsForm(UsersViewModel user)
        {
            currUser = user;
            InitializeComponent();

            tbName.Text = currUser.name;
            tbSurname.Text = currUser.surname;
            tbEmail.Text = currUser.email;
            tbUsername.Text = currUser.username;

            tbPasswd.PasswordChar = '*';
            tbConfPasswd.PasswordChar = '*';

            tbPasswd.Text = "xxx";
            tbConfPasswd.Text = "xxx";
        }
Exemple #4
0
        /// <summary>
        /// Updates the list of years.
        /// </summary>
        /// <returns>Returns Collection of years.</returns>
        private async Task<ICollection<YearsViewModel>> UpdateYearList(){
            currentUser = await users.GetUser(username);

            listYear.Items.Clear();
            listYear.Sorted = false;
            //get list of years for user
            var yearsList = await years.GetYears(username);

            //Get groups from groupDetails
            var groupDetailsList = await groupDetails.GetGroupDetailsForUser(currentUser.id);

            if ((yearsList != null && yearsList.Count != 0) || (groupDetailsList != null && groupDetailsList.Count != 0))
            {
                //If it is not a visitor display all years from usr and groups otherwise
                // otherwise display only years form a group it is being visited from
                if (!visiting)
                {
                    listYear.Items.Add(new YearListItem("Users Years"));
                    // populate with current user years
                    foreach (var year in yearsList)
                    {
                        YearListItem item = new YearListItem(year.name, year.id);
                        listYear.Items.Add(item);
                    }

                    var userGroups = currentUser.Groups;
                    
                    foreach (var group in userGroups)
                    {
                        var groupYears = group.Years;
                        if (groupYears != null && groupYears.Count != 0)
                        {
                            //adding a separator with a name of the group
                            listYear.Items.Add(new YearListItem(group.name));
                            //listYear.Items.Add();
                            foreach (var year in groupYears)
                            {
                                YearListItem item;
                                if (group.owner_id == currentUser.id)
                                    item = new YearListItem(year.name, year.id, true, true);
                                else
                                    item = new YearListItem(year.name, year.id, true, false);

                                listYear.Items.Add(item);
                            }

                        }
                    }
                } //else: for displaying only years from common group
                else {
                    var groupYears = await years.GetYearsOfGroup(visitorGroupId);
                    foreach (var year in groupYears)
                    {
                        listYear.Items.Add(new YearListItem(year.name, year.id, true, false));
                    }
                }


                //Check if the form is being visited
                if (visiting)
                {
                    btnAddSubject.Enabled = false;
                    btnDeleteYear.Enabled = false;
                    btnEditYear.Enabled = false;
                    btnAddYear.Enabled = false;
                }
                else
                {
                    //check If a year is displayed by an Owner
                    if (selectedYearListItem != null)
                    {
                        if (selectedYearListItem.Owned)
                        {
                            btnAddSubject.Enabled = true;
                            btnDeleteYear.Enabled = true;
                            btnEditYear.Enabled = true;
                        }
                        else
                        {
                            btnAddSubject.Enabled = false;
                            btnDeleteYear.Enabled = false;
                            btnEditYear.Enabled = false;
                        }
                    }
                }

               if (selectedYearListItem != null)
                {
                    
                    listYear.SelectedIndex = listYear.Items.IndexOf(selectedYearListItem);
                    //listYear.Text = selectedYear.name;
                }
                else
                {
                    listYear.SelectedIndex = 0;
                }
            }
            else
            {
                btnAddSubject.Enabled = false;
                btnDeleteYear.Enabled = false;
                btnEditYear.Enabled = false;
                if (visiting) {
                    btnAddYear.Enabled = false;
                }
            }
            return yearsList;
        }
Exemple #5
0
 /// <summary>
 /// Funciton updates currently logged user to have the same data as in databse.
 /// </summary>
 /// <returns></returns>
 public static async Task UpdateCurrentUser()
 {
     HttpUsersRepository repo = new HttpUsersRepository();
     CurrentUser = await repo.GetOne(CurrentUser.id);
 }
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                //var user = new ApplicationUser() { UserName = model.Username, Username = model.Username };
                var user = new ApplicationUser()
                {
                    UserName = model.Username,
                    Email = model.Email
                };
                
                IdentityResult result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    ////adding user to custom Users table
                    UsersViewModel userViewModel = new UsersViewModel()
                    {
                        id = user.Id,
                        username = user.UserName,
                        email = user.Email,
                        passwd = "tmp"
                    };
                    HttpUsersRepository repo = new HttpUsersRepository();

                    await repo.AddOne(userViewModel);
                   // ====
                    //Users newUser = new Users()
                    //{
                    //    id=user.Id,
                    //    username = user.UserName,
                    //    email = user.Username,
                    //    passwd = user.PasswordHash,
                        
                    //};
                    //GradingBookDbEntities db = new GradingBookDbEntities();
                    //db.Users.Add(newUser);
                    //db.SaveChanges();
                    //
                    await SignInAsync(user, isPersistent: false);

                    // For more information on how to enable account confirmation and password reset please visit http://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("Index", "Home");
                }
                else
                {
                    AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }