public async Task <ActionResult <Brand> > PutBrand(int id, BrandInputDto input) { var brand = await _context.Brands.FindAsync(id); brand.Name = input.Name; brand.ArabicName = input.ArabicName; brand.UpdatedUserId = input.UserId; brand.UpdatedDate = DateTime.Now; _context.Entry(brand).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BrandExists(id)) { return(NotFound()); } else { throw; } } return(brand); }
public async Task <ActionResult <Brand> > PostBrand(BrandInputDto input) { try { var brand = new Brand() { Name = input.Name, ArabicName = input.ArabicName, CreatedDate = DateTime.Now, CreatedUserId = input.UserId }; _context.Brands.Add(brand); await _context.SaveChangesAsync(); return(brand); } catch (Exception ex) { return(null); } }