Exemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("ImageId,Title,ImageFile")] ImageModal imageModal)
        {
            if (ModelState.IsValid)
            {
                if (imageModal != null && imageModal.ImageFile != null)
                {
                    //Save Image to wwwroot/Image
                    string wwwRootPath = _hostEnvironment.WebRootPath;
                    string fileName    = Path.GetFileNameWithoutExtension(imageModal.ImageFile.FileName);
                    string extension   = Path.GetExtension(imageModal.ImageFile.FileName);
                    imageModal.ImageName = fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                    string path = Path.Combine(wwwRootPath + "/Image/", fileName);
                    using (var fileStream = new FileStream(path, FileMode.Create))
                    {
                        await imageModal.ImageFile.CopyToAsync(fileStream);
                    }
                }
                //Insert record

                _context.Add(imageModal);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(imageModal));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, [Bind("ImageId,Title,ImageName")] ImageModal imageModal)
        {
            if (id != imageModal.ImageId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(imageModal);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ImageModalExists(imageModal.ImageId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(imageModal));
        }
Exemplo n.º 3
0
 private void clearBtn_Click(object sender, EventArgs e)
 {
     _imageModal     = new ImageModal();
     inputPic.Image  = null;
     resultPic.Image = null;
     richTextBox1.Clear();
     for (int i = 0; i < checkedListBox1.Items.Count; i++)
     {
         checkedListBox1.SetItemCheckState(i, CheckState.Unchecked);
     }
 }
        public JsonResult ImageUpload(ImageModal img)
        {
            var file = img.imageFile;

            if (file != null)
            {
                var fname   = Path.GetFileName(file.FileName);
                var ext     = Path.GetExtension(file.FileName);
                var without = Path.GetFileNameWithoutExtension(file.FileName);
                file.SaveAs(Server.MapPath("/imagefolder/" + file.FileName));
            }
            return(Json(file.FileName, JsonRequestBehavior.AllowGet));
        }