public async Task <IActionResult> PutColor(int id, Color color) { if (id != color.ID) { return(BadRequest()); } _context.Entry(color).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ColorExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Create([Bind("ID,Product,Price")] Items items) { if (ModelState.IsValid) { _context.Add(items); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(items)); }
public async Task <IActionResult> PostItem([FromBody] Item item) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Items.Add(item); await _context.SaveChangesAsync(); return(CreatedAtAction("GetItem", new { id = item.Id }, item)); }
public async Task <bool> Create(Item record) { _context.Items.Add(record); try { await _context.SaveChangesAsync(); return(true); } catch (Exception ex) { Debug.WriteLine(ex.Message, $"{typeof(ItemService)}:Update"); return(false); } }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(Item).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ItemExists(Item.Id)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> Create([Bind("Id,Name,Price,CategoryId,GenderId,Features,Image")] Item item) { var catId = Request.Form["CategoryId"]; var CatObj = _categoryContext.AllCategories.FirstOrDefault(x => x.Id == catId); var genId = Request.Form["GenderId"]; var genObj = _gendersContext.AllGenders.FirstOrDefault(x => x.Id == genId); var fDesc = Request.Form["Features.Description"]; var fCountry = Request.Form["Features.Country"]; var fMater = Request.Form["Features.Material"]; var fSize = Request.Form["Features.Size"]; var fColor = Request.Form["Features.Color"]; if (ModelState.IsValid) { item.Features.Id = item.Id + "fe"; item.CategoryId = catId; item.GenderId = genId; /* * item.Features.Country = fCountry; * item.Features.Description = fDesc; * item.Features.Material = fMater; * item.Features.Id = item.Id+"fe"; * item.Features.Color = fColor;*/ /* * item.Category.Id = CatObj.Id.ToString(); * item.Gender.Id = genObj.Id.ToString(); * * item.Category.Name = CatObj.Name.ToString(); * item.Gender.Name = genObj.Name.ToString();*/ _context.Add(item); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(item)); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Items.Add(Item); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> Create([Bind("IdModel,BitchNameModel,NumberModel,TiTDescriptionModel,ProfilePictureModel")] ListViewModel item) { if (ModelState.IsValid) { string uniqueFileName = UploadedFile(item); Item listItem = new Item { BitchName = item.BitchNameModel, ProfilePicture = uniqueFileName, Number = item.NumberModel, TiTDescription = item.TiTDescriptionModel }; _context.Add(listItem); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(item)); }
public async Task <bool> Register(User user) { _context.Users.Add(user); try { await _context.SaveChangesAsync(); return(true); } catch (Exception ex) { Debug.WriteLine(ex.Message, $"{typeof(AuthService)}:Update"); return(false); } }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Item = await _context.Items.FindAsync(id); if (Item != null) { _context.Items.Remove(Item); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
//Look into asyncronous programming to make my code more efficient. public void SaveChangesAsync() { if (_context != null) { _context.SaveChangesAsync(); } if (_spellsContext != null) { _spellsContext.SaveChangesAsync(); } if (_itemsContext != null) { _itemsContext.SaveChangesAsync(); } if (_playableClassContext != null) { _playableClassContext.SaveChangesAsync(); } if (_raceContext != null) { _raceContext.SaveChangesAsync(); } }
public Task Save() { return(_appDbContext.SaveChangesAsync()); }