public Manahel GetManahel(int idProduct) { var product = context.Products.Find(idProduct); if (product != null) { Manahel manahel = context.Manahels.Find(product.ManhalId); if (manahel != null) { return(manahel); } } return(null); }
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 SearchType(int id, string txtSearch) { ViewData["ManhalImage"] = new AddImageVM() { id = id, imageFile = null }; Manahel manahel = context1.GetElement(id); if (manahel != null) { List <Khalias> khalias = context1.GetKhaliases(id).Where(a => a.KhaliaType == txtSearch).ToList(); List <ImagesManahel> images = context1.GetImages(id); ManhalDetailsVM detailsVM = new ManhalDetailsVM(); detailsVM.manhal = manahel; detailsVM.khalias = khalias; detailsVM.imagesManahels = images; return(View(nameof(Details), detailsVM)); } return(NotFound()); }
public ActionResult Edit(int id, [Bind("Id,Ssn,NickName,LocationName,FlowerName,DateCreated")] Manahel manahel) { if (id != manahel.Id) { return(NotFound()); } if (ModelState.IsValid) { try { manahel.DateUpdated = DateTime.Now; context1.Updata(manahel); context1.Savechange(); if (IsSuperAdmin == true) { return(RedirectToAction(nameof(SuperAdminIndex))); } else { string userId = contextuser.GetAllBy(a => a.ManelId == manahel.Id).FirstOrDefault().UserId; return(RedirectToAction(nameof(AdminIndex), new { user_ID = manahel })); } } catch (DbUpdateConcurrencyException) { if (!context1.IsExist(a => a.Id == manahel.Id)) { return(NotFound()); } else { throw; } } } return(View(manahel)); }
// GET: Manahels/Details/5 public ActionResult Details(int id) { ViewData["ManhalImage"] = new AddImageVM() { id = id, imageFile = null }; Manahel manahel = context1.GetElement(id); if (manahel != null) { List <Khalias> khalias = context1.GetKhaliases(id); List <ImagesManahel> images = context1.GetImages(id); ManhalDetailsVM detailsVM = new ManhalDetailsVM(); detailsVM.manhal = manahel; detailsVM.khalias = khalias; detailsVM.imagesManahels = images; return(View(detailsVM)); } return(NotFound()); //return View(manahel); }