public async Task <IActionResult> validateQuestion(int?id) { var question = await _context.questions.FindAsync(id); question.validatedQuestion = true; _context.Update(question); await _context.SaveChangesAsync(); return(RedirectToAction("adminDashboard", "question")); }
public async Task <IActionResult> validateAnswer(int?id) { var answer = await _context.answers.FindAsync(id); answer.validatedAnswer = true; _context.Update(answer); await _context.SaveChangesAsync(); return(RedirectToAction("adminDashboard", "question")); }
public async Task<IActionResult> Edit(int id, [Bind("id,categoryname")] category category) { if (id != category.id) { return RedirectToAction("customErrorPage", "user"); } if (ModelState.IsValid) { try { _context.Update(category); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!categoryExists(category.id)) { return RedirectToAction("customErrorPage", "user"); } else { throw; } } return RedirectToAction(nameof(Index)); } return View(category); }
public async Task <IActionResult> Edit(int id, string userfname, string userlname, string username, string useremail, string userpassword, DateTimeOffset userdob, string useraddress, string usercountry, string companyname, string companydescription, int nbshareordinary, double sharevalueordinary, string descordinary, string additionalordinary, int nbsharepreferencial, double sharevaluepreferencial, string descpreferencial, string additionalpreferencial, int nbsharenonvoting, double sharevaluenonvoting, string descnonvoting, string additionalnonvoting, int nbshareredeemable, double sharevalueredeemable, string descredeemable, string additionalredeemable, double userassets, IFormFile fileUserphotoEdit, IFormFile fileCompanyLogoEdit, string editpart) { var user = await _context.users.FirstOrDefaultAsync(m => m.id == id); if (ModelState.IsValid) { try { if (user == null) { return(RedirectToAction("customErrorPage", "user")); } else { // if the user profile is to be modified if (editpart == "edituser") { // upload new user photo if (fileUserphotoEdit == null || fileUserphotoEdit.Length == 0) { user.userphoto = user.userphoto; } else { var newUserPhoto = "images/" + fileUserphotoEdit.FileName; if (newUserPhoto == user.userphoto) { user.userphoto = user.userphoto; } else { //save the new photo in the server var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images/", fileUserphotoEdit.FileName); using (var stream = new FileStream(path, FileMode.Create)) { await fileUserphotoEdit.CopyToAsync(stream); } user.userphoto = "images/" + fileUserphotoEdit.FileName; } } // set record's value to the new ones. If no parameter is given keep the old ones if (userfname == null) { user.userfname = user.userfname; } else { user.userfname = userfname; } if (userlname == null) { user.userlname = user.userlname; } else { user.userlname = userlname; } if (username == null) { user.username = user.username; } else { user.username = username; } if (useremail == null) { user.useremail = user.useremail; } else { user.useremail = useremail; } if (userpassword == null) { user.userpassword = user.userpassword; } else { user.userpassword = userpassword; } if (userdob == null) { user.userdob = user.userdob; } else { user.userdob = userdob; } if (useraddress == null) { user.useraddress = user.useraddress; } else { user.useraddress = useraddress; } if (usercountry == null) { user.usercountry = user.usercountry; } else { user.usercountry = usercountry; } user.companyname = user.companyname; user.companylogo = user.companylogo; user.companydescription = user.companydescription; user.nbshareordinary = user.nbshareordinary; user.sharevalueordinary = user.sharevalueordinary; user.descordinary = user.descordinary; user.additionalordinary = user.additionalordinary; user.nbsharepreferencial = user.nbsharepreferencial; user.sharevaluepreferencial = user.sharevaluepreferencial; user.descpreferencial = user.descpreferencial; user.additionalpreferencial = user.additionalpreferencial; user.nbsharenonvoting = user.nbsharenonvoting; user.sharevaluenonvoting = user.sharevaluenonvoting; user.descnonvoting = user.descnonvoting; user.additionalnonvoting = user.additionalnonvoting; user.nbshareredeemable = user.nbshareredeemable; user.sharevalueredeemable = user.sharevalueredeemable; user.descredeemable = user.descredeemable; user.additionalredeemable = user.additionalredeemable; user.userassets = user.userassets; } // end edit user // if the company profile is to be updated else if (editpart == "editcompany") { // upload new company logo if (fileCompanyLogoEdit == null || fileCompanyLogoEdit.Length == 0) { user.companylogo = user.companylogo; } else { var newcLogo = "images/" + fileCompanyLogoEdit.FileName; if (newcLogo == user.companylogo) { user.companylogo = user.companylogo; } else { //save the new company logo in the server var path1 = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images/", fileCompanyLogoEdit.FileName); using (var stream1 = new FileStream(path1, FileMode.Create)) { await fileCompanyLogoEdit.CopyToAsync(stream1); } user.companylogo = "images/" + fileCompanyLogoEdit.FileName; } } user.userphoto = user.userphoto; user.userfname = user.userfname; user.userlname = user.userlname; user.username = user.username; user.useremail = user.useremail; user.userpassword = user.userpassword; user.userdob = user.userdob; user.useraddress = user.useraddress; user.usercountry = user.usercountry; if (companyname == null) { user.companyname = user.companyname; } else { user.companyname = companyname; } if (companydescription == null) { user.companydescription = user.companydescription; } else { user.companydescription = companydescription; } if (nbshareordinary == 0) { user.nbshareordinary = user.nbshareordinary; } else { user.nbshareordinary = nbshareordinary; } if (sharevalueordinary == 0) { user.sharevalueordinary = user.sharevalueordinary; } else { user.sharevalueordinary = sharevalueordinary; } if (descordinary == null) { user.descordinary = user.descordinary; } else { user.descordinary = descordinary; } if (additionalordinary == null) { user.additionalordinary = user.additionalordinary; } else { user.additionalordinary = additionalordinary; } if (nbsharepreferencial == 0) { user.nbsharepreferencial = user.nbsharepreferencial; } else { user.nbsharepreferencial = nbsharepreferencial; } if (sharevaluepreferencial == 0) { user.sharevaluepreferencial = user.sharevaluepreferencial; } else { user.sharevaluepreferencial = sharevaluepreferencial; } if (descpreferencial == null) { user.descpreferencial = user.descpreferencial; } else { user.descpreferencial = descpreferencial; } if (additionalpreferencial == null) { user.additionalpreferencial = user.additionalpreferencial; } else { user.additionalpreferencial = additionalpreferencial; } if (nbsharenonvoting == 0) { user.nbsharenonvoting = user.nbsharenonvoting; } else { user.nbsharenonvoting = nbsharenonvoting; } if (sharevaluenonvoting == 0) { user.sharevaluenonvoting = user.sharevaluenonvoting; } else { user.sharevaluenonvoting = sharevaluenonvoting; } if (descnonvoting == null) { user.descnonvoting = user.descnonvoting; } else { user.descnonvoting = descnonvoting; } if (additionalnonvoting == null) { user.additionalnonvoting = user.additionalnonvoting; } else { user.additionalnonvoting = additionalnonvoting; } if (nbshareredeemable == 0) { user.nbshareredeemable = user.nbshareredeemable; } else { user.nbshareredeemable = nbshareredeemable; } if (sharevalueredeemable == 0) { user.sharevalueredeemable = user.sharevalueredeemable; } else { user.sharevalueredeemable = sharevalueredeemable; } if (descredeemable == null) { user.descredeemable = user.descredeemable; } else { user.descredeemable = descredeemable; } if (additionalredeemable == null) { user.additionalredeemable = user.additionalredeemable; } else { user.additionalredeemable = additionalredeemable; } if (userassets == 0) { user.userassets = user.userassets; } else { user.userassets = userassets; } } // end edit company user.isadmin = user.isadmin; user.validatedUser = user.validatedUser; } // update the user and save changes _context.Update(user); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!userExists(user.id)) { return(RedirectToAction("customErrorPage", "user")); } else { throw; } } return(RedirectToAction("Details", "user", new { id = user.id })); } return(RedirectToAction("Details", "user", new { id = user.id })); }
public async Task<IActionResult> editUser(int id, string userfname, string userlname, string username, string useremail, string userpassword, DateTimeOffset userdob, string useraddress, string usercountry, IFormFile fileUserphotoEdit) { var user = await _context.users.FirstOrDefaultAsync(m => m.id == id); if (user == null) { return NotFound(); }else{ // upload new user photo if (fileUserphotoEdit == null || fileUserphotoEdit.Length == 0){ user.userphoto = user.userphoto; } else { var newUserPhoto = "images/"+fileUserphotoEdit.FileName; if (newUserPhoto == user.userphoto) { user.userphoto = user.userphoto; } else { var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images/", fileUserphotoEdit.FileName); using (var stream = new FileStream(path, FileMode.Create)) { await fileUserphotoEdit.CopyToAsync(stream); } user.userphoto = "images/" + fileUserphotoEdit.FileName; } } if(userfname == null){user.userfname = user.userfname; }else{user.userfname = userfname;} if(userlname == null){user.userlname = user.userlname; }else{user.userlname = userlname;} if(username == null){user.username = user.username; }else{user.username = username;} if(useremail == null){user.useremail = user.useremail; }else{user.useremail = useremail;} if(userpassword == null){user.userpassword = user.userpassword; }else{user.userpassword = userpassword;} if(userdob == null){user.userdob = user.userdob; }else{user.userdob = userdob;} if(useraddress == null){user.useraddress = user.useraddress; }else{user.useraddress = useraddress;} if(usercountry == null){user.usercountry = user.usercountry; }else{user.usercountry = usercountry;} user.companyname = user.companyname; user.companydescription = user.companydescription; user.nbshareordinary = user.nbshareordinary; user.sharevalueordinary = user.sharevalueordinary; user.descordinary = user.descordinary; user.additionalordinary = user.additionalordinary; user.nbsharepreferencial = user.nbsharepreferencial; user.sharevaluepreferencial = user.sharevaluepreferencial; user.descpreferencial = user.descpreferencial; user.additionalpreferencial = user.additionalpreferencial; user.nbsharenonvoting = user.nbsharenonvoting; user.sharevaluenonvoting = user.sharevaluenonvoting; user.descnonvoting = user.descnonvoting; user.additionalnonvoting = user.additionalnonvoting; user.nbshareredeemable = user.nbshareredeemable; user.sharevalueredeemable = user.sharevalueredeemable; user.descredeemable = user.descredeemable; user.additionalredeemable = user.additionalredeemable; user.userassets = user.userassets; user.isadmin=user.isadmin; user.validatedUser=user.validatedUser;} _context.Update(user); await _context.SaveChangesAsync(); return Json(user); }
public async Task <IActionResult> Edit(int id, [Bind("id,projectname,projectdescription,projectamounttoraise,projectamountraised,projectcreationdate,projectclosingdate,projectimage1,projectimage2,projectimage3,projectimage4,fkuser,fkcategory,nbshareordinary,nbsharepreferencial,nbsharenonvoting,nbshareredeemable")] project project, IFormFile fileOne, IFormFile fileTwo, IFormFile fileThree, IFormFile fileFour, int fkuser, int fkcategory) { if (id != project.id) { return(RedirectToAction("customErrorPage", "user")); } try { // photo upload 1 if (fileOne == null || fileOne.Length == 0) { project.projectimage1 = project.projectimage1; } else { var path1 = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images/", fileOne.FileName); using (var stream1 = new FileStream(path1, FileMode.Create)) { await fileOne.CopyToAsync(stream1); } project.projectimage1 = "images/" + fileOne.FileName; } // photo upload 2 if (fileTwo == null || fileTwo.Length == 0) { project.projectimage2 = project.projectimage2; } else { var path2 = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images/", fileTwo.FileName); using (var stream2 = new FileStream(path2, FileMode.Create)) { await fileTwo.CopyToAsync(stream2); } project.projectimage2 = "images/" + fileTwo.FileName; } // photo upload 3 if (fileThree == null || fileThree.Length == 0) { project.projectimage3 = project.projectimage3; } else { var path3 = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images/", fileThree.FileName); using (var stream3 = new FileStream(path3, FileMode.Create)) { await fileThree.CopyToAsync(stream3); } project.projectimage3 = "images/" + fileThree.FileName; } // photo upload 4 if (fileFour == null || fileFour.Length == 0) { project.projectimage4 = project.projectimage4; } else { var path4 = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images/", fileFour.FileName); using (var stream4 = new FileStream(path4, FileMode.Create)) { await fileFour.CopyToAsync(stream4); } project.projectimage4 = "images/" + fileFour.FileName; } project.fkuser = (user)_context.users.First(user => user.id == fkuser); project.fkcategory = (category)_context.categories.First(category => category.id == fkcategory); project.projectamountraised = project.projectamountraised; project.validatedProject = false; _context.Update(project); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!projectExists(project.id)) { return(RedirectToAction("customErrorPage", "user")); } else { throw; } } return(RedirectToAction("Details", new { id = project.id })); }