Example #1
0
 public void Update(T entity)
 {
     // attach function - pay attention to certain entity
     _db.Attach(entity);
     // lets db know it has been updated, and updates the object
     _dbContext.Entry(entity).State = EntityState.Modified;
 }
Example #2
0
 public ActionResult Create(ConfigEmail model)
 {
     if (ModelState.IsValid)
     {
         db.Entry(model).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
 public ActionResult Edit([Bind(Include = "Id,CategoryName")] Category category)
 {
     if (ModelState.IsValid)
     {
         db.Entry(category).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(category));
 }
Example #4
0
 public ActionResult Edit([Bind(Include = "Id,Name,Code,CategoryId")] Product product)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", product.CategoryId);
     return(View(product));
 }
Example #5
0
 public ActionResult Edit([Bind(Include = "Id,CategoryId,ItemId,StockInQuentity")] StockIn stockIn)
 {
     if (ModelState.IsValid)
     {
         db.Entry(stockIn).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CategoryId = new SelectList(db.Categorys, "Id", "CategoryName", stockIn.CategoryId);
     ViewBag.ItemId     = new SelectList(db.Items, "Id", "ItemName", stockIn.ItemId);
     return(View(stockIn));
 }
Example #6
0
        public bool Delete(T entity)
        {
            DbEntityEntry dbEntityEntry = _dbContext.Entry(entity);

            if (dbEntityEntry == null)
            {
                return(false);
            }

            if (dbEntityEntry.State != EntityState.Deleted)
            {
                dbEntityEntry.State = EntityState.Deleted;
            }
            else
            {
                _dbSet.Attach(entity);
                _dbSet.Remove(entity);
            }

            return(true);
        }
Example #7
0
 public ActionResult Edit([Bind(Include = "Id,CategoryId,CompanyId,ItemName,ReorderLevel")] Item item)
 {
     if (ModelState.IsValid)
     {
         db.Entry(item).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CategoryId = new SelectList(db.Categorys, "Id", "CategoryName", item.CategoryId);
     ViewBag.CompanyId  = new SelectList(db.Companys, "Id", "CompanyName", item.CompanyId);
     return(View(item));
 }
Example #8
0
        public async Task <IActionResult> UpdatedEntry(Stock stock)
        {
            if (ModelState.IsValid)
            {
                _context.Entry(stock).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                return(RedirectToAction("Home"));
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
        public bool UpdateCustomer(Customer customer)
        {
            int isExecuted = 0;

            db.Entry(customer).State = EntityState.Modified;
            isExecuted = db.SaveChanges();


            if (isExecuted > 0)
            {
                return(true);
            }
            return(false);
        }
        public async Task <IncreaseStockResponseModel> Handle(IncreaseStockCommand request, CancellationToken cancellationToken)
        {
            var stock = await _dbContext.Stocks.FirstOrDefaultAsync(x => x.ProductId == request.IncreaseStockRequest.ProductId);

            if (stock == null)
            {
                throw new System.Exception("Product not found!");
            }

            stock.Quantity += request.IncreaseStockRequest.Quantity;
            _dbContext.Stocks.Attach(stock);
            _dbContext.Entry(stock).Property(x => x.Quantity).IsModified = true;
            await _dbContext.SaveChangesAsync();

            return(_mapping.Map <Infrastructure.Entities.Stock, IncreaseStockResponseModel>(stock));
        }
        public bool UpdateCategory(Category category)
        {
            int isExecuted = 0;

            //Category aCategory = db.Categories.FirstOrDefault(c => c.Code == category.Code);
            //if (aCategory != null)
            //{
            //    aCategory.Name = category.Name;

            //}
            db.Entry(category).State = EntityState.Modified;
            isExecuted = db.SaveChanges();
            if (isExecuted > 0)
            {
                return(true);
            }
            return(false);
        }
        public async Task Consume(ConsumeContext <IUpdateStockEventModel> context)
        {
            var stock = await _dbContext.Stocks.FirstOrDefaultAsync(x => x.ProductId == context.Message.ProductId);

            if (stock == null)
            {
                await context.Publish <IOrderFailedEventModel>(new
                {
                    context.Message.OrderId
                });

                throw new Exception("Product not found!");
            }

            stock.Quantity -= context.Message.Quantity;
            if (stock.Quantity < 0)
            {
                await context.Publish <IOrderFailedEventModel>(new
                {
                    context.Message.OrderId
                });

                throw new Exception("Quantity must be greater than or equal to zero!");
            }

            _dbContext.Stocks.Attach(stock);
            _dbContext.Entry(stock).Property(x => x.Quantity).IsModified = true;
            if (await _dbContext.SaveChangesAsync() > 0)
            {
                await context.Publish <ICreateShipmentEventModel>(new
                {
                    context.Message.OrderId,
                    ShipmentType = (int)ShipmentType.MNG
                });
            }
            else
            {
                await context.Publish <IOrderFailedEventModel>(new
                {
                    context.Message.OrderId
                });
            }
        }
Example #13
0
        public bool UpdateSupplier(Supplier supplier)
        {
            int isExecuted = 0;

            //Supplier aSupplier = db.Suppliers.FirstOrDefault(c => c.Code == supplier.Code);
            //if (aSupplier != null)
            //{
            //    aSupplier.Name = supplier.Name;

            //}

            db.Entry(supplier).State = EntityState.Modified;
            isExecuted = db.SaveChanges();


            if (isExecuted > 0)
            {
                return(true);
            }
            return(false);
        }
Example #14
0
        public bool UpdateCustomerSale(CustomerSale customerSale)
        {
            int isExecuted = 0;

            //CustomerSale aCustomerSale = db.CustomerSales.FirstOrDefault(c => c.Code == customerSale.Code);
            //if (aCustomerSale != null)
            //{
            //    aCustomerSale.Name = customerSale.Name;

            //}

            db.Entry(customerSale).State = EntityState.Modified;
            isExecuted = db.SaveChanges();


            if (isExecuted > 0)
            {
                return(true);
            }
            return(false);
        }
Example #15
0
        public bool UpdateProductSale(ProductSale productSale)
        {
            int isExecuted = 0;

            //ProductSale aProductSale = db.ProductSales.FirstOrDefault(c => c.Code == productSale.Code);
            //if (aProductSale != null)
            //{
            //    aProductSale.Name = productSale.Name;

            //}

            db.Entry(productSale).State = EntityState.Modified;
            isExecuted = db.SaveChanges();


            if (isExecuted > 0)
            {
                return(true);
            }
            return(false);
        }
        public bool UpdatePurchase(Purchase purchase)
        {
            int isExecuted = 0;

            //Purchase aPurchase = db.Purchases.FirstOrDefault(c => c.Code == purchase.Code);
            //if (aPurchase != null)
            //{
            //    aPurchase.Name = purchase.Name;

            //}

            db.Entry(purchase).State = EntityState.Modified;
            isExecuted = db.SaveChanges();


            if (isExecuted > 0)
            {
                return(true);
            }
            return(false);
        }
        public async Task ConsumeAsync(UpdateStockEvent context, CancellationToken cancellationToken)
        {
            var stock = await _dbContext.Stocks.FirstOrDefaultAsync(x => x.ProductId == context.ProductId);

            if (stock == null)
            {
                await _bus.PubSub.PublishAsync(new OrderFailedEvent
                {
                    OrderId = context.OrderId
                });

                throw new Exception("Product not found!");
            }

            stock.Quantity -= context.Quantity;
            if (stock.Quantity < 0)
            {
                await _bus.PubSub.PublishAsync(new OrderFailedEvent
                {
                    OrderId = context.OrderId
                });

                throw new Exception("Quantity must be greater than or equal to zero!");
            }

            _dbContext.Stocks.Attach(stock);
            _dbContext.Entry(stock).Property(x => x.Quantity).IsModified = true;

            if (await _dbContext.SaveChangesAsync() > 0)
            {
                await _bus.PubSub.PublishAsync(new CreateShipmentEvent
                {
                    ShipmentType = (int)ShipmentType.MNG,
                    OrderId      = context.OrderId
                });
            }
        }
Example #18
0
        public static string GenerateNumber(ObjectType type, StockDbContext db)
        {
            int y   = DateTime.Now.Year;
            var obj = db.AutoNumbers.SingleOrDefault(p => p.Year == y && p.Object.Equals(type.ToString(), StringComparison.OrdinalIgnoreCase));

            if (obj != null)
            {
                obj.Number++;
                db.Entry(obj).State = System.Data.Entity.EntityState.Modified;
            }
            else
            {
                obj = new AutoNumber()
                {
                    Number = 1,
                    Object = type.ToString(),
                    Year   = y,
                };
                db.AutoNumbers.Add(obj);
            }
            db.SaveChanges();

            return(string.Format("{0}{1:00000}", EnumHelper.GetDescription(type), obj.Number));
        }
Example #19
0
 public void Update(TEntity item)
 {
     _context.Entry(item).State = EntityState.Modified;
     _context.SaveChanges();
 }
 // GET: SupplierContact/Edit/5
 public ActionResult Edit(SupplierContact model, int pageNo = 1)
 {
     db.Entry(model).State = EntityState.Modified;
     db.SaveChanges();
     return(RedirectToAction("Index", new { PageNo = pageNo }));
 }
Example #21
0
 // GET: Invoice/Edit/5
 public ActionResult Edit(Invoice model)
 {
     db.Entry(model).State = EntityState.Modified;
     db.SaveChanges();
     return(RedirectToAction("Details", "invoice", new { id = model.Id }));
 }