Пример #1
0
        public async Task <IActionResult> Create([Bind("Name,Upload,Photo,Id,Price,Star,Count")] Shop shop)
        {
            if (shop.Upload == null)
            {
                ModelState.AddModelError("Upload", "Şəkil məcburidir");
            }
            else
            {
                if (shop.Upload.ContentType != "image/jpeg" && shop.Upload.ContentType != "image/png" && shop.Upload.ContentType != "image/gif")
                {
                    ModelState.AddModelError("Upload", "Siz yalnız png,jpg və ya gif faylı yükləyə bilərsiniz");
                }

                if (shop.Upload.Length > 1048576)
                {
                    ModelState.AddModelError("Upload", "Fayl ölcüsu maximum 1MB ola bilər");
                }
            }
            if (ModelState.IsValid)
            {
                var fileName = _fileManager.Upload(shop.Upload);
                shop.Photo = fileName;

                await _context.AddAsync(shop);

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(shop));
        }
        public async Task <ProductDTO> Handle(ProductCreateCommand request, CancellationToken cancellationToken)
        {
            var tracking = await _context.AddAsync(new Domain.Product
            {
                Name        = request.Name,
                Description = request.Description,
                Expiration  = request.Expiration
            });

            var result = await _context.SaveChangesAsync();

            return(_mapper.Map <ProductDTO>(tracking.Entity));
        }