예제 #1
0
        // GET: Products/Create
        public async Task <ActionResult> Create()
        {
            CreateProductsVM model = new CreateProductsVM();

            var providers = await _providersService.GetAll();

            model.Providers = providers.Select(l => new SelectListItem()
            {
                Text  = l.ProvName,
                Value = l.Id.ToString()
            });
            model.ProvidId = providers != null && providers.Any() ? providers.First().Id : 0;


            var locations = await _locationService.GetAll();

            model.Locations = locations.Select(l => new SelectListItem()
            {
                Text  = l.LocName,
                Value = l.Id.ToString()
            });
            model.LocId = locations != null && locations.Any() ? locations.First().Id : 0;

            //ViewBag.ProvId = new SelectList(db.Providers, "ProvId", "ProvName");
            return(View(model));
        }
예제 #2
0
        // GET: Products/Create
        public ActionResult Create()
        {
            //ViewBag.LocationId = new SelectList(db.Locations, "LocId", "LocName");
            //return View();
            CreateProductsVM model = new CreateProductsVM();

            var locations = await _locationService.GetAll();

            model.Locations = locations.Select(l => new SelectListItem()
            {
                Text  = l.Name,
                Value = l.Id.ToString()
            });
            model.LocationId = locations != null && locations.Any() ? locations.First().Id : 0;

            return(View(model));
        }
예제 #3
0
        public async Task <ActionResult> Create(CreateProductsVM model)
        {
            if (ModelState.IsValid)
            {
                Products newprod = new Products()
                {
                    Item        = model.Item,
                    Brand       = model.Brand,
                    Description = model.Description,
                    Qty         = model.Qty,
                    Cost        = model.Cost,
                    Price       = model.Price,
                    Warranty    = model.Warranty,
                    DateAd      = model.DateAd,
                    ProvId      = model.ProvidId,
                    LocId       = model.LocId,
                    DateCreated = DateTimeOffset.Now
                };

                //try
                //{
                //    await _productsService.Create(newprod);

                //    TempData.Add("SuccessMsg", "The new product was created successfully!");
                //}
                //catch (Exception ex)
                //{
                //    // Add message to the user
                //    Console.WriteLine("An error has occurred. Message: " + ex.ToString());
                //    throw;
                //}
                await _productsService.Create(newprod);

                return(RedirectToAction("Index"));
                //db.Products.Add(products);
                //await db.SaveChangesAsync();
                //return RedirectToAction("Index");
            }

            //ViewBag.ProvId = new SelectList(db.Providers, "ProvId", "ProvName", products.ProvId);
            return(View(model));
        }