Ejemplo n.º 1
0
        public string DeleteUser(iMentorUserInfo user)
        {
            if (user != null)
            {
                using (iMAST_dbEntities db = new iMAST_dbEntities())
                {
                    var u = db.iMentorUsers.Where(x => x.Email.Equals(user.Email)).FirstOrDefault();

                    if (u != null)
                    {
                        db.iMentorUsers.Remove(u);
                        db.SaveChanges();

                        DeleteAspUser(user);

                        return "User Deleted";
                    }
                    else
                    {
                        return "Invalid User";
                    }

                }
            }
            else
            {
                return "Invalid User";
            }
        }
Ejemplo n.º 2
0
        public string RemoveUserAssignments(iMentorUserInfo user)
        {
            if (user != null)
            {
                using (iMAST_dbEntities db = new iMAST_dbEntities())
                {
                    var assignments = db.AssignedListings.Where(x => x.UserId == user.Id).ToList();

                    if (assignments != null || assignments.Count == 0)
                    {
                        foreach(AssignedListing assignment in assignments)
                        {
                            db.AssignedListings.Remove(assignment);
                            db.SaveChanges();
                        }
                        return "Assignment Removed";
                    }
                    else
                    {
                        return "No assignment found";
                    }
                }
            }
            else
            {
                return "Invalid Assignment";
            }
        }
Ejemplo n.º 3
0
        public List<iMentorUserInfo> GetAllUsers()
        {
            using (iMAST_dbEntities db = new iMAST_dbEntities())
            {
                var iMentorUsers = db.iMentorUsers.ToList();

                List<iMentorUserInfo> users = new List<iMentorUserInfo>();

                foreach (iMentorUser user in iMentorUsers)
                {
                    var u = new iMentorUserInfo();

                    u.Id = user.Id;
                    u.UrlId = user.UrlId;
                    u.UserName = user.UserName;
                    u.FirstName = user.FirstName;
                    u.LastName = user.LastName;
                    u.Email = user.Email;
                    u.RoleId = u.GetRoleIdByUser(user);
                    u.Role = u.GetRoleName(user);
                    u.ShowOnlyAssignedListings = user.ShowOnlyAssignedListings;
                    u.IconIndex = user.IconIndex;

                    users.Add(u);
                }

                return users;
            }
        }
Ejemplo n.º 4
0
 public List<iMentorRole> GetRoles()
 {
     using (iMAST_dbEntities db = new iMAST_dbEntities())
     {
         return db.iMentorRoles.ToList();
     }
 }
Ejemplo n.º 5
0
        public string RemoveApplicant(Applicant applicant)
        {
            if (applicant != null)
            {
                using (iMAST_dbEntities db = new iMAST_dbEntities())
                {
                    var a = db.Applicants.Where(x => x.UserId == applicant.UserId && x.ListingId == applicant.ListingId).FirstOrDefault();

                    if (a != null)
                    {
                        db.Applicants.Remove(a);
                        db.SaveChanges();
                        return "Applicant Removed";
                    }
                    else
                    {
                        return "Invalid Applicant";
                    }
                }
            }
            else
            {
                return "Invalid Applicant";
            }
        }
Ejemplo n.º 6
0
        public string RemoveUserApplications(iMentorUserInfo user)
        {
            if (user != null)
            {
                using (iMAST_dbEntities db = new iMAST_dbEntities())
                {
                    var applications = db.Applicants.Where(x => x.UserId == user.Id).ToList();

                    if (applications != null || applications.Count == 0)
                    {
                        foreach(Applicant applicant in applications)
                        {
                            db.Applicants.Remove(applicant);
                            db.SaveChanges();
                        }
                        return "Applicant Removed";
                    }
                    else
                    {
                        return "No application found";
                    }
                }
            }
            else
            {
                return "Invalid Applicant";
            }
        }
Ejemplo n.º 7
0
 public List<Applicant> GetApplicants()
 {
     using (iMAST_dbEntities db = new iMAST_dbEntities())
     {
         return db.Applicants.ToList();
     }
 }
Ejemplo n.º 8
0
        public string RemoveUserRole(iMentorUserInfo user)
        {
            if(user != null)
            {
                using (iMAST_dbEntities db = new iMAST_dbEntities())
                {
                    var u = db.iMentorUserRoles.Where(x => x.UserId == user.Id).FirstOrDefault();

                    if(u != null)
                    {
                        db.iMentorUserRoles.Remove(u);
                        db.SaveChanges();

                        return "User Role Removed";
                    }
                    else
                    {
                        return "No user role found";
                    }

                }
            }
            else
            {
                return "Invalid User Role";
            }
        }
Ejemplo n.º 9
0
 public List<AssignedListing> GetAssignments()
 {
     using (iMAST_dbEntities db = new iMAST_dbEntities())
     {
         return db.AssignedListings.ToList();
     }
 }
Ejemplo n.º 10
0
        public string DeleteListing(ListingModel listing)
        {
            if (listing != null)
            {
                using (iMAST_dbEntities db = new iMAST_dbEntities())
                {
                    var l = db.ListingModels.Where(x => x.Id == listing.Id).FirstOrDefault();

                    if (l != null)
                    {
                        DeleteAssociatedAssignments(l);
                        DeleteAssociatedApplications(l);

                        db.ListingModels.Remove(l);
                        db.SaveChanges();
                        return "Listing Deleted";
                    }
                    else
                    {
                        return "Invalid Listing";
                    }
                }
            }
            else
            {
                return "Invalid Listing";
            }
        }
Ejemplo n.º 11
0
        public List<ListingInfo> GetListings()
        {
            using (iMAST_dbEntities db = new iMAST_dbEntities())
            {
                var listingModels = db.ListingModels.ToList();
                List<ListingInfo> listings = new List<ListingInfo>();

                foreach (ListingModel listing in listingModels)
                {
                    var l = new ListingInfo();
                    l.Id = listing.Id;
                    l.UrlId = listing.UrlId;
                    l.Title = listing.Title;
                    l.StartDate = listing.StartDate;
                    l.EndDate = listing.EndDate;
                    l.Area = listing.Area;
                    l.AgeGroup = listing.AgeGroup;
                    l.Frequency = listing.Frequency;
                    l.Description = listing.Description;
                    l.HangoutUrl = listing.HangoutUrl;
                    l.HangoutStart = listing.HangoutStart;
                    l.TeacherId = listing.TeacherId;
                    l.Open = listing.Open;
                    l.Teacher = l.GetTeacherUserName(listing);

                    listings.Add(l);
                }

                CheckForExpiredListings(listings);
                CheckForExpiredHangouts(listings);

                return listings;
            }
        }
Ejemplo n.º 12
0
        public ListingModel AddListing(ListingModel listing)
        {
            if (listing != null)
            {
                using (iMAST_dbEntities db = new iMAST_dbEntities())
                {
                    try
                    {
                        db.ListingModels.Add(listing);
                        db.SaveChanges();

                        //Return the listing because it now has its new Id
                        return listing;
                    }
                    catch (Exception err)
                    {
                        return null;
                    }
                }
            }
            else
            {
                return null;
            }
        }
Ejemplo n.º 13
0
        public string RemoveParticipant(AssignedListing assignment)
        {
            if (assignment != null)
            {
                using (iMAST_dbEntities db = new iMAST_dbEntities())
                {
                    var a = db.AssignedListings.Where(x => x.Id == assignment.Id).FirstOrDefault();

                    if (a != null)
                    {
                        db.AssignedListings.Remove(a);
                        db.SaveChanges();
                        return "Assignment Removed";
                    }
                    else
                    {
                        return "Invalid Assignment";
                    }
                }
            }
            else
            {
                return "Invalid Assignment";
            }
        }
Ejemplo n.º 14
0
        public int GetRoleIdByUser(iMentorUser user)
        {
            using (iMAST_dbEntities db = new iMAST_dbEntities())
            {
                var userRole = db.iMentorUserRoles.Where(x => x.UserId == user.Id).FirstOrDefault();

                var result = userRole.RoleId;

                return result;
            }
        }
Ejemplo n.º 15
0
        public string AddApplicant(Applicant applicant)
        {
            if (applicant != null)
            {
                using (iMAST_dbEntities db = new iMAST_dbEntities())
                {
                    db.Applicants.Add(applicant);
                    db.SaveChanges();

                    return "Assignment Added";
                }
            }
            else
            {
                return "Invalid Assignment";
            }
        }
Ejemplo n.º 16
0
        public string AddParticipant(AssignedListing assignment)
        {
            if (assignment != null)
            {
                using (iMAST_dbEntities db = new iMAST_dbEntities())
                {
                    try
                    {
                        db.AssignedListings.Add(assignment);
                        db.SaveChanges();

                        return "Assignment Added";
                    }
                    catch (Exception err)
                    {
                        return err.ToString();
                    }
                }
            }
            else
            {
                return "Invalid Assignment";
            }
        }
Ejemplo n.º 17
0
        private void DeleteAssociatedAssignments(ListingModel listing)
        {
            using (iMAST_dbEntities db = new iMAST_dbEntities())
            {
                var assignments = db.AssignedListings.Where(x => x.ListingId == listing.Id).ToList();

                foreach (AssignedListing assignment in assignments)
                {
                    db.AssignedListings.Remove(assignment);
                    db.SaveChanges();
                }
            }
        }
Ejemplo n.º 18
0
        private void DeleteAssociatedApplications(ListingModel listing)
        {
            using (iMAST_dbEntities db = new iMAST_dbEntities())
            {
                var applicants = db.Applicants.Where(x => x.ListingId == listing.Id).ToList();

                foreach (Applicant applicant in applicants)
                {
                    db.Applicants.Remove(applicant);
                    db.SaveChanges();
                }
            }
        }
Ejemplo n.º 19
0
        public string UpdateListing(ListingInfo listing)
        {
            if (listing != null)
            {
                using (iMAST_dbEntities db = new iMAST_dbEntities())
                {
                    int no = Convert.ToInt32(listing.Id);
                    var l = db.ListingModels.Where(x => x.Id == no).FirstOrDefault();

                    if (l != null)
                    {
                        l.Title = listing.Title;
                        l.UrlId = listing.UrlId;
                        l.StartDate = listing.StartDate;
                        l.EndDate = listing.EndDate;
                        l.Area = listing.Area;
                        l.AgeGroup = listing.AgeGroup;
                        l.Frequency = listing.Frequency;
                        l.Description = listing.Description;
                        l.HangoutUrl = listing.HangoutUrl;
                        l.HangoutStart = listing.HangoutStart;
                        l.TeacherId = listing.TeacherId;
                        l.Open = listing.Open;
                        db.SaveChanges();
                        return "Listing Updated";
                    }
                    else
                    {
                        return "Invalid Listing";
                    }
                }
            }
            else
            {
                return "Invalid Listing";
            }
        }
Ejemplo n.º 20
0
        public iMentorUserInfo GetCurrentUser(string userName)
        {
            var currentUserName = userName;
            var user = new iMentorUserInfo();

            if (!currentUserName.Equals(""))
            {
                using (iMAST_dbEntities db = new iMAST_dbEntities())
                {
                    var iMentorUser = db.iMentorUsers.Where(x => x.UserName.Equals(currentUserName)).FirstOrDefault();

                    if (iMentorUser != null)
                    {
                        user.Id = iMentorUser.Id;
                        user.UrlId = iMentorUser.UrlId;
                        user.UserName = iMentorUser.UserName;
                        user.FirstName = iMentorUser.FirstName;
                        user.LastName = iMentorUser.LastName;
                        user.Email = iMentorUser.Email;
                        user.RoleId = user.GetRoleIdByUser(iMentorUser);
                        user.Role = user.GetRoleName(iMentorUser);
                        user.ShowOnlyAssignedListings = iMentorUser.ShowOnlyAssignedListings;
                        user.IconIndex = iMentorUser.IconIndex;
                    }
                }
            }

            return user;
        }
Ejemplo n.º 21
0
        public string UpdateUser(iMentorUserInfo user)
        {
            if (user != null)
            {
                UpdateAspUser(user);
                using (iMAST_dbEntities db = new iMAST_dbEntities())
                {
                    int no = Convert.ToInt32(user.Id);
                    var u = db.iMentorUsers.Where(x => x.Id == no).FirstOrDefault();

                    if (u != null)
                    {
                        u.Id = user.Id;
                        u.UrlId = user.UrlId;
                        u.UserName = user.UserName;
                        u.FirstName = user.FirstName;
                        u.LastName = user.LastName;
                        u.Email = user.Email;
                        u.ShowOnlyAssignedListings = user.ShowOnlyAssignedListings;
                        u.IconIndex = user.IconIndex;

                        var role = db.iMentorRoles.Where(x => x.RoleName.Equals(user.Role)).FirstOrDefault();
                        var userRole = db.iMentorUserRoles.Where(x => x.UserId == user.Id).FirstOrDefault();
                        userRole.RoleId = role.Id;

                        db.SaveChanges();
                        return "User Updated";
                    }
                    else
                    {
                        return "Invalid User";
                    }
                }
            }
            else
            {
                return "Invalid User";
            }
        }
Ejemplo n.º 22
0
        public string UpdateAspUser(iMentorUserInfo user)
        {
            if (user != null)
            {
                using (iMAST_dbEntities db = new iMAST_dbEntities())
                {
                    var aspUser = db.AspNetUsers.Where(x => x.Email.Equals(user.Email)).FirstOrDefault();

                    if (aspUser != null)
                    {
                        aspUser.UserName = user.UserName;
                        aspUser.Email = user.Email;

                        db.SaveChanges();

                        return "Asp User Updated";
                    }
                    else
                    {
                        return "Invalid Asp User";
                    }

                }
            }
            else
            {
                return "Invalid Asp User";
            }
        }
Ejemplo n.º 23
0
        public List<iMentorUserInfo> GetUsersByListing(string data)
        {
            using (iMAST_dbEntities db = new iMAST_dbEntities())
            {
                var users = new List<iMentorUserInfo>();

                if (data != null)
                {
                    var userIds = new List<int>();
                    int id = Convert.ToInt32(data);

                    if (id > 0)
                    {
                        var listing = db.ListingModels.Where(x => x.Id == id).FirstOrDefault();

                        var assignments = db.AssignedListings.Where(x => x.ListingId == listing.Id).ToList();

                        foreach (AssignedListing assignment in assignments)
                        {
                            var user = db.iMentorUsers.Where(x => x.Id == assignment.UserId).FirstOrDefault();

                            var u = new iMentorUserInfo();
                            u.Id = user.Id;
                            u.UrlId = user.UrlId;
                            u.UserName = user.UserName;
                            u.FirstName = user.FirstName;
                            u.LastName = user.LastName;
                            u.Email = user.Email;
                            u.RoleId = u.GetRoleIdByUser(user);
                            u.Role = u.GetRoleName(user);
                            u.ShowOnlyAssignedListings = user.ShowOnlyAssignedListings;
                            u.IconIndex = user.IconIndex;

                            users.Add(u);
                        }
                    }
                }

                return users;
            }
        }
Ejemplo n.º 24
0
 public iMentorUser GetUserById(string userId)
 {
     using (iMAST_dbEntities db = new iMAST_dbEntities())
     {
         var id = Convert.ToInt32(userId);
        return db.iMentorUsers.Where(x => x.Id == id).FirstOrDefault();
     }
 }
Ejemplo n.º 25
0
        public string GetRoleName(iMentorUser user)
        {
            using (iMAST_dbEntities db = new iMAST_dbEntities())
            {
                var userRole = db.iMentorUserRoles.Where(x => x.UserId == user.Id).FirstOrDefault();
                var role = db.iMentorRoles.Where(x => x.Id == userRole.RoleId).FirstOrDefault();

                var result = role.RoleName;

                return result;
            }
        }
Ejemplo n.º 26
0
        public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return RedirectToAction("Index", "Manage");
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();
                if (info == null)
                {
                    return View("ExternalLoginFailure");
                }
                var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
                var result = await UserManager.CreateAsync(user);
                if (result.Succeeded)
                {

                    //Create the iMentorUser entry
                    using (iMAST_dbEntities db = new iMAST_dbEntities())
                    {
                        bool userExists = false;

                        foreach (iMentorUser u in db.iMentorUsers.ToList())
                        {
                            if (u.Email.Equals(user.Email))
                            {
                                userExists = true;
                            }
                        }

                        //Create the user
                        if (!userExists)
                        {
                            var imUser = new iMentorUser();
                            imUser.UserName = user.UserName;
                            imUser.Email = user.Email;
                            imUser.UrlId = GetNewUrlId();
                            
                            db.iMentorUsers.Add(imUser);
                            db.SaveChanges();


                            //Create the Role
                            var imUserRole = new iMentorUserRole();
                            imUserRole.UserId = imUser.Id;
                            imUserRole.RoleId = db.iMentorRoles.Where(x => x.RoleName.Equals("Read Only")).FirstOrDefault().Id; //Default role is "Read Only"
                            
                            db.iMentorUserRoles.Add(imUserRole);
                            db.SaveChanges();
                        }
                    }

                    result = await UserManager.AddLoginAsync(user.Id, info.Login);
                    if (result.Succeeded)
                    {
                        await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                        return RedirectToAction("Index", "Home");
                    }
                }
                AddErrors(result);
            }

            //ViewBag.ReturnUrl = returnUrl;

            //return View(model);
            return RedirectToAction("Index", "Home");
        }
Ejemplo n.º 27
0
        public int GetTeacherIdByName(string teacherName)
        {
            using (iMAST_dbEntities db = new iMAST_dbEntities())
            {
                var role = db.iMentorUsers.Where(x => x.UserName.Equals(teacherName)).FirstOrDefault();
                var result = role.Id;

                return result;
            }
        }
Ejemplo n.º 28
0
        public List<ListingInfo> GetListingsByCurrentUser(string userName)
        {
            var currentUserName = userName;
            List<ListingInfo> listings = new List<ListingInfo>();
            var userInDatabase = false;

            //Check if the current user is in the database
            using (iMAST_dbEntities db = new iMAST_dbEntities())
            {
                userInDatabase = db.iMentorUsers.Where(x => x.UserName.Equals(currentUserName)).FirstOrDefault() != null;
            }

            if (userInDatabase)
            {
                using (iMAST_dbEntities db = new iMAST_dbEntities())
                {
                    //Get the current user from the database
                    var iMentorUser = db.iMentorUsers.Where(x => x.UserName.Equals(currentUserName)).FirstOrDefault();

                    //Get current users assigned listings
                    var assignments = db.AssignedListings.Where(x => x.UserId == iMentorUser.Id);

                    //Get listings base on the assignments
                    var assidnedListings = new List<ListingModel>();
                    foreach (AssignedListing assignment in assignments)
                    {
                        assidnedListings.Add(db.ListingModels.Where(x => x.Id == assignment.ListingId).FirstOrDefault());
                    }

                    foreach (ListingModel listing in assidnedListings)
                    {
                        var l = new ListingInfo();
                        l.Id = listing.Id;
                        l.UrlId = listing.UrlId;
                        l.Title = listing.Title;
                        l.StartDate = listing.StartDate;
                        l.EndDate = listing.EndDate;
                        l.Area = listing.Area;
                        l.AgeGroup = listing.AgeGroup;
                        l.Frequency = listing.Frequency;
                        l.Description = listing.Description;
                        l.HangoutUrl = listing.HangoutUrl;
                        l.HangoutStart = listing.HangoutStart;
                        l.TeacherId = listing.TeacherId;
                        l.Open = listing.Open;
                        l.Teacher = l.GetTeacherUserName(listing);

                        listings.Add(l);
                    }

                    CheckForExpiredListings(listings);
                }
            }

            return listings;
        }
Ejemplo n.º 29
0
        public iMentorUser ReturnLastAddedUser()
        {
            using (iMAST_dbEntities db = new iMAST_dbEntities())
            {
                var lastAdded = (from n in db.iMentorUsers
                                 orderby n.Id descending
                                 select n).FirstOrDefault();
                return lastAdded;

            }
        }
Ejemplo n.º 30
0
        public string GetTeacherName(ListingModel listing)
        {
            using (iMAST_dbEntities db = new iMAST_dbEntities())
            {
                var teacher = db.iMentorUsers.Where(x => x.Id == listing.TeacherId).FirstOrDefault();
                var result = teacher.UserName;

                return result;
            }
        }