public TEntity Add(TEntity entity) { TEntity addedEntity = _bikeStoresEntities.Add(entity); try { _bikeStoresContext.SaveChanges(); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } return(addedEntity); }
public ActionResult DeleteStor(int id) { // Yarın bitirilecek/referans tip değer tip bakılacak var entity = _context.Stores.Include("Orders").Include("Stocks").Include("Staff").FirstOrDefault(x => x.StoreId == id); if (entity == null) { return(NoContent()); } foreach (var item in entity.Orders) { item.IsDeleted = true; } foreach (var item in entity.Stocks) { item.IsDeleted = true; } foreach (var item in entity.Staff) { item.IsDeleted = true; } entity.IsDeleted = true; _context.Update(entity); _context.SaveChanges(); return(Ok()); }
public void WhenICompleteEnteringInformation() { _repository.Brands.Add(new Brand() { BrandName = "Test2" }); _repository.SaveChanges(); }
public Product CreateProduct(Product product) { if (product == null) { throw new ArgumentException("Product is null"); } _context.Products.Add(product); _context.SaveChanges(); return(product); }
public ActionResult <CategoriesReadDto> CreateCategory(CategoriesCreateDto categoriesCreateDto) { var category = _mapper.Map <Categories>(categoriesCreateDto); _context.Categories.Add(category); _context.SaveChanges(); var categoriesReadDto = _mapper.Map <CategoriesReadDto>(category); // return 201 with location of created resource inside header return(CreatedAtRoute(nameof(GetCategoryById), new { id = categoriesReadDto.CategoryId }, categoriesReadDto)); }
public ActionResult DeleteSto(int id) { var entity = _context.Stocks.FirstOrDefault(x => x.Quantity == id); if (entity == null) { return(NoContent()); } entity.IsDeleted = true; _context.Update(entity); _context.SaveChanges(); return(Ok()); }
public ActionResult DeleteOrIt(int id) { var entity = _context.OrderItems.FirstOrDefault(x => x.ItemId == id); if (entity == null) { return(NoContent()); } entity.IsDeleted = true; _context.Update(entity); _context.SaveChanges(); return(Ok()); }
public ActionResult <Brand> PutBrand([FromBody] Brand model) { if (model == null || model.BrandName == null || model.BrandId == 0) { return(BadRequest()); } var entity = _context.Brands.FirstOrDefault(x => x.BrandId == model.BrandId); if (entity == null) { return(NotFound()); } entity.BrandName = model.BrandName; _context.Brands.Update(entity); _context.SaveChanges(); return(Ok(entity)); }
public ActionResult DeleteOr(int id) { var entity = _context.Orders.Include("OrderItems").FirstOrDefault(x => x.OrderId == id); if (entity == null) { return(NotFound()); } foreach (var item in entity.OrderItems) { item.IsDeleted = true; } entity.IsDeleted = true; _context.Update(entity); _context.SaveChanges(); return(Ok("Kayıt silinmiştir.")); }
public ActionResult DeleteControl(int id) { var entity = _context.Categories.Include("Products").Include("OrderItems").FirstOrDefault(x => x.CategoryId == id); if (entity == null) { return(NotFound()); } foreach (var item in entity.Products) { foreach (var order in item.OrderItems) { order.IsDeleted = true; } item.IsDeleted = true; } entity.IsDeleted = true; _context.Update(entity); _context.SaveChanges(); return(Ok("Id silinmiştir.")); }
public bool UpdateBrand(int Id, string brandName) { var Brand = base.GetById(Id); if (Brand != null) { Brand.BrandName = brandName; _dbContext.SaveChanges(); return(true); } return(false); }
public ActionResult DeletePr(int id) { var entity = _context.Products.Include("OrderItems").Include("Stocks").FirstOrDefault(x => x.ProductId == id); if (entity == null) { return(NoContent()); } foreach (var item in entity.OrderItems) { item.IsDeleted = true; } foreach (var item in entity.Stocks) { item.IsDeleted = true; } entity.IsDeleted = true; _context.Update(entity); _context.SaveChanges(); return(Ok()); }
public ActionResult DeleteSt(int id) { var entity = _context.Staffs.Include("InverseManager").Include("Orders").FirstOrDefault(x => x.StaffId == id); if (entity == null) { return(NoContent()); } foreach (var item in entity.InverseManager) { item.IsDeleted = true; } foreach (var item in entity.Orders) { item.IsDeleted = true; } entity.IsDeleted = true; _context.Update(entity); _context.SaveChanges(); return(Ok()); }
public virtual void Save() { _dataContext.SaveChanges(); }
public bool SaveChanges() => _context.SaveChanges() > 0;
public int Complete() { return(_bikeStoresContext.SaveChanges()); }