コード例 #1
0
        public async Task <IActionResult> Insert(InsertProductViewModel model)
        {
            var productDto = _productDtoFactory.InsertProductDto(model.Title, model.Description, model.Feature, model.Price, model.QuantityInStock, model.Weight);
            await _productService.InsertProductAsync(productDto);

            return(View());
        }
コード例 #2
0
        public async Task <IActionResult> CreateProduct()
        {
            var model      = new InsertProductViewModel();
            var categories = await this.service.GetAllCategoryNamesAsync();

            model.Categories      = categories.ToList();
            model.CategoryPattern = await this.adminCharacteristicsServices.GetAvailableCharacteristicsAsync();

            return(this.View(model));
        }
コード例 #3
0
        public async Task <IActionResult> InsertProductConfirm(InsertProductViewModel model)
        {
            ApplicationUser applicationUser = new ApplicationUser();
            var             userID          = (await userManager.FindByNameAsync(User.Identity.Name)).Id;

            System.Globalization.PersianCalendar pc = new System.Globalization.PersianCalendar();

            var DateTimes = (pc.GetYear(DateTime.Now) + " " + pc.GetMonth(DateTime.Now) + " " + pc.GetDayOfMonth(DateTime.Now));

            TblProduct tblProduct = new TblProduct()
            {
                AllId          = model.GameId,
                About          = model.About,
                TblProductImgs = new List <TblProductImg>(),
                CategoryId     = model.CategoryId,
                PlatformId     = model.PlatformId,
                Level          = model.Level,
                UserId         = userID,
                Price          = model.Price,
                SavedDate      = DateTimes
            };

            model.Img.ForEach(x =>
            {
                if (x != null)
                {
                    byte[] b = new byte[x.Length];
                    x.OpenReadStream().Read(b, 0, b.Length);
                    var img       = Image.FromStream(new MemoryStream(b));
                    Bitmap bitmap = new Bitmap(img, 200, 200 * img.Height / img.Width);
                    MemoryStream thumbnailStream = new MemoryStream();
                    bitmap.Save(thumbnailStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                    TblProductImg productImage = new TblProductImg
                    {
                        Img      = b,
                        ImgThumb = thumbnailStream.ToArray()
                    };
                    tblProduct.TblProductImgs.Add(productImage);
                }
            });

            dbGamingShop.Add(tblProduct);
            dbGamingShop.SaveChanges();

            return(RedirectToAction("Index", "Home"));
        }
コード例 #4
0
        public IActionResult Create(InsertProductViewModel insertProductViewModel)
        {
            if (ModelState.IsValid)
            {
                var newProduct = new Product()
                {
                    Title    = insertProductViewModel.Title,
                    Category = insertProductViewModel.Category,
                    Date     = DateTime.UtcNow,
                    Price    = insertProductViewModel.Price,
                    Quantity = insertProductViewModel.Quantity
                };
                _productService.Add(newProduct);
                return(RedirectToAction("Index"));
            }

            return(View());
        }
コード例 #5
0
        public async Task <IActionResult> CreateProduct(InsertProductViewModel form)
        {
            var categories = await this.service.GetAllCategoryNamesAsync();

            form.Categories      = categories.ToList();
            form.CategoryPattern = await this.adminCharacteristicsServices.GetAvailableCharacteristicsAsync();

            if (!categories.Contains(form.Category))
            {
                this.ModelState.AddModelError("Category", "Invalid Category Name");
            }
            if (!this.ModelState.IsValid)
            {
                return(this.View(form));
            }


            await this.service.CreateProductAsync(form);

            return(this.RedirectToAction("Success", "Blacksmith", new { message = $"Successfully Created Product with id: {form.ArticleNumber} in category: {form.Category}" }));
        }
コード例 #6
0
        public IActionResult Insert()
        {
            var model = new InsertProductViewModel();

            return(View(model));
        }
コード例 #7
0
        public IActionResult Create()
        {
            var insertProductViewModel = new InsertProductViewModel();

            return(View(insertProductViewModel));
        }
コード例 #8
0
        public async Task <ActionResult <Product> > PostProduct([FromBody] InsertProductViewModel model)
        {
            if (String.IsNullOrEmpty(model.productId))
            {
                return(Ok("Mã sản phẩm không được để trống."));
            }

            if (!CategoryExists(model.categoryId))
            {
                return(NotFound());
            }
            foreach (var item in model.supplies)
            {
                if (!SupplierExists(item))
                {
                    return(NotFound());
                }
            }
            if (string.IsNullOrEmpty(model.images))
            {
                return(Ok("Vui lòng chọn hình ảnh đính kèm."));
            }

            if (model.images.Length > 1048576)
            {
                return(Ok("Kích thước không vượt quá 1mb"));
            }

            string path = _webhostEnvieronment.WebRootPath + "\\uploads\\";

            string filename = model.productId + ".png";

            try
            {
                Base64ToImage(model.images, path + filename);
                //if (model.images.Length > 0)
                //{

                //    if (!Directory.Exists(path))
                //    {
                //        Directory.CreateDirectory(path);
                //    }
                //    using (FileStream file = System.IO.File.Create(path + model.images.FileName))
                //    {
                //        model.Image.CopyTo(file);
                //        file.Flush();
                //    }
                //}
            }
            catch (Exception e)
            {
                return(Ok(e.Message));
            }

            UserCredential credential;

            credential = GetCredentials();

            // Create Drive API service.
            var service = new DriveService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = ApplicationName,
            });

            //Id của folder muốn upload
            string folderid = "1iCNelsHCSLGKQL9XRJwMu9nUHZURFgR8";

            var filePath = path + filename;

            string fileId = "1paIUZyOqIW5ZllHXE0b6r-kZWJHQMQYR";

            try
            {
                fileId       = UploadImage(filePath, service, folderid);
                model.images = fileId;
            }
            catch (Exception e)
            {
                return(Ok(e.Message));
            }

            var product = model.ToProduct();

            WareHouse ware = new WareHouse();

            ware.Date      = DateTime.Now;
            ware.ProductId = product.ProductId;
            ware.Quantity  = 0;

            product.WareHouses.Add(ware);

            _context.Products.Add(product);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (ProductExists(product.ProductId))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetProductDetails", new { productId = product.ProductId }, product));
        }