コード例 #1
0
        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);
        }
コード例 #2
0
        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());
        }
コード例 #3
0
 public void WhenICompleteEnteringInformation()
 {
     _repository.Brands.Add(new Brand()
     {
         BrandName = "Test2"
     });
     _repository.SaveChanges();
 }
コード例 #4
0
 public Product CreateProduct(Product product)
 {
     if (product == null)
     {
         throw new ArgumentException("Product is null");
     }
     _context.Products.Add(product);
     _context.SaveChanges();
     return(product);
 }
コード例 #5
0
        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));
        }
コード例 #6
0
        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());
        }
コード例 #7
0
        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());
        }
コード例 #8
0
        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));
        }
コード例 #9
0
        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."));
        }
コード例 #10
0
        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."));
        }
コード例 #11
0
        public bool UpdateBrand(int Id, string brandName)
        {
            var Brand = base.GetById(Id);

            if (Brand != null)
            {
                Brand.BrandName = brandName;
                _dbContext.SaveChanges();
                return(true);
            }
            return(false);
        }
コード例 #12
0
        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());
        }
コード例 #13
0
        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());
        }
コード例 #14
0
 public virtual void Save()
 {
     _dataContext.SaveChanges();
 }
コード例 #15
0
 public bool SaveChanges() => _context.SaveChanges() > 0;
コード例 #16
0
 public int Complete()
 {
     return(_bikeStoresContext.SaveChanges());
 }