コード例 #1
0
ファイル: StockServiceTest.cs プロジェクト: katiie/BookStore
        /// Creates this instance.
        /// </summary>
        /// <returns>The id of the new record.</returns>
        private Guid Create()
        {
            // Arrange
            Stock Stock = Builder <Stock> .CreateNew().With(s => s.Id = Guid.NewGuid())
                          .With(s => s.BookId   = Book.Id)
                          .With(s => s.StoreId  = Store.Id)
                          .With(s => s.Quantity = Faker.RandomNumber.Next(2))
                          .Build();

            // Act
            var StockId = _StockService.Add(Stock);

            // Assert
            Assert.AreNotEqual(Guid.Empty, Stock.Id, "Creating new record returns id");

            Stock = Builder <Stock> .CreateNew().With(s => s.Id = Guid.NewGuid())
                    .With(s => s.BookId  = Book.Id)
                    .With(s => s.StoreId = Store.Id)
                    .Build();


            Stock.Id = _StockService.Add(Stock);
            Assert.AreNotEqual(Guid.Empty, Stock.Id, "Creating new record does not return id");


            return(StockId);
        }
コード例 #2
0
        public ActionResult OrderEntry(OrderEntry orderEntry)
        {
            try
            {
                Stock stock = new Stock();
                stock.SupplierId     = orderEntry.Supplier.UniqueId;
                stock.ProductId      = orderEntry.Product.UniqueId;
                stock.UnitId         = orderEntry.Unit.UniqueId;
                stock.EntryDate      = orderEntry.Stock.EntryDate;
                stock.Quatity        = orderEntry.Stock.Quatity;
                stock.CostPerProduct = orderEntry.Stock.CostPerProduct;
                stock.CreatedBy      = User.Identity.Name;
                stock.CreatedDate    = DateTime.Now;

                stockService.Add(stock);
                stockService.Save();

                return(RedirectToAction("GetOrderEntry"));
            }
            catch (Exception ex)
            {
                ViewBag.Suppliers = supplierService.GetAll().Where(x => x.IsActive == true).ToList();
                ViewBag.Products  = productService.GetAll().Where(x => x.IsActive == true).ToList();
                ViewBag.Units     = unitService.GetAll().Where(x => x.IsActive == true).ToList();
            }

            return(View(orderEntry));
        }
コード例 #3
0
        public IActionResult AddAmountStock([FromBody] StockCreate stock)
        {
            if (stock == null)
            {
                return(NotFound());
            }

            return(Execute(() => _stockService.Add(stock).Id));
        }
コード例 #4
0
        public async Task <HttpResponseMessage> PostStock(HttpRequestMessage request)
        {
            _stockService = new StockService();
            var message    = "";
            var jsonString = await request.Content.ReadAsStringAsync();

            var model = JsonConvert.DeserializeObject <Stock>(jsonString);

            return(new HttpResponseMessage(_stockService.Add(model, out message) ? HttpStatusCode.OK : HttpStatusCode.InternalServerError));
        }
コード例 #5
0
        public IActionResult Add(Stock stock)
        {
            var result = _stockService.Add(stock);

            if (result.Success)
            {
                return(Ok(result.Message));
            }

            return(BadRequest(result.Message));
        }
コード例 #6
0
        public async Task <ActionResult> Post([FromBody] Stock value)
        {
            try
            {
                var result = await stockService.Add(value);

                return(Ok(result));
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
コード例 #7
0
        // POST api/Stock
        public IHttpActionResult PostStock(Stock stock)
        {
            if (ModelState.IsValid)
            {
                service.Add(new dm.stock()
                {
                    code      = stock.code,
                    name      = stock.name,
                    price     = stock.price,
                    symbol    = stock.symbol,
                    yestclose = stock.yestclose
                });

                return(Ok <Stock>(stock));
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
コード例 #8
0
        public ActionResult Create(StockViewModel item)
        {
            try
            {
                // TODO: Add insert logic here
                Stock AVM = new Stock();
                AVM.idProduct = item.idProduct;
                AVM.idStore   = item.idStore;
                AVM.Quantity  = item.Quantity;


                StockService.Add(AVM);
                StockService.Commit();

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }