public IHttpActionResult PutiMentorUser(int id, iMentorUser iMentorUser)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != iMentorUser.Id)
            {
                return(BadRequest());
            }

            db.Entry(iMentorUser).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!iMentorUserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 2
0
        public IHttpActionResult PutListingModel(int id, ListingModel listingModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != listingModel.Id)
            {
                return(BadRequest());
            }

            db.Entry(listingModel).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ListingModelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        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.º 4
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.º 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");
            }
        }
        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.º 7
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.º 8
0
        public string DeleteAspUser(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)
                    {
                        db.AspNetUsers.Remove(aspUser);
                        db.SaveChanges();

                        return("Asp User Deleted");
                    }
                    else
                    {
                        return("Invalid Asp User");
                    }
                }
            }
            else
            {
                return("Invalid Asp User");
            }
        }
Ejemplo n.º 9
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.º 10
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.º 11
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.º 12
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.º 13
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.º 14
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.º 15
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.º 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
        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"));
        }