public async Task <ActionResult> UpdateTask(Automation_Tasks task) { var newItem = database.Automation_Tasks.Find(task.ID); database.Entry(task).State = EntityState.Modified; await database.SaveChangesAsync(); return(new ContentResult { Content = JsonConvert.SerializeObject(newItem), ContentType = "application/json", ContentEncoding = Encoding.UTF8 }); }
public IHttpActionResult PutKhachHang(string id, KhachHang khachHang) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != khachHang.KhachHang_ID) { return(BadRequest()); } db.Entry(khachHang).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!KhachHangExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutDichVu(string id, DichVu dichVu) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != dichVu.DichVu_ID) { return(BadRequest()); } db.Entry(dichVu).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!DichVuExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutDonHang(string id, DonHang donHang) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != donHang.SoHieu) { return(BadRequest()); } db.Entry(donHang).State = EntityState.Modified; try { //Update loại hàng UpdateLoaiHang(donHang.LoaiHang_Name); db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!DonHangExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutNhanVien(string id, NhanVien nhanVien) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != nhanVien.NhanVien_ID) { return(BadRequest()); } db.Entry(nhanVien).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!NhanVienExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public bool RemoveAmbassFromSchool(int?selected_school_id) { //Input validation if (selected_school_id == null || selected_school_id < 0) { return(false); } //Remove ambassador from selected school using (var context = new MainDBEntities()) { //Find project with id = project_id, store in temp_project School school = context.Schools.Find(selected_school_id); //Ensure there's a point to the update if (school.Username == null || school.Username == "") { return(true); } //Ensure user is actually ambassador before assignment and that //user actually exists in database school.Username = null; //Verify that valid project was found context.Schools.Add(school); //Indicate modification and make changes persistent context.Entry(school).State = EntityState.Modified; context.SaveChanges(); //Return true indicating successful project edit return(true); } }
public IHttpActionResult PutTinhThanhPho(string id, TinhThanhPho tinhThanhPho) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != tinhThanhPho.TinhThanhPho_ID) { return(BadRequest()); } db.Entry(tinhThanhPho).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!TinhThanhPhoExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutAspNetUsers(string id, AspNetUsers aspNetUsers) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != aspNetUsers.Id) { return(BadRequest()); } db.Entry(aspNetUsers).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!AspNetUsersExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Edit([Bind(Include = "GroupID,GroupTitle")] Product_Groups product_Groups) { if (ModelState.IsValid) { db.Entry(product_Groups).State = EntityState.Modified; db.SaveChanges(); return(PartialView("ListGroup", db.Product_Groups.ToList())); } return(View(product_Groups)); }
public ActionResult Edit([Bind(Include = "ID,Title,Text,ForumGroupID,CreatedBy,CreatedDate")] ForumPosts forumPosts) { if (ModelState.IsValid) { db.Entry(forumPosts).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ForumGroupID = new SelectList(db.ForumGroups, "ID", "Title", forumPosts.ForumGroupID); return(View(forumPosts)); }
public ActionResult EditNews(News news, HttpPostedFileBase NewImage) { if (ModelState.IsValid) { if (NewImage != null)//اگر عکس انتخاب شده بود { if (news.Image != "no-photo.jpg") { //System.IO.File.SetAttributes(Server.MapPath("~/Content/News/Images/" + news.Image), FileAttributes.Normal); System.IO.File.Delete(Server.MapPath("~/Content/News/Images/" + news.Image)); } news.Image = Guid.NewGuid().ToString() + Path.GetExtension(NewImage.FileName); NewImage.InputStream.ResizeImage(800, 448, Path.Combine(Server.MapPath("/Content/News/Images"), news.Image)); } database.Entry(news).State = EntityState.Modified; database.SaveChanges(); return(RedirectToAction("newsIndex", "News")); } return(View(news)); }
public bool AdminUpdateProjectStatus(int project_id, string new_status) { //Perform input validation if (new_status == null || new_status == "") { return(false); } if ((new_status != ProjectStatus.ASSIGNED) && (new_status != ProjectStatus.IN_PROGRESS) && (new_status != ProjectStatus.INTERN) && (new_status != ProjectStatus.PRODUCTION) && (new_status != ProjectStatus.ARCHIVED)) { return(false); } using (var context = new MainDBEntities()) { //Access object checks if (this.GetType() == typeof(AdminAccess)) { ProjectAssignment current_project = new ProjectAssignment(); //Read in necessary object current_project = context.ProjectAssignments.Find(project_id); //Modify status current_project.ProgressStatus = new_status; //Indicate that that value has been modified context.ProjectAssignments.Attach(current_project); var entry = context.Entry(current_project); //Indicate that IsArchived property has been modified (indicates to EF that property //needs update entry.Property(x => x.ProgressStatus).IsModified = true; //Save update context.SaveChanges(); //Indicate successful update return(true); } else { //Invalid access object return(false); } } }
public bool UpdateUserRole(string username, int?new_role) { if (username == null || username == "") { return(false); } if ((new_role != UserRole.ADMIN) && (new_role != UserRole.AMBASSADOR) && (new_role != UserRole.CONTRIBUTOR)) { return(false); } using (var context = new MainDBEntities()) { User selected_user = context.Users.Find(username); if (selected_user == null) { return(false); } //Modify status if (new_role != null) { selected_user.UserRole = (int)new_role; } else { return(false); } //Indicate that that value has been modified context.Users.Attach(selected_user); var entry = context.Entry(selected_user); //Indicate that IsArchived property has been modified (indicates to EF that property //needs update entry.Property(x => x.UserRole).IsModified = true; //Save update context.SaveChanges(); //Indicate successful archive return(true); } }
public ActionResult UpdateDescription_ReturenedProduct_Async(Guid genericId, string Description) { var name = database.USERS.Find(new Guid(HttpContext.User.Identity.Name)).LFName; var item = database.BaniChav_ReturnedProducts.FirstOrDefault(q => q.genericId == genericId); item.Description = item.Description + "<br/>" + name + Description; database.Entry(item).State = EntityState.Modified; database.SaveChanges(); return(new ContentResult { Content = JsonConvert.SerializeObject("ثبت با موفقیت انجام شد"), ContentType = "application/json", ContentEncoding = Encoding.UTF8, }); }
public bool UpdateActiveStatusToInProg(int?active_project_id) { //Input checks if (active_project_id == null) { return(false); } if (active_project_id < 0) { return(false); } using (var context = new MainDBEntities()) { //Access object checks if ((this.GetType() == typeof(AdminAccess)) || (this.GetType() == typeof(AmbassadorAccess))) { ProjectAssignment active_project = new ProjectAssignment(); //Read in necessary object active_project = context.ProjectAssignments.Find(active_project_id); //Modify status active_project.ProgressStatus = ProjectStatus.IN_PROGRESS; //Indicate that that value has been modified context.ProjectAssignments.Attach(active_project); var entry = context.Entry(active_project); //Indicate that IsArchived property has been modified (indicates to EF that property //needs update entry.Property(x => x.ProgressStatus).IsModified = true; //Save update context.SaveChanges(); //Indicate successful archive return(true); } else { //Invalid access object return(false); } } }
public bool AddAmbassToSchool(int?selected_school_id, string new_ambassador_username) { //Input validation if (selected_school_id == null || selected_school_id < 0) { return(false); } if (new_ambassador_username == null || new_ambassador_username == "") { return(false); } using (var context = new MainDBEntities()) { //Find project with id = project_id, store in temp_project School school = context.Schools.Find(selected_school_id); User ambassador = context.Users.Find(new_ambassador_username); //Perform input validation if (school == null || ambassador == null) { return(false); } //Ensure user is actually ambassador before assignment and that //user actually exists in database if (ambassador.UserRole != UserRole.AMBASSADOR) { return(false); } else { school.Username = new_ambassador_username; //Verify that valid project was found context.Schools.Add(school); //Indicate modification and make changes persistent context.Entry(school).State = EntityState.Modified; context.SaveChanges(); //Return true indicating successful project edit return(true); } } }
public ActionResult Edit([Bind(Include = "userId,email,userName,password,firstName,lastName")] user userE) { if (ModelState.IsValid) { try { using (var dc = new MainDBEntities()) { //user userEdit = dc.users.Find(userId); dc.Entry(userE).State = EntityState.Modified; dc.SaveChanges(); return(RedirectToAction("List")); } } catch { ModelState.AddModelError("", "Add value to the password field"); return(View()); } } return(View(userE)); }
//Func Desc: Used to mark the project with primary key id to archived. // Input: Int representing id of project to archive. // Output: A bool indicating whether update was successful or not. T = success, F = failure. public bool ArchiveProject(int?id) { if (id == null) { return(false); } using (var context = new MainDBEntities()) { //Retrieve project Project project = context.Projects.Find(id); //Mark the project as archived if (project != null) { project.IsArchived = true; } else { //Indicate error status return(false); } //Indicate that that value has been modified context.Projects.Attach(project); var entry = context.Entry(project); //Indicate that IsArchived property has been modified (indicates to EF that property //needs update entry.Property(x => x.IsArchived).IsModified = true; //Save update context.SaveChanges(); //Indicate successful archive return(true); } }
public bool AddAmbassToSchool(int? selected_school_id, string new_ambassador_username) { //Input validation if (selected_school_id == null || selected_school_id < 0) { return false; } if (new_ambassador_username == null || new_ambassador_username == "") { return false; } using (var context = new MainDBEntities()) { //Find project with id = project_id, store in temp_project School school = context.Schools.Find(selected_school_id); User ambassador = context.Users.Find(new_ambassador_username); //Perform input validation if (school == null || ambassador == null) { return false; } //Ensure user is actually ambassador before assignment and that //user actually exists in database if (ambassador.UserRole != UserRole.AMBASSADOR) { return false; } else { school.Username = new_ambassador_username; //Verify that valid project was found context.Schools.Add(school); //Indicate modification and make changes persistent context.Entry(school).State = EntityState.Modified; context.SaveChanges(); //Return true indicating successful project edit return true; } } }
public bool AdminUpdateProjectStatus(int project_id, string new_status) { //Perform input validation if (new_status == null || new_status == "") { return false; } if( (new_status != ProjectStatus.ASSIGNED) && (new_status != ProjectStatus.IN_PROGRESS) && (new_status != ProjectStatus.INTERN) && (new_status != ProjectStatus.PRODUCTION) && (new_status != ProjectStatus.ARCHIVED) ) { return false; } using (var context = new MainDBEntities()) { //Access object checks if (this.GetType() == typeof(AdminAccess)) { ProjectAssignment current_project = new ProjectAssignment(); //Read in necessary object current_project = context.ProjectAssignments.Find(project_id); //Modify status current_project.ProgressStatus = new_status; //Indicate that that value has been modified context.ProjectAssignments.Attach(current_project); var entry = context.Entry(current_project); //Indicate that IsArchived property has been modified (indicates to EF that property //needs update entry.Property(x => x.ProgressStatus).IsModified = true; //Save update context.SaveChanges(); //Indicate successful update return true; } else { //Invalid access object return false; } } }
public bool UpdateUserRole(string username, int? new_role) { if (username == null || username == "") { return false; } if ( (new_role != UserRole.ADMIN) && (new_role != UserRole.AMBASSADOR) && (new_role != UserRole.CONTRIBUTOR)) { return false; } using (var context = new MainDBEntities()) { User selected_user = context.Users.Find(username); if (selected_user == null) { return false; } //Modify status if (new_role != null) { selected_user.UserRole = (int)new_role; } else { return false; } //Indicate that that value has been modified context.Users.Attach(selected_user); var entry = context.Entry(selected_user); //Indicate that IsArchived property has been modified (indicates to EF that property //needs update entry.Property(x => x.UserRole).IsModified = true; //Save update context.SaveChanges(); //Indicate successful archive return true; } }
public bool UpdateActiveStatusToProduction(int? active_project_id) { //Input checks if (active_project_id == null) { return false; } if (active_project_id < 0) { return false; } using (var context = new MainDBEntities()) { //Access object checks if ((this.GetType() == typeof(AdminAccess)) || (this.GetType() == typeof(AmbassadorAccess))) { ProjectAssignment active_project = new ProjectAssignment(); //Read in necessary object active_project = context.ProjectAssignments.Find(active_project_id); //Modify status active_project.ProgressStatus = ProjectStatus.PRODUCTION; //Indicate that that value has been modified context.ProjectAssignments.Attach(active_project); var entry = context.Entry(active_project); //Indicate that IsArchived property has been modified (indicates to EF that property //needs update entry.Property(x => x.ProgressStatus).IsModified = true; //Save update context.SaveChanges(); //Indicate successful archive return true; } else { //Invalid access object return false; } } }
public bool RemoveAmbassFromSchool(int? selected_school_id) { //Input validation if (selected_school_id == null || selected_school_id < 0) { return false; } //Remove ambassador from selected school using (var context = new MainDBEntities()) { //Find project with id = project_id, store in temp_project School school = context.Schools.Find(selected_school_id); //Ensure there's a point to the update if (school.Username == null || school.Username == "") { return true; } //Ensure user is actually ambassador before assignment and that //user actually exists in database school.Username = null; //Verify that valid project was found context.Schools.Add(school); //Indicate modification and make changes persistent context.Entry(school).State = EntityState.Modified; context.SaveChanges(); //Return true indicating successful project edit return true; } }
//Func Desc: Used to mark the project with primary key id to archived. // Input: Int representing id of project to archive. // Output: A bool indicating whether update was successful or not. T = success, F = failure. public bool ArchiveProject(int? id) { if (id == null) { return false; } using (var context = new MainDBEntities()) { //Retrieve project Project project = context.Projects.Find(id); //Mark the project as archived if (project != null) { project.IsArchived = true; } else { //Indicate error status return false; } //Indicate that that value has been modified context.Projects.Attach(project); var entry = context.Entry(project); //Indicate that IsArchived property has been modified (indicates to EF that property //needs update entry.Property(x => x.IsArchived).IsModified = true; //Save update context.SaveChanges(); //Indicate successful archive return true; } }
public bool EditSchool(AdminSchoolViewModel vm_school) { if (vm_school == null) { return false; } try { using (var context = new MainDBEntities()) { ApplicationSpecificMapper mapper = new ApplicationSpecificMapper(); //Validate input if (mapper == null) { return false; } School school = (School)mapper.Map((AdminSchoolViewModel)vm_school, typeof(School)); //Validate input if (school == null) { return false; } //Create the project edit and populate necessary attributes SchoolEdit edit = new SchoolEdit(); edit.SchoolID = school.SchoolID; edit.Username = school.Username; edit.SchoolName = school.SchoolName; edit.Phone = (int)school.Phone; edit.Email = school.Email; edit.ContactEmail = school.ContactEmail; edit.ContactName = school.ContactName; edit.ContactPhone = school.ContactPhone; edit.Department = school.Department; edit.Class = school.Class; edit.StreetNumber = school.StreetNumber; edit.StreetName = school.StreetName; edit.ZipCode = school.ZipCode; edit.City = school.City; edit.State = school.State; edit.EditDate = DateTime.Now; context.SchoolEdits.Add(edit); //Indicate modification and make changes persistent context.Entry(school).State = EntityState.Modified; context.SaveChanges(); //Return true indicating successful project edit return true; } } catch { //There was an error during school edit return false; } }
public ActionResult Create(Products products, HttpPostedFileBase Image, HttpPostedFileBase[] Gallery, string Tags) { if (ModelState.IsValid) { products.Productimage = "no-photo.jpg"; db.Products.Add(products); db.SaveChanges(); if (Image != null) { Image.SaveAs(Server.MapPath("/Content/Product/Images/large/" + products.ProductID + "_" + Image.FileName)); ImageResizer img = new ImageResizer(); img.Resize(Server.MapPath("/Content/Product/Images/large/" + products.ProductID + "_" + Image.FileName), Server.MapPath("/Content/Product/Images/thumb/" + products.ProductID + "_" + Image.FileName)); products.Productimage = products.ProductID + "_" + Image.FileName; db.Entry(products).State = EntityState.Modified; } if (Gallery != null && Gallery.Any()) { foreach (HttpPostedFileBase gal in Gallery) { string imageName = Guid.NewGuid().ToString() + Path.GetExtension(gal.FileName); gal.SaveAs(Server.MapPath("/Content/Product/Images/large/" + imageName)); ImageResizer img = new ImageResizer(); img.Resize(Server.MapPath("/Content/Product/Images/large/" + imageName), Server.MapPath("/Content/Product/Images/thumb/" + imageName)); db.Product_Gallery.Add(new Product_Gallery() { ImageName = imageName, ProductID = products.ProductID, }); } } if (!string.IsNullOrEmpty(Tags)) { string[] Tag = Tags.Split('-'); foreach (string s in Tag) { db.Product_Tags.Add(new Product_Tags() { ProductID = products.ProductID, TagTitle = s.Trim().ToLower(), }); } } if (Session["Features"] != null) { List <FeatureItem> list = Session["Features"] as List <FeatureItem>; foreach (var feature in list) { db.Product_Features.Add(new Product_Features() { FeatureID = feature.FeatureID, Value = feature.Value, ProductID = products.ProductID, }); } Session["Features"] = null; } db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.GroupID = new SelectList(db.Product_Groups, "GroupID", "GroupTitle", products.GroupID); return(View(products)); }
//Func Desc: Used to return a project from its id. // Input: Int representing id of project to locate. // Output: An instance of the project that has the specified id, or null public bool EditProject(object vm_project) { //Input checks if (vm_project == null) { return false; } if ( (vm_project.GetType() != typeof(AdminProjectViewModel)) && (vm_project.GetType() != typeof(AmbassProjectViewModel)) && (vm_project.GetType() != typeof(ContributorProjectViewModel))) { //Invalid view model Debug.WriteLine("\n\n***** " + "View model input into EditProject of ContributorAccess is invalid in type. " + "ERROR IN: CommerceIdeaBank.DatabaseInterface.BusinessLogic.ContributorAccess EditProject()" + "*****\n\n" ); //Indicate failure in status return false; } using (var context = new MainDBEntities()) { ApplicationSpecificMapper mapper = new ApplicationSpecificMapper(); if (this.GetType() == typeof(AdminAccess)) { Project proj = (Project)mapper.Map((AdminProjectViewModel)vm_project, typeof(Project)); //Create the project edit and populate necessary attributes ProjectEdit edit = new ProjectEdit(); edit.Username = proj.Username; edit.ProjectID = proj.ProjectID; edit.EditDate = DateTime.Now; context.ProjectEdits.Add(edit); //Indicate modification and make changes persistent context.Entry(proj).State = EntityState.Modified; context.SaveChanges(); //Return true indicating successful project edit return true; } else if (this.GetType() == typeof(AmbassadorAccess)) { Project proj = (Project)mapper.Map((AmbassProjectViewModel)vm_project, typeof(Project)); //Create the project edit and populate necessary attributes ProjectEdit edit = new ProjectEdit(); edit.Username = proj.Username; edit.ProjectID = proj.ProjectID; edit.EditDate = DateTime.Now; context.ProjectEdits.Add(edit); //Indicate modification and make changes persistent context.Entry(proj).State = EntityState.Modified; context.SaveChanges(); //Return true indicating successful project edit return true; } else if (this.GetType() == typeof(ContributorAccess)) { Project proj = (Project)mapper.Map((ContributorProjectViewModel)vm_project, typeof(Project)); //Create the project edit and populate necessary attributes ProjectEdit edit = new ProjectEdit(); edit.Username = proj.Username; edit.ProjectID = proj.ProjectID; edit.EditDate = DateTime.Now; context.ProjectEdits.Add(edit); //Indicate modification and make changes persistent context.Entry(proj).State = EntityState.Modified; context.SaveChanges(); //Return true indicating successful project edit return true; } else { //Access type not recognized Debug.WriteLine("\n\n***** " + "Access object type wasn't recognized during EditProject(). " + "ERROR IN: CommerceIdeaBank.DatabaseInterface.BusinessLogic.ContributorAccess EditProject()" + "*****\n\n"); //Indicate error status return false; } } }
public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl) { string provider = null; string providerUserId = null; if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId)) { return(RedirectToAction("Manage")); } if (ModelState.IsValid) { // Insert a new user into the database using (MainDBEntities db = new MainDBEntities()) { user userEx = db.users.FirstOrDefault(u => u.email == model.UserName); // Check if user already exists if (userEx != null) { userEx.userName = model.twitterName; userEx.firstName = model.firstName; userEx.lastName = model.lastName; db.Entry(userEx).State = EntityState.Modified; db.SaveChanges(); FormsAuthentication.SetAuthCookie(userEx.email, false); return(RedirectToAction("List")); } if (userEx == null) { ///////////////////////////////////////// try { using (var df = new MainDBEntities()) { var sysUser = df.users.Create(); sysUser.userId = Guid.NewGuid(); sysUser.email = model.UserName; sysUser.password = "******"; sysUser.userName = model.twitterName; sysUser.firstName = model.firstName; sysUser.lastName = model.lastName; df.users.Add(sysUser); df.SaveChanges(); //return RedirectToAction("List"); FormsAuthentication.SetAuthCookie(model.UserName, false); return(RedirectToAction("List")); } } catch { ModelState.AddModelError("UserName", "User name or twitter name already exists. Please enter a different user name or twitter name."); } ///////////////////////////////// // Insert name into the profile table // db.UserProfiles.Add(new UserProfile { UserName = model.UserName }); // db.SaveChanges(); //OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName); //OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false); //return RedirectToLocal(returnUrl); } else { ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name."); } } } ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName; ViewBag.ReturnUrl = returnUrl; return(View(model)); }
public ActionResult EditGroup(ForumGroups group) { database.Entry(group).State = EntityState.Modified; database.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "userId,email,userName,password,firstName,lastName")] user userE) { if (ModelState.IsValid) { try { using (var dc = new MainDBEntities()) { //user userEdit = dc.users.Find(userId); dc.Entry(userE).State = EntityState.Modified; dc.SaveChanges(); return RedirectToAction("List"); } } catch { ModelState.AddModelError("", "Add value to the password field"); return View(); } } return View(userE); }
public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl) { string provider = null; string providerUserId = null; if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId)) { return RedirectToAction("Manage"); } if (ModelState.IsValid) { // Insert a new user into the database using (MainDBEntities db = new MainDBEntities()) { user userEx = db.users.FirstOrDefault(u => u.email == model.UserName); // Check if user already exists if (userEx != null) { userEx.userName = model.twitterName; userEx.firstName = model.firstName; userEx.lastName = model.lastName; db.Entry(userEx).State = EntityState.Modified; db.SaveChanges(); FormsAuthentication.SetAuthCookie(userEx.email, false); return RedirectToAction("List"); } if (userEx == null) { ///////////////////////////////////////// try { using (var df = new MainDBEntities()) { var sysUser = df.users.Create(); sysUser.userId = Guid.NewGuid(); sysUser.email = model.UserName; sysUser.password = "******"; sysUser.userName = model.twitterName; sysUser.firstName = model.firstName; sysUser.lastName = model.lastName; df.users.Add(sysUser); df.SaveChanges(); //return RedirectToAction("List"); FormsAuthentication.SetAuthCookie(model.UserName, false); return RedirectToAction("List"); } } catch { ModelState.AddModelError("UserName", "User name or twitter name already exists. Please enter a different user name or twitter name."); } ///////////////////////////////// // Insert name into the profile table // db.UserProfiles.Add(new UserProfile { UserName = model.UserName }); // db.SaveChanges(); //OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName); //OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false); //return RedirectToLocal(returnUrl); } else { ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name."); } } } ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName; ViewBag.ReturnUrl = returnUrl; return View(model); }
public ActionResult UserCreate(USERS user) { if (user.Username == "" || user.Username == null) { ModelState.AddModelError(string.Empty, "Username cannot be blank"); } try { if (ModelState.IsValid) { List <string> results = database.Database.SqlQuery <String>(string.Format("SELECT Username FROM USERS WHERE Username = '******'", user.Username)).ToList(); bool _userExistsInTable = (results.Count > 0); USERS _user = null; if (_userExistsInTable) { _user = database.USERS.Where(p => p.Username == user.Username).FirstOrDefault(); if (_user != null) { if (_user.Inactive == false) { ModelState.AddModelError(string.Empty, "USERS already exists!"); } else { database.Entry(_user).Entity.Inactive = false; database.Entry(_user).Entity.LastModified = System.DateTime.Now; database.Entry(_user).State = EntityState.Modified; database.SaveChanges(); return(RedirectToAction("Index")); } } } else { _user = new USERS(); _user.Username = user.Username; _user.Lastname = user.Lastname; _user.Firstname = user.Firstname; _user.Title = user.Title; _user.Initial = user.Initial; _user.EMail = user.EMail; if (ModelState.IsValid) { _user.Inactive = false; _user.LastModified = System.DateTime.Now; database.USERS.Add(_user); database.SaveChanges(); return(RedirectToAction("Index")); } } } } catch (Exception ex) { //return base.ShowError(ex); } return(View(user)); }
public bool EditSchool(AdminSchoolViewModel vm_school) { if (vm_school == null) { return(false); } try { using (var context = new MainDBEntities()) { ApplicationSpecificMapper mapper = new ApplicationSpecificMapper(); //Validate input if (mapper == null) { return(false); } School school = (School)mapper.Map((AdminSchoolViewModel)vm_school, typeof(School)); //Validate input if (school == null) { return(false); } //Create the project edit and populate necessary attributes SchoolEdit edit = new SchoolEdit(); edit.SchoolID = school.SchoolID; edit.Username = school.Username; edit.SchoolName = school.SchoolName; edit.Phone = (int)school.Phone; edit.Email = school.Email; edit.ContactEmail = school.ContactEmail; edit.ContactName = school.ContactName; edit.ContactPhone = school.ContactPhone; edit.Department = school.Department; edit.Class = school.Class; edit.StreetNumber = school.StreetNumber; edit.StreetName = school.StreetName; edit.ZipCode = school.ZipCode; edit.City = school.City; edit.State = school.State; edit.EditDate = DateTime.Now; context.SchoolEdits.Add(edit); //Indicate modification and make changes persistent context.Entry(school).State = EntityState.Modified; context.SaveChanges(); //Return true indicating successful project edit return(true); } } catch { //There was an error during school edit return(false); } }
//Func Desc: Used to return a project from its id. // Input: Int representing id of project to locate. // Output: An instance of the project that has the specified id, or null public bool EditProject(object vm_project) { //Input checks if (vm_project == null) { return(false); } if ((vm_project.GetType() != typeof(AdminProjectViewModel)) && (vm_project.GetType() != typeof(AmbassProjectViewModel)) && (vm_project.GetType() != typeof(ContributorProjectViewModel))) { //Invalid view model Debug.WriteLine("\n\n***** " + "View model input into EditProject of ContributorAccess is invalid in type. " + "ERROR IN: CommerceIdeaBank.DatabaseInterface.BusinessLogic.ContributorAccess EditProject()" + "*****\n\n"); //Indicate failure in status return(false); } using (var context = new MainDBEntities()) { ApplicationSpecificMapper mapper = new ApplicationSpecificMapper(); if (this.GetType() == typeof(AdminAccess)) { Project proj = (Project)mapper.Map((AdminProjectViewModel)vm_project, typeof(Project)); //Create the project edit and populate necessary attributes ProjectEdit edit = new ProjectEdit(); edit.Username = proj.Username; edit.ProjectID = proj.ProjectID; edit.EditDate = DateTime.Now; context.ProjectEdits.Add(edit); //Indicate modification and make changes persistent context.Entry(proj).State = EntityState.Modified; context.SaveChanges(); //Return true indicating successful project edit return(true); } else if (this.GetType() == typeof(AmbassadorAccess)) { Project proj = (Project)mapper.Map((AmbassProjectViewModel)vm_project, typeof(Project)); //Create the project edit and populate necessary attributes ProjectEdit edit = new ProjectEdit(); edit.Username = proj.Username; edit.ProjectID = proj.ProjectID; edit.EditDate = DateTime.Now; context.ProjectEdits.Add(edit); //Indicate modification and make changes persistent context.Entry(proj).State = EntityState.Modified; context.SaveChanges(); //Return true indicating successful project edit return(true); } else if (this.GetType() == typeof(ContributorAccess)) { Project proj = (Project)mapper.Map((ContributorProjectViewModel)vm_project, typeof(Project)); //Create the project edit and populate necessary attributes ProjectEdit edit = new ProjectEdit(); edit.Username = proj.Username; edit.ProjectID = proj.ProjectID; edit.EditDate = DateTime.Now; context.ProjectEdits.Add(edit); //Indicate modification and make changes persistent context.Entry(proj).State = EntityState.Modified; context.SaveChanges(); //Return true indicating successful project edit return(true); } else { //Access type not recognized Debug.WriteLine("\n\n***** " + "Access object type wasn't recognized during EditProject(). " + "ERROR IN: CommerceIdeaBank.DatabaseInterface.BusinessLogic.ContributorAccess EditProject()" + "*****\n\n"); //Indicate error status return(false); } } }