public async Task <Category> RemoveCategory(Category category) { _context.Categories.Remove(category); await _context.SaveChangesAsync(); return(category); }
public async Task Create(Account account) { Validate(account); _context.Accounts.Add(account); await _context.SaveChangesAsync(); }
public async Task <Category> Post([FromBody] Category category) { _context.Categories.Add(category); await _context.SaveChangesAsync(); return(category); }
public async Task <ProductModel> CreateProduct(ProductModel model) { var product = new Product(); model.MapTo(product); await _db.Products.AddAsync(product); await _db.SaveChangesAsync(); return(product.MapToDto()); }
public async Task AddAsync(Brand brand) { try { _context.Brands.Add(brand); await _context.SaveChangesAsync(); } catch (Exception ex) { throw; } }
public async Task UpdateCategoryAsync(Category category) { try { _context.Entry <Category>(category).State = EntityState.Modified; await _context.SaveChangesAsync(); } catch (Exception ex) { throw new Exception("An error has occurred"); } }
public async Task DeleteProductAync(Guid id) { try { Product obj = await _context.Products.FindAsync(id); _context.Entry <Product>(obj).State = EntityState.Deleted; await _context.SaveChangesAsync(); } catch (ArgumentNullException ex) { throw new ArgumentNullException(ex.Message); } }
public async Task <IActionResult> Create(Product product) { db.Products.Add(product); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <bool> Put(Category category) { bool resultUpdate = false; try { context.Entry <Category>(category).State = EntityState.Modified; int resultLine = await context.SaveChangesAsync(); resultUpdate = resultLine > 0 ? true : false; } catch (Exception ex) { Console.WriteLine("Put -> " + ex.Message); } return(resultUpdate); }
public override async Task UpdateAsync(Course entity) { using (StoreDataContext dbContext = new StoreDataContext()) { var course = dbContext.Courses.FirstOrDefault(s => s.CourseId == entity.CourseId); course.Name = entity.Name; course.Precentage = entity.Precentage; course.StartedDateTime = entity.StartedDateTime; course.EndDateTime = entity.EndDateTime; course.Description = entity.Description; course.Author = entity.Author; course.ModifyDateTime = DateTime.Now; course.CourseStatus = entity.CourseStatus; course.Tags.Clear(); foreach (var tags in entity.Tags) { var dbTag = dbContext.Tags.FirstOrDefault(s => s.TagId == tags.TagId); course.Tags.Add(dbTag); } await dbContext.SaveChangesAsync(); } }
public async Task <bool> Save(Product product) { bool resultSave = false; try { context.Products.Add(product); int result = await context.SaveChangesAsync(); resultSave = result > 0 ? true : false; } catch (Exception ex) { Console.WriteLine("Save -> " + ex.Message); } return(resultSave); }
public async Task Register(AbstractOperation operation) { operation.SetDescription(); operation.CalculateRate(); _context.AbstractOperation.Add(operation); await _context.SaveChangesAsync(); }
public async Task <ActionResult> DeleteCategory( [FromServices] StoreDataContext _context, [FromBody] Category category) { _context.Categories.Remove(category); await _context.SaveChangesAsync(); return(NoContent()); }
public override async Task DeleteAsync(int id) { using (StoreDataContext dbContext = new StoreDataContext()) { var course = dbContext.Courses.FirstOrDefault(s => s.CourseId == id); course.Tags.Clear(); dbContext.Courses.Remove(course); await dbContext.SaveChangesAsync(); } }
public virtual async Task CreateAsync(T entity) { using (StoreDataContext dataContext = new StoreDataContext()) { entity.CreatedDateTime = DateTime.Now; entity.ModifyDateTime = DateTime.Now; dataContext.Set <T>().Add(entity); await dataContext.SaveChangesAsync(); } }
public async Task <ActionResult> Post( [FromServices] StoreDataContext context, [FromBody] Product product ) { await context.Products.AddAsync(product); await context.SaveChangesAsync(); return(Created("", product)); }
public async Task <ActionResult> Post( [FromServices] StoreDataContext context, [FromBody] Usuario Usuario ) { await context.Usuarios.AddAsync(Usuario); await context.SaveChangesAsync(); return(Created("", Usuario)); }
public async Task Add(User user) { try { _context.Users.Add(user); await _context.SaveChangesAsync(); } catch (Exception ex) { throw; } }
// Asenkron olarak çalışabilen ve sayfadaki Submit işlemi sonrası tetiklenen Post metodumuz // Tipik olarak Razor sayfasındaki model verisini alıp DbSet'e ekliyor ve kayıt ediyoruz. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var addedBook = _context.Books.Add(BookData).Entity; Console.WriteLine($"{addedBook.Title} eklendi"); await _context.SaveChangesAsync(); return(RedirectToPage("/Index")); // Kitap eklendikten sonra ana sayfaya yönlendirme yapıyoruz }
public async Task <ActionResult> PutCategory( [FromServices] StoreDataContext _context, [FromBody] Category category) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Entry <Category>(category).State = EntityState.Modified; await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(PutCategory), category)); }
// Silme operasyonunu icra eden metodumuz public async Task <IActionResult> OnPostDeleteAsync(int id) { // Silme operasyonu için Identity alanından önce // kitabı bul var book = await _context.Books.FindAsync(id); if (book != null) //Kitabı bulduysan { _context.Books.Remove(book); //Kitabı çıkart ve Context'i son haliyle kaydet await _context.SaveChangesAsync(); } return(RedirectToPage()); // Scotty bizi o anki sayfaya döndür }
public async Task <ResultViewModel> Post([FromBody] EditorProductViewModel model) { model.Validate(); if (model.IsValid) { return new ResultViewModel { Success = false, Message = "Não foi possível cadastrar o produto", Data = model.Notifications } } var product = new Product() { Title = model.Title, CategoryId = model.CategoryId, CreateDate = DateTime.Now, Description = model.Description, Image = model.Image, LastUpdateDate = DateTime.Now, Price = model.Price, Quantity = model.Quantity }; _context.Products.Add(product); await _context.SaveChangesAsync(); return(await Task.FromResult(new ResultViewModel() { Success = true, Message = "Produto cadastrado com sucesso", Data = product })); }
public async Task <ActionResult> PostCategory( [FromServices] StoreDataContext _context, [FromBody] Category category) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await _context.Categories.AddAsync(category); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(PostCategory), category)); }
public async Task <ActionResult> Delete( [FromServices] StoreDataContext context, int id ) { var item = await context.Products.FirstOrDefaultAsync(x => x.Id == id); if (item == null) { return(NotFound()); } context.Products.Remove(item); await context.SaveChangesAsync(); return(Ok(item)); }
public override async Task CreateAsync(Course entity) { using (StoreDataContext dbContext = new StoreDataContext()) { foreach (var tags in entity.Tags) { dbContext.Entry(tags).State = EntityState.Unchanged; dbContext.Tags.Attach(tags); } entity.CreatedDateTime = DateTime.Now; entity.ModifyDateTime = DateTime.Now; dbContext.Courses.Add(entity); await dbContext.SaveChangesAsync(); } }
public async Task <ActionResult> Put( [FromServices] StoreDataContext context, [FromBody] Product product, int id ) { var item = await context.Products.FirstOrDefaultAsync(x => x.Id == id); if (item == null) { return(NotFound()); } context.Entry <Product>(product).State = EntityState.Modified; await context.SaveChangesAsync(); return(Ok(item)); }
public async Task <OrderRowModel> AddRowToOrder(long id, OrderRowModel model) { if (await OrderExists(id) == false) { throw new EntityNotFoundException <OrderModel>(id); } var row = new OrderRow(); model.MapTo(row); row.OrderId = id; await _db.OrderRows.AddAsync(row); await _db.SaveChangesAsync(); return(row.MapToDto()); }
public async Task <IActionResult> OnPostAsync() { // Eksik veya hatalı bilgiler nedeniyle Model örneği doğrulanamadıysa // sayfada kalalım if (!ModelState.IsValid) { return(Page()); } // Güncellenen kitap bilgilerini Context'e ilave edip durumunu Modified'e çektik _context.Attach(BookData).State = EntityState.Modified; try { // Değişiklikleri kaydetmeyi deniyoruz await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw new Exception($"{BookData.Id} numaralı kitabı bulamadık!"); } // İşlemler başarılı ise tekrardan index'e(Anasayfa oluyor tabii) dönüyoruz return(RedirectToPage("/index")); }
public async Task Save(Product product) { await _context.Products.AddAsync(product); await _context.SaveChangesAsync(); }
public virtual async Task Save(TType entity) { await _context.Set <TType>().AddAsync(entity); await _context.SaveChangesAsync(); }