public ActionResult AddImage2(int id, IFormFile imageFile)
        {
            string uniqueFileName = null;

            if (imageFile != null)
            {
                try
                {
                    string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "images");
                    uniqueFileName = Guid.NewGuid().ToString() + "_" + imageFile.FileName;
                    string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                    using (var fileStream = new FileStream(filePath, FileMode.Create))
                    {
                        imageFile.CopyTo(fileStream);
                    }
                    ImagesManahel image = new ImagesManahel();
                    image.ImagesString = uniqueFileName;
                    image.ManahelId    = id;
                    context1.AddImage(image);
                }
                catch { }
            }
            List <ImagesManahel> images = context1.GetImages(id);

            return(new JsonResult(images));
            //return RedirectToAction("Details", "Manahels", new { id = id });
        }
        public ActionResult DeleteImage(int idImg, int id)
        {
            ImagesManahel image = context1.GetImages(id).Where(a => a.Id == idImg).FirstOrDefault();

            context1.DeleteImage(idImg);
            return(RedirectToAction(nameof(Details), new { id = id }));
        }
        public ActionResult Create(CreateManhalVM manahelVM)
        {
            var res = contextuser.GetUsers();

            ViewData["Users"] = res;
            if (ModelState.IsValid)
            {
                Task <bool> b = context1.Is_SSN_Exist(manahelVM.manahel.Ssn, manahelVM.AccountId);
                if (b.Result == false)
                {
                    manahelVM.manahel.DateUpdated = manahelVM.manahel.DateCreated;
                    Manahel manahel = context1.Add(manahelVM.manahel);
                    context1.Savechange();
                    UsersManhals usersManhals = new UsersManhals();
                    usersManhals.ManelId = manahel.Id;
                    usersManhals.UserId  = manahelVM.AccountId;
                    contextuser.Add(usersManhals);
                    contextuser.Savechange();
                    string uniqueFileName = null;
                    if (manahelVM.imageFile != null)
                    {
                        try
                        {
                            string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "images");
                            uniqueFileName = Guid.NewGuid().ToString() + "_" + manahelVM.imageFile.FileName;
                            string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                            using (var fileStream = new FileStream(filePath, FileMode.Create))
                            {
                                manahelVM.imageFile.CopyTo(fileStream);
                            }
                            ImagesManahel images = new ImagesManahel();
                            images.ImagesString = uniqueFileName;
                            images.ManahelId    = manahel.Id;

                            context1.AddImage(images);
                        }
                        catch { }
                    }
                    return(RedirectToAction(nameof(SuperAdminIndex)));
                }
            }
            return(View(manahelVM));
        }
        public ActionResult AddImage(AddImageVM imageVM)
        {
            string uniqueFileName = null;

            if (imageVM.imageFile != null)
            {
                try
                {
                    string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "images");
                    uniqueFileName = Guid.NewGuid().ToString() + "_" + imageVM.imageFile.FileName;
                    string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                    using (var fileStream = new FileStream(filePath, FileMode.Create))
                    {
                        imageVM.imageFile.CopyTo(fileStream);
                    }
                    ImagesManahel images = new ImagesManahel();
                    images.ImagesString = uniqueFileName;
                    images.ManahelId    = imageVM.id;
                    context1.AddImage(images);
                }
                catch { }
            }
            return(RedirectToAction("Details", "Manahels", new { id = imageVM.id }));
        }
示例#5
0
 public int AddImage(ImagesManahel item)
 {
     context.ImagesManahels.Add(item);
     return(context.SaveChanges());
 }