예제 #1
0
        public async Task <IActionResult> AddItems(AddItemsViewModel model)
        {
            if (ModelState.IsValid)
            {
                string uniqueFilename = null;
                if (model.ItemPhoto != null)
                {
                    string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "images\\item");
                    uniqueFilename = Guid.NewGuid().ToString() + "_" + Path.GetFileName(model.ItemPhoto.FileName);
                    string filePath = Path.Combine(uploadsFolder, uniqueFilename);
                    using (var fileStream = new FileStream(filePath, FileMode.Create))
                    {
                        model.ItemPhoto.CopyTo(fileStream);
                    }
                }

                Shop = await userManager.GetUserAsync(HttpContext.User);

                await itemsRepository.AddItem(new Items
                {
                    ItemName   = model.ItemName,
                    ItemPrice  = model.ItemPrice,
                    ItemDesc   = model.ItemDesc,
                    ItemWeight = model.ItemWeight,
                    Seller     = Shop,
                    category   = await context.Categories.FindAsync(model.Category),
                    Id         = Shop.Id,
                    IsInStock  = true,
                    PhotoPath  = uniqueFilename
                });

                ModelState.Clear();
                return(View());
            }

            return(View(model));
        }
예제 #2
0
 public AddItemsPage(NewItem arg)
 {
     BindingContext = new AddItemsViewModel(arg);
     InitializeComponent();
 }