Exemple #1
0
        public async Task <IActionResult> AddImage(int?id, IFormFile uploads)
        {
            if (id != null)
            {
                if (uploads != null)
                {
                    MainImages images = await _context.MainImages.Where(x => x.id == id).FirstOrDefaultAsync();

                    byte[] p1 = null;
                    using (var fs1 = uploads.OpenReadStream())
                        using (var ms1 = new MemoryStream())
                        {
                            fs1.CopyTo(ms1);
                            p1 = ms1.ToArray();
                        }
                    images.ImageType = uploads.ContentType;
                    images.Image     = p1;
                    _context.MainImages.Update(images);
                    _context.SaveChanges();
                    return(RedirectToAction(nameof(Index)));
                }
            }

            return(RedirectToAction(nameof(Index)));
        }
Exemple #2
0
        public async Task <IActionResult> Edit(int id, [Bind("id,Name,Image,ImageType")] MainImages mainImages)
        {
            if (id != mainImages.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(mainImages);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MainImagesExists(mainImages.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(mainImages));
        }
Exemple #3
0
        public async Task <IActionResult> Create([Bind("id,Name,Image,ImageType")] MainImages mainImages)
        {
            if (ModelState.IsValid)
            {
                _context.Add(mainImages);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(mainImages));
        }
Exemple #4
0
        public FileContentResult GetImage(string?name)
        {
            MainImages images = _context.MainImages
                                .FirstOrDefault(g => g.Name == name);

            if (images != null)
            {
                var file = File(images.Image, images.ImageType);
                return(file);
            }
            else
            {
                return(null);
            }
        }
        public async Task <IActionResult> OnPostSubmitGoodsAsync()
        {
            if (CheckHasNull())
            {
                return(RedirectToPage("/ErrorNull"));
            }
            BaseResponseModel <string> responseModel = new BaseResponseModel <string>();

            if (MainImages.Count > 5)
            {
                MainImages.RemoveRange(5, MainImages.Count - 5);
            }
            if (GoodsModel.GoodsMainImages == null)
            {
                GoodsModel.GoodsMainImages = new List <FileModel <string[]> >();
            }
            if (GoodsModel.GoodsOtherImages == null)
            {
                GoodsModel.GoodsOtherImages = new List <FileModel <string[]> >();
            }
            await SaveImage(ListImage);
            await SaveImages(MainImages, GoodsModel.GoodsMainImages);
            await SaveImages(OtherImages, GoodsModel.GoodsOtherImages);

            saveColor();
            saveRule();
            if (GoodsModel.GoodsPayType == 2)
            {
                GoodsModel.GoodsPrice = new decimal(0.01);
            }
            try
            {
                new MongoDBTool().GetMongoCollection <GoodsModel>().InsertOne(GoodsModel);
                responseModel.StatusCode = (int)ActionParams.code_ok;
            }
            catch (Exception)
            {
                responseModel.StatusCode = (int)ActionParams.code_error;
                throw;
            }

            return(RedirectToPage("/GoodsPushFinish"));
        }