public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Age,Describe,IsDelete")] Mac mac) { if (id != mac.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(mac); await _context.SaveChangesAsync(); Message = "Successfully update mac"; } catch (DbUpdateConcurrencyException) { if (!MacExists(mac.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(mac)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Title,IsDelete")] Category category) { if (id != category.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(category); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(category.Id)) { return(NotFound()); } else { throw; } } Message = "Successfully update rooms"; return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Spelen(int?id) { // meegegeven id en er is iemand ingelogd if (id == null || nuSpelend == null) { return(NotFound()); } var spel = await _context.Spel.FirstOrDefaultAsync(m => m.ID == id); if (spel == null) { return(NotFound()); } var aantal_mensen_in_game = identityContext.Spelers.Where(m => m.Token == spel.Token).Select(m => m.Token).Count(); if (aantal_mensen_in_game >= 2 && nuSpelend.Token != spel.Token) { return(NotFound()); } var speler_temp = nuSpelend; if (aantal_mensen_in_game == 1 && nuSpelend.Token == spel.Token) { // maker van spel 'rejoint' ViewData["enigeSpeler"] = true; speler_temp.HuidigeKleur = Kleur.Wit; } else { // tweede speler joint ViewData["enigeSpeler"] = false; Speler temp = await identityContext.Spelers.FirstOrDefaultAsync(m => m.Token == spel.Token && m.Email != speler_temp.Email); if (temp.HuidigeKleur == Kleur.Wit) { speler_temp.HuidigeKleur = Kleur.Zwart; } else { speler_temp.HuidigeKleur = Kleur.Wit; } //speler_temp.HuidigeKleur = Kleur.Zwart; } // token van spel wordt gegeven aan de speler // speler die meedoet aan een spel krijgt kleur zwart speler_temp.Token = spel.Token; identityContext.Update(speler_temp); await identityContext.SaveChangesAsync(); spel.Bord = JsonConvert.DeserializeObject <Kleur[, ]>(spel.JsonBord); return(View(spel)); }
public async Task <IActionResult> Edit(EditUserViewModel model) { if (ModelState.IsValid) { //User u = new User { Email = model.Email, UserName = model.Email, Nick = model.Nick }; User user = await _userManager.FindByIdAsync(model.Id); User resUser = user; if (user != null) { user.Email = model.Email; user.UserName = model.Email; user.Nick = model.Nick; //await _context.SaveChangesAsync(); var result = await _userManager.UpdateAsync(user); if (result.Succeeded) { user = resUser; var comments = _context.Comments.Where(c => c.UserId == user.Id).ToList(); var rewiews = _context.Reviews.Where(r => r.UserId == user.Id).ToList(); foreach (var com in comments) { com.UserName = model.Nick; _context.Update(com); } foreach (var rew in rewiews) { rew.UserName = model.Nick; _context.Update(rew); } return(RedirectToAction("Index")); } else { foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } } } return(View(model)); }
public JsonResult DeleteSevice(int?id) { Sevice sevice = new Sevice(); sevice = _context.Sevices.FirstOrDefault(x => x.Id == id && x.IsDelete == false); if (sevice == null) { return(Json("Fail")); } sevice.IsDelete = true; _context.Update(sevice); _context.SaveChangesAsync(); Message = "Successfully deleted sevice"; return(Json("Success")); }
public async Task <IActionResult> Edit(int id, [Bind("Id,ClientId,Description,Expiration,Type,Value")] ClientSecret clientSecret) { if (id != clientSecret.Id) { return(NotFound()); } if (ModelState.IsValid) { try { clientSecret.Value = clientSecret.Value.Sha256(); _context.Update(clientSecret); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ClientSecretExists(clientSecret.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } ViewData["ClientId"] = new SelectList(_context.Clients, "Id", "ClientId", clientSecret.ClientId); return(View(clientSecret)); }
public async Task <IActionResult> Edit(int id, [Bind("idPatients,namePatients,phonePatients,gender,health_condition,doctor_id,nurse_id,created")] Patients patients) { if (id != patients.idPatients) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(patients); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PatientsExists(patients.idPatients)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(patients)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,AbsoluteRefreshTokenLifetime,AccessTokenLifetime,AccessTokenType,AllowAccessTokensViaBrowser,AllowOfflineAccess,AllowPlainTextPkce,AllowRememberConsent,AlwaysIncludeUserClaimsInIdToken,AlwaysSendClientClaims,AuthorizationCodeLifetime,ClientId,ClientName,ClientUri,EnableLocalLogin,Enabled,IdentityTokenLifetime,IncludeJwtId,LogoUri,LogoutSessionRequired,LogoutUri,PrefixClientClaims,ProtocolType,RefreshTokenExpiration,RefreshTokenUsage,RequireClientSecret,RequireConsent,RequirePkce,SlidingRefreshTokenLifetime,UpdateAccessTokenClaimsOnRefresh")] Client client) { if (id != client.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(client); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ClientExists(client.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } return(View(client)); }
public async Task <IActionResult> Edit(int id, [Bind("IdMedConv,NomMedConv,PrenomMedConv,Email,Jours_Usine,PlageHoraire,Honoraire_seance,MobielMedConv,idSpecialite")] MedecinConventionne medecinConventionne) { if (id != medecinConventionne.IdMedConv) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(medecinConventionne); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MedecinConventionneExists(medecinConventionne.IdMedConv)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["idSpecialite"] = new SelectList(_context.Specialites, "idSpecialite", "nameSpecialite", medecinConventionne.idSpecialite); return(View(medecinConventionne)); }
public ApiResponse <User> Update(User userData) { //Prevent changing the ID userData.Id = Guid.Empty; var userToChange = GetUserFromIdAsync(userData.Id).Result; // Can only update an existing user if (userToChange == null) { return(new ApiResponse <User>(ApiResponseCode.UnAuthenticated, null)); } // Update the user if (!string.IsNullOrWhiteSpace(userData.PasswordHash) && userData.PasswordHash != userToChange.PasswordHash) { //If the password is unchanged or empty, this does not update the password userData.PasswordHash = userToChange.PasswordHash; } // Automapper is configured to only overwrite the fields that are not null _mapper.Map(userData, userToChange); _identityContext.Update(userToChange); _identityContext.SaveChanges(); return(new ApiResponse <User>(ApiResponseCode.OK, userToChange)); }
public async Task <IActionResult> Edit(string id, [Bind("ID,FirstName,LastName,Email,Password,CreditCard,CarNumber,CarType,Address,PhoneNumber,Balance")] GeneralUser generalUser) { if (id != generalUser.UID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(generalUser); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GeneralUserExists(generalUser.UID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(generalUser)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Description,DisplayName,Enabled,Name")] ApiResource apiResource) { if (id != apiResource.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(apiResource); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ApiResourceExists(apiResource.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } return(View(apiResource)); }
public async Task <IActionResult> Edit(string id, [Bind("Id,AccessFailedCount,ConcurrencyStamp,Email,EmailConfirmed,LockoutEnabled,LockoutEnd,NormalizedEmail,NormalizedUserName,PasswordHash,PhoneNumber,PhoneNumberConfirmed,SecurityStamp,TwoFactorEnabled,UserName,Deleted,DeletedByUserId,DeletedDate,FirstName,LastName")] AspNetUser aspNetUser) { if (id != aspNetUser.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(aspNetUser); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AspNetUserExists(aspNetUser.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } ViewData["DeletedByUserId"] = new SelectList(_context.AspNetUsers, "Id", "Id", aspNetUser.DeletedByUserId); return(View(aspNetUser)); }
public async Task <IActionResult> Edit(int id, [Bind("idSpecialite,nameSpecialite")] Specialites specialites) { if (id != specialites.idSpecialite) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(specialites); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SpecialitesExists(specialites.idSpecialite)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(specialites)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] Ingredient ingredient) { if (id != ingredient.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(ingredient); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!IngredientExists(ingredient.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(ingredient)); }
public JsonResult DeleteRoom(int?id) { Room room = new Room(); Role role = new Role(); room = _context.Rooms.FirstOrDefault(x => x.Id == id && x.IsDelete == false); if (room == null) { return(Json("Fail")); } room.IsDelete = true; role = _context.Roles.FirstOrDefault(x => x.Id == room.RoleId); role.IsDelete = true; _context.Update(role); _context.Update(room); _context.SaveChangesAsync(); return(Json("Success")); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Info, Date, ProductId, UserId, UserName")] Comment comment, int num, string searchString) { if (id != comment.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(comment); User user = await _userMenager.FindByIdAsync(comment.UserId); user.Comment.Where(c => c.Id == comment.Id).FirstOrDefault().Info = comment.Info; user.Comment.Where(c => c.Id == comment.Id).FirstOrDefault().Date = comment.Date; _context.Update(user); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CommentExists(comment.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index", "Comments", new { Id = comment.ProductId, name = _context.Products.Where(c => c.Id == comment.ProductId).FirstOrDefault().Name, num = num, searchString = searchString })); } else { return(RedirectToAction("Edit", "Comments", new { id = comment.Id, productId = comment.ProductId, userId = comment.UserId, num = num, searchString = searchString })); } //ViewData["ProductId"] = new SelectList(_context.Products, "Id", "Name", comment.ProductId); //ViewData["UserId"] = new SelectList(_context.Users, "Id", comment.UserId); ////return View(comment); //return RedirectToAction("Index", "Comments", new { Id = comment.ProductId, name = _context.Products.Where(c => c.Id == comment.ProductId).FirstOrDefault().Name }); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,CategoryId")] Subcategory subcategory) { if (id != subcategory.Id) { return(NotFound()); } if (ModelState.IsValid) { try { var subcategories = _context.Subcategories.Where(s => s.Name == subcategory.Name).FirstOrDefault(); if (subcategories != null) { ModelState.AddModelError(string.Empty, "This subcategory already exists"); return(RedirectToAction("Edit", "Subcategories", new { id = subcategory.Id })); } else { _context.Update(subcategory); await _context.SaveChangesAsync(); } } catch (DbUpdateConcurrencyException) { if (!SubcategoryExists(subcategory.Id)) { return(NotFound()); } else { throw; } } //return RedirectToAction(nameof(Index)); return(RedirectToAction("Index", "Subcategories", new { Id = subcategory.CategoryId, name = _context.Categories.Where(c => c.Id == subcategory.CategoryId).FirstOrDefault().Name })); } //ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Name", subcategory.CategoryId); //return View(subcategory); return(RedirectToAction("Index", "Subcategories", new { Id = subcategory.CategoryId, name = _context.Categories.Where(c => c.Id == subcategory.CategoryId).FirstOrDefault().Name })); }
public async Task <bool> EndActivity(string userIdNr) { var currentActivity = _context.BuildingActivities.Where(activity => !activity.exited && activity.IdentificationNumber == userIdNr).FirstOrDefault(); currentActivity.exited = true; currentActivity.ExitDate = DateTime.Now; var updatedActivity = _context.Update(currentActivity); var res = await _context.SaveChangesAsync(); return(res > 0); }
public User Edit(User t) { var user = GetById(t.Id); if (user != null) { _context.Update(user); _context.SaveChanges(); return(user); } return(null); }
public Role Edit(Role t) { var role = GetById(t.Id); if (role != null) { _context.Update(role); _context.SaveChanges(); return(role); } return(null); }
public async Task <IActionResult> Create([Bind("Info,Date,Rating,ProductId,UserId,UserName")] Review review, int num, string searchString) { try { if (ModelState.IsValid) { _context.Add(review); User user = await _userManager.FindByIdAsync(review.UserId); user.Review.Add(review); _context.Update(user); await _context.SaveChangesAsync(); var product = _context.Products.Find(review.ProductId); var reviews = _context.Reviews.Where(c => c.ProductId == product.Id); //int count = product.Review.Count(); double?rating = reviews.Average(c => c.Rating); product.Rating = rating; _context.Update(product); await _context.SaveChangesAsync(); return(RedirectToAction("Index", "Reviews", new { Id = review.ProductId, name = _context.Products.Where(c => c.Id == review.ProductId).FirstOrDefault().Name, num = num, searchString = searchString })); } else { return(RedirectToAction("Create", "Reviews", new { productId = review.ProductId, userId = review.UserId, num = num, searchString = searchString })); } } catch (DbUpdateException /* ex */) { //Log the error (uncomment ex variable name and write a log. ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); } //PopulateDepartmentsDropDownList(subcategory.CategoryId); //return View(subcategory); return(RedirectToAction("Index", "Reviews", new { Id = review.ProductId, name = _context.Products.Where(c => c.Id == review.ProductId).FirstOrDefault().Name })); }
public IActionResult Put(int id, [FromBody] IdorViewModel value) { if (ModelState.IsValid) { var result = _myContext.Idor.SingleOrDefault(x => x.IdorId == id); if (result != null) { result.IdorValue = value.IdorValue; _myContext.Update(result); _myContext.SaveChanges(); } return(Ok("New value was updated succesfull!")); } else { return(BadRequest("Update of the item has failed!")); } }
public IActionResult Put(int id, [FromBody] CsrfViewModel value) { if (ModelState.IsValid) { var result = _myContext.Csrf.SingleOrDefault(x => x.PrivateDataId == id); if (result != null) { result.PrivateData = value.PrivateData; result.PrivateDateTime = DateTime.Now; _myContext.Update(result); _myContext.SaveChanges(); } return(Ok("New value was updated succesfull!")); } else { return(BadRequest("Update of the item has failed!")); } }
internal int Update(string email, ApplicationUser am) { ApplicationUser oldAccount = GetAccount(email); if (oldAccount == null) { return(0); } if (am.Email != null) { oldAccount.Email = am.Email; } if (am.Name != null) { oldAccount.Name = am.Name; } // Fix age if (am.Age != -1) { oldAccount.Age = am.Age; } if (am.Sex != null) { oldAccount.Sex = am.Sex; } if (am.Major != null) { oldAccount.Major = am.Major; } // Fix grade if (am.Grade != -1) { oldAccount.Grade = am.Grade; } // Fix isseller oldAccount.IsSeller = am.IsSeller; _context.Update(oldAccount); _context.SaveChanges(); return(1); }
/// <inheritdoc/> public async Task <bool> UpdateAccountAsync(AccountViewModel accountViewModel) { var account = await _identityContext.Accounts.FirstOrDefaultAsync(p => p.Id == accountViewModel.Id); if (account == null) { return(false); } account.Login = accountViewModel.Login; account.Role = accountViewModel.Role.Value; account.IsActive = accountViewModel.IsActive.Value; account.Email = accountViewModel.Email; account.Password = accountViewModel.Password; _identityContext.Update(account); await _identityContext.SaveChangesAsync(); return(true); }
public IActionResult CreateOrEdit([Bind("Name,Id,Number")] Test test) { if (ModelState.IsValid) { try { if (test.Id == 0) { _context.Add(test); } else { _context.Update(test); } _context.SaveChanges(); } catch (Exception) { } } return(View("Index")); }
public async Task <IActionResult> Create([Bind("ReserveSpotID,UserID,SpotID,CreatedOn,ReservationDate,ReservationHour,Duration,carNumber")] ReserveSpot reserveSpot, [FromRoute] int parkingSpotID) { if (ModelState.IsValid) { //checks if the reservation date didn't pass or if the the reservation date is today if ((reserveSpot.ReservationDate.Date >= DateTime.Today)) { //checks if the reservation hour is valid for today's date if ((reserveSpot.ReservationHour <= System.DateTime.Now.Hour) && ((reserveSpot.ReservationDate.Date == DateTime.Today))) { return(RedirectToAction(nameof(InvalidHour))); } //getting the id of current user var currentUser = (from userID in _identitycontext.GeneralUser where userID.Id == User.FindFirstValue(ClaimTypes.NameIdentifier) select userID.UID).FirstOrDefault(); reserveSpot.ReserveSpotID = Guid.NewGuid(); reserveSpot.CreatedOn = System.DateTime.Now; reserveSpot.Spot = _context.ParkingSpot.FirstOrDefault(u => u.ParkingSpotID == parkingSpotID); reserveSpot.UserID = currentUser; //get all the reservations for the wanted day for a specific spot spot var myreservations = (from reservations in _context.ReserveSpot where reservations.Spot.ParkingSpotID == parkingSpotID && reservations.ReservationDate == reserveSpot.ReservationDate //replace select reservations); //validation that the reservation made for the desired date if (reserveSpot.ReservationHour + reserveSpot.Duration > 24) { return(RedirectToAction(nameof(SorryChooseDurationForTheDayYouSelected))); } foreach (var r in myreservations) { //case1: check if the desired res hour is between an already reserved time range if ((reserveSpot.ReservationHour < r.ReservationHour + r.Duration && reserveSpot.ReservationHour >= r.ReservationHour)) { return(RedirectToAction(nameof(SorrySpotIsTaken))); } //case2: the desired res hour is an availble hour but the duration slip into other reservation and its end time is before the already existing reservation fullfiled if ((reserveSpot.ReservationHour + reserveSpot.Duration <= r.ReservationHour + r.Duration) && (reserveSpot.ReservationHour + reserveSpot.Duration > r.ReservationHour)) { return(RedirectToAction(nameof(SorrySpotIsTaken))); } //case3: the desired res hour is an availble hour but the duration slip into other reservation if ((reserveSpot.ReservationHour <= r.ReservationHour) && (reserveSpot.ReservationHour + reserveSpot.Duration >= r.ReservationHour + r.Duration)) { return(RedirectToAction(nameof(SorrySpotIsTaken))); } } reserveSpot.Spot.NunOfOrders++; _context.Add(reserveSpot); await _context.SaveChangesAsync(); // finding current user by name var uName = User.Identity.Name; var thisUser = await _identitycontext.GeneralUser.FirstOrDefaultAsync(u => u.UserName.Equals(uName)); // validation thisUser really exists if (thisUser == null) { return(NotFound()); } // this section is to save the history of spots reserved to serve the ML algo string uHistory = thisUser.History; if (!string.IsNullOrEmpty(uHistory)) { uHistory += ","; } uHistory += reserveSpot.SpotID.ToString(); thisUser.History = uHistory; try { _identitycontext.Update(thisUser); await _identitycontext.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw new Exception("error"); } return(RedirectToAction(nameof(Index))); } else { return(RedirectToAction(nameof(InvalidDate))); } } return(View(reserveSpot)); }