public async Task <IActionResult> Edit([FromForm] AspNetUserRolesEditViewModel vmItem) { if (!ModelState.IsValid) { return(View(vmItem)); } var tableName = nameof(AspNetUserRoles); var tableVersion = await _context.TableVersion.FirstOrDefaultAsync(h => h.Id == tableName); var dbItem = await _context.AspNetUserRoles .Where(h => h.UserId == vmItem.UserId) .FirstOrDefaultAsync(); if (dbItem == null) { return(NotFound()); } // Trim white space dbItem.RoleId = vmItem.RoleId; _context.Entry(dbItem); // Set time stamp for table to handle concurrency conflict await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Details), new { id = dbItem.UserId })); }
public async Task <IActionResult> Edit([FromForm] SettingTypeEditViewModel vmItem) { // Invalid model if (!ModelState.IsValid) { return(View(vmItem)); } // Get time stamp for table to handle concurrency conflict var tableName = nameof(SettingType); var tableVersion = await _context.TableVersion.FirstOrDefaultAsync(h => h.Id == tableName); var dbItem = await _context.SettingType .Where(h => h.Id == vmItem.Id) .FirstOrDefaultAsync(); if (dbItem == null) { return(NotFound()); } dbItem.Name = vmItem.Name; _context.Entry(dbItem).Property(nameof(SettingType.RowVersion)).OriginalValue = vmItem.RowVersion; // Set time stamp for table to handle concurrency conflict tableVersion.LastModify = DateTime.Now; await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Details), new { id = dbItem.Id })); }
public async Task <IActionResult> Edit([FromForm] ProjectEditViewModel vmItem) { ViewData["ControllerNameForImageBrowser"] = nameof(ImageBrowserProjectController).Replace("Controller", ""); // Invalid model if (!ModelState.IsValid) { // Get list master of foreign property and set to view data await PrepareListMasterForeignKey(vmItem); return(View(vmItem)); } // Get time stamp for table to handle concurrency conflict var tableName = nameof(Project); var tableVersion = await _context.TableVersion.FirstOrDefaultAsync(h => h.Id == tableName); var dbItem = await _context.Project .Where(h => h.Id == vmItem.Id) .FirstOrDefaultAsync(); if (dbItem == null) { return(NotFound()); } // Trim white space vmItem.Name = $"{vmItem.Name}".Trim(); // Update db item dbItem.UpdatedBy = _loginUserId; dbItem.UpdatedDate = DateTime.Now; dbItem.RowVersion = vmItem.RowVersion; dbItem.FkProjectTypeId = vmItem.FkProjectTypeId; dbItem.Name = vmItem.Name; dbItem.SlugName = vmItem.SlugName; dbItem.AutoSlug = vmItem.AutoSlug; dbItem.ImageSlug = vmItem.ImageSlug; dbItem.ShortDescriptionHtml = vmItem.ShortDescriptionHtml; dbItem.LongDescriptionHtml = vmItem.LongDescriptionHtml; dbItem.Tags = vmItem.Tags; dbItem.KeyWord = vmItem.KeyWord; dbItem.MetaData = vmItem.MetaData; dbItem.Note = vmItem.Note; _context.Entry(dbItem).Property(nameof(Project.RowVersion)).OriginalValue = vmItem.RowVersion; // Set time stamp for table to handle concurrency conflict tableVersion.LastModify = DateTime.Now; await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Details), new { id = dbItem.Id })); }
public async Task <IActionResult> Edit([FromForm] NewsTypeEditViewModel vmItem) { // Invalid model if (!ModelState.IsValid) { return(View(vmItem)); } // Get time stamp for table to handle concurrency conflict var tableName = nameof(NewsType); var tableVersion = await _webcontext.TableVersion.FirstOrDefaultAsync(h => h.Id == tableName); var dbItem = await _webcontext.NewsType .Where(h => h.Id == vmItem.Id) .FirstOrDefaultAsync(); if (dbItem == null) { return(NotFound()); } // Trim white space vmItem.Code = $"{vmItem.Code}".Trim(); vmItem.Name = $"{vmItem.Name}".Trim(); // Check code is existed if (await _webcontext.NewsType.AnyAsync(h => h.Id != vmItem.Id && h.Code == vmItem.Code)) { ModelState.AddModelError(nameof(NewsType.Code), "The code has been existed."); return(View(vmItem)); } // Update db item dbItem.UpdatedBy = _loginUserId; dbItem.UpdatedDate = DateTime.Now; dbItem.RowVersion = vmItem.RowVersion; dbItem.Code = vmItem.Code; dbItem.Name = vmItem.Name; dbItem.SlugName = vmItem.SlugName; dbItem.AutoSlug = vmItem.AutoSlug; dbItem.Tags = vmItem.Tags; dbItem.KeyWord = vmItem.KeyWord; dbItem.MetaData = vmItem.MetaData; dbItem.Note = vmItem.Note; _webcontext.Entry(dbItem).Property(nameof(NewsType.RowVersion)).OriginalValue = vmItem.RowVersion; // Set time stamp for table to handle concurrency conflict tableVersion.LastModify = DateTime.Now; await _webcontext.SaveChangesAsync(); return(RedirectToAction(nameof(Details), new { id = dbItem.Id })); }
public async Task <IActionResult> Edit([FromForm] ImageSlideEditViewModel vmItem) { // Invalid model if (!ModelState.IsValid) { return(View(vmItem)); } // Get time stamp for table to handle concurrency conflict var tableName = nameof(ImageSlide); var tableVersion = await _context.TableVersion.FirstOrDefaultAsync(h => h.Id == tableName); var dbItem = await _context.ImageSlide .Where(h => h.Id == vmItem.Id) .FirstOrDefaultAsync(); if (dbItem == null) { return(NotFound()); } // Trim white space vmItem.Name = $"{vmItem.Name}".Trim(); // Update db item dbItem.UpdatedBy = _loginUserId; dbItem.UpdatedDate = DateTime.Now; dbItem.RowVersion = vmItem.RowVersion; dbItem.Name = vmItem.Name; dbItem.SlugName = vmItem.SlugName; dbItem.AutoSlug = vmItem.AutoSlug; dbItem.Extension = vmItem.Extension; dbItem.Description = vmItem.Description; dbItem.SortIndex = vmItem.SortIndex; dbItem.IsYoutube = vmItem.IsYoutube; dbItem.YoutubeLink = vmItem.YoutubeLink; dbItem.Thumbnail = vmItem.Thumbnail; dbItem.Note = vmItem.Note; dbItem.Tags = vmItem.Tags; dbItem.KeyWord = vmItem.KeyWord; dbItem.MetaData = vmItem.MetaData; _context.Entry(dbItem).Property(nameof(ImageSlide.RowVersion)).OriginalValue = vmItem.RowVersion; // Set time stamp for table to handle concurrency conflict tableVersion.LastModify = DateTime.Now; await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Details), new { id = dbItem.Id })); }
public async Task <IActionResult> Edit([FromForm] AboutUsEditViewModel vmItem) { // Invalid model if (!ModelState.IsValid) { return(View(vmItem)); } // Get time stamp for table to handle concurrency conflict var tableName = nameof(AboutUs); var tableVersion = await _context.TableVersion.FirstOrDefaultAsync(h => h.Id == tableName); var dbItem = await _context.AboutUs .Where(h => h.Id == vmItem.Id) .FirstOrDefaultAsync(); if (dbItem == null) { return(NotFound()); } // Trim white space // Update db item dbItem.UpdatedBy = _loginUserId; dbItem.UpdatedDate = DateTime.Now; dbItem.RowVersion = vmItem.RowVersion; dbItem.Title = vmItem.Title; dbItem.SlugTitle = vmItem.SlugTitle; dbItem.AutoSlug = vmItem.AutoSlug; dbItem.ShortDescriptionHtml = vmItem.ShortDescriptionHtml; dbItem.LongDescriptionHtml = vmItem.LongDescriptionHtml; dbItem.ImageSlug = vmItem.ImageSlug; dbItem.Tags = vmItem.Tags; dbItem.KeyWord = vmItem.KeyWord; dbItem.MetaData = vmItem.MetaData; dbItem.Note = vmItem.Note; _context.Entry(dbItem).Property(nameof(AboutUs.RowVersion)).OriginalValue = vmItem.RowVersion; // Set time stamp for table to handle concurrency conflict tableVersion.LastModify = DateTime.Now; await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Details), new { id = dbItem.Id })); }
public async Task <IActionResult> Edit([FromForm] ContactEditViewModel vmItem) { // Invalid model if (!ModelState.IsValid) { return(View(vmItem)); } // Get time stamp for table to handle concurrency conflict var tableName = nameof(Contact); var tableVersion = await _context.TableVersion.FirstOrDefaultAsync(h => h.Id == tableName); var dbItem = await _context.Contact .Where(h => h.Id == vmItem.Id) .FirstOrDefaultAsync(); if (dbItem == null) { return(NotFound()); } // Trim white space vmItem.Name = $"{vmItem.Name}".Trim(); // Update db item dbItem.UpdatedBy = _loginUserId; dbItem.UpdatedDate = DateTime.Now; dbItem.RowVersion = vmItem.RowVersion; dbItem.Name = vmItem.Name; dbItem.Email = vmItem.Email; dbItem.Phone = vmItem.Phone; dbItem.Title = vmItem.Title; dbItem.Body = vmItem.Body; dbItem.IsRead = vmItem.IsRead; dbItem.FkProductCommentId = vmItem.FkProductCommentId; dbItem.Note = vmItem.Note; _context.Entry(dbItem).Property(nameof(Contact.RowVersion)).OriginalValue = vmItem.RowVersion; // Set time stamp for table to handle concurrency conflict tableVersion.LastModify = DateTime.Now; await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Details), new { id = dbItem.Id })); }
public async Task <IActionResult> Edit([FromForm] RoleEditViewModel vmItem) { // Invalid model if (!ModelState.IsValid) { return(View(vmItem)); } // Get time stamp for table to handle concurrency conflict var tableName = nameof(AspNetRoles); var tableVersion = await _context.TableVersion.FirstOrDefaultAsync(h => h.Id == tableName); var dbItem = await _context.AspNetRoles .Where(h => h.Id == vmItem.Id) .FirstOrDefaultAsync(); if (dbItem == null) { return(NotFound()); } dbItem.Name = vmItem.Name; dbItem.NormalizedName = vmItem.NormalizedName; dbItem.ConcurrencyStamp = vmItem.ConcurrencyStamp; _context.Entry(dbItem); // Set time stamp for table to handle concurrency conflict await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Details), new { id = dbItem.Id })); }
public async Task <IActionResult> Edit([FromForm] PeopleEditViewModel vmItem) { ViewData["ControllerNameForImageBrowser"] = nameof(ImageBrowserPeopleController).Replace("Controller", ""); // Invalid model if (!ModelState.IsValid) { return(View(vmItem)); } // Get time stamp for table to handle concurrency conflict var tableName = nameof(People); var tableVersion = await _context.TableVersion.FirstOrDefaultAsync(h => h.Id == tableName); var dbItem = await _context.People .Where(h => h.Id == vmItem.Id) .FirstOrDefaultAsync(); if (dbItem == null) { return(NotFound()); } // Trim white space dbItem.Name = vmItem.Name; dbItem.BirthDay = vmItem.BirthDay; dbItem.Job = vmItem.Job; dbItem.JobIntroduction = vmItem.JobIntroduction; dbItem.Phone = vmItem.Phone; dbItem.Gmail = vmItem.Gmail; dbItem.Img = vmItem.Img; // Update db item dbItem.RowVersion = vmItem.RowVersion; _context.Entry(dbItem).Property(nameof(People.RowVersion)).OriginalValue = vmItem.RowVersion; // Set time stamp for table to handle concurrency conflict tableVersion.LastModify = DateTime.Now; await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Details), new { id = dbItem.Id })); }
public async Task <IActionResult> Edit([FromForm] SettingEditViewModel vmItem) { ViewData["ControllerNameForImageBrowser"] = nameof(ImageBrowserSettingController).Replace("Controller", ""); // Invalid model if (!ModelState.IsValid) { // Get list master of foreign property and set to view data //await PrepareListMasterForeignKey(vmItem); return(View(vmItem)); } // Get time stamp for table to handle concurrency conflict var tableName = nameof(Setting); var tableVersion = await _context.TableVersion.FirstOrDefaultAsync(h => h.Id == tableName); var dbItem = await _context.Setting .Where(h => h.Id == vmItem.Id) .FirstOrDefaultAsync(); if (dbItem == null) { return(NotFound()); } // Trim white space // Update db item dbItem.Style = vmItem.Style; dbItem.Value = vmItem.Value; dbItem.Description = vmItem.Description; dbItem.IsManual = vmItem.IsManual; dbItem.ImageSlug = vmItem.ImageSlug; _context.Entry(dbItem).Property(nameof(Setting.RowVersion)).OriginalValue = vmItem.RowVersion; // Set time stamp for table to handle concurrency conflict tableVersion.LastModify = DateTime.Now; await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Details), new { id = dbItem.Id })); }