Ejemplo n.º 1
0
        public async Task <Commissioner> LoginAsync(Commissioner commissioner)
        {
            if (commissioner == null)
            {
                throw new ArgumentNullException(nameof(commissioner));
            }
            if (commissioner.IsChairman)
            {
                try
                { return(await _context.Commissioners.FirstOrDefaultAsync(x => x.IsChairman && x.UserName.Equals(commissioner.UserName) && x.Password.Equals(commissioner.Password))); }
                catch (Exception e)
                {
                    throw new Exception("Something went wrong. could not log in as chairman", e);
                }
            }
            else if (commissioner.IsPresident)
            {
                try
                { return(await _context.Commissioners.FirstOrDefaultAsync(x => x.IsPresident && x.UserName.Equals(commissioner.UserName) && x.Password.Equals(commissioner.Password))); }
                catch (Exception e)
                {
                    throw new Exception("Something went wrong. could not log in as president", e);
                }
            }
            else if (commissioner.IsAdmin)
            {
                try
                { return(await _context.Commissioners.FirstOrDefaultAsync(x => x.IsAdmin && x.UserName.Equals(commissioner.UserName) && x.Password.Equals(commissioner.Password))); }
                catch (Exception e)
                {
                    throw new Exception("Something went wrong. could not log in as admin", e);
                }
            }
            else if (commissioner.IsPresident)
            {
                try
                { return(await _context.Commissioners.FirstOrDefaultAsync(x => x.IsPresident && x.UserName.Equals(commissioner.UserName) && x.Password.Equals(commissioner.Password))); }
                catch (Exception e)
                {
                    throw new Exception("Something went wrong. could not log in as president", e);
                }
            }
            else
            {
                try
                {
                    var result = await _context.Commissioners.FirstOrDefaultAsync(x => x.UserName.Equals(commissioner.UserName, StringComparison.InvariantCultureIgnoreCase) &&
                                                                                  x.Password.Equals(commissioner.Password));

                    return(result);
                }
                catch (Exception e)
                {
                    throw new Exception("Something went wrong. could not log in ", e);
                }
            }
        }
Ejemplo n.º 2
0
        public AdminMenuPage(Commissioner commissioner)
        {
            Commissioner = commissioner;

            container = new BootStrapper().BootStrap();
            InitializeComponent();
            BtnDeclareVotes.Click     += BtnDeclareVotes_Click;
            BtnDispensePassword.Click += BtnDispensePassword_Click;
            Loaded += AdminMenuPage_Loaded;
            BtnAddFaculty.Click += BtnAddFaculty_Click;
        }
Ejemplo n.º 3
0
        public async Task <Commissioner> SaveCommissioner(Commissioner commissioner)
        {
            if (commissioner == null)
            {
                throw new ArgumentNullException(nameof(commissioner));
            }
            if (commissioner.Id == 0)
            {
                try
                {
                    await _context.Commissioners.AddAsync(commissioner);

                    await _context.SaveChangesAsync();

                    return(commissioner);
                }
                catch (Exception e)
                {
                    throw new Exception("Something went wrong. we could not add commisioner", e);
                }
            }
            else
            {
                try
                {
                    _context.Commissioners.Update(commissioner);
                    await _context.SaveChangesAsync();

                    return(commissioner);
                }
                catch (Exception e)
                {
                    throw new Exception("Something went wrong. we could not update commisioner", e);
                }
            }
        }