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)); }
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"); } }
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"); } }
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"); } }
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"); } }
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"); } }
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"); } }
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); } }
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(); } } }
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(); } } }
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"); } }
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"); } }
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"); } }
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"); } }
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")); }