public async Task <IActionResult> Create(EducationBodyCreateViewModel bodyEdu) { if (ModelState.IsValid) { string uniqFileName = null; if (bodyEdu.StampFile != null && bodyEdu.StampFile.Length > 0) { if (IsFileValidate(bodyEdu.StampFile.FileName)) { string uplouadsFolder = Path.Combine(_ihostingEnvironment.WebRootPath, "img/stamps"); uniqFileName = Guid.NewGuid().ToString() + "_" + bodyEdu.StampFile.FileName; string filePath = Path.Combine(uplouadsFolder, uniqFileName); using (var fileStream = new FileStream(filePath, FileMode.Create)) { bodyEdu.StampFile.CopyTo(fileStream); } } else { ViewBag.msg = "الصور المسموح بها يجب ان تكون بمتداد : " + "png , jpeg , jpg , gif , bmp "; return(View(bodyEdu)); } } var educationalBody = new EducationalBody() { Name = bodyEdu.Name, City = bodyEdu.City, EntityType = bodyEdu.EntityType, UserId = bodyEdu.UserId, Stamp = uniqFileName }; _context.Add(educationalBody); await _context.SaveChangesAsync(); _f.Flash("success", "تم الحفظ بنجاح"); return(RedirectToAction(nameof(Index))); } var type = new List <EntityTypeForEducation>(); var Institutes = new EntityTypeForEducation() { Name = "المعاهد والدور" }; type.Add(Institutes); var Colleges = new EntityTypeForEducation() { Name = "الكليات" }; type.Add(Colleges); ViewData["type"] = new SelectList(type, "Name", "Name", bodyEdu.EntityType); ViewData["UserId"] = new SelectList(_context.Users.Include(u => u.UserRoles).Where(r => r.UserRoles.Any(a => a.Role.Name == "Supervisor")), "Id", "FullName", bodyEdu.UserId); return(View(bodyEdu)); }
// GET: Admin/EducationalBodies/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { Response.StatusCode = 404; return(View("EducationalNotFound")); } var educationalBody = await _context.EducationalBodies.FindAsync(id); if (educationalBody == null) { Response.StatusCode = 404; return(View("EducationalNotFound")); } var budyEdu = new EducationBodyEditViewModel() { City = educationalBody.City, EntityType = educationalBody.EntityType, Id = educationalBody.Id, Name = educationalBody.Name, Stamp = educationalBody.Stamp, UserId = educationalBody.UserId }; var type = new List <EntityTypeForEducation>(); var Institutes = new EntityTypeForEducation() { Name = "المعاهد والدور" }; type.Add(Institutes); var Colleges = new EntityTypeForEducation() { Name = "الكليات" }; type.Add(Colleges); ViewData["type"] = new SelectList(type, "Name", "Name", educationalBody.EntityType); ViewData["UserId"] = new SelectList(_context.Users.Include(u => u.UserRoles).Where(r => r.UserRoles.Any(a => a.Role.Name == "Supervisor")), "Id", "FullName", educationalBody.UserId); return(View(budyEdu)); }
// GET: Admin/EducationalBodies/Create public IActionResult Create() { var type = new List <EntityTypeForEducation>(); var Institutes = new EntityTypeForEducation() { Name = "المعاهد والدور" }; type.Add(Institutes); var Colleges = new EntityTypeForEducation() { Name = "الكليات" }; type.Add(Colleges); ViewData["UserId"] = new SelectList(_context.Users.Include(u => u.UserRoles) .Where(r => r.UserRoles.Any(a => a.Role.Name == "Supervisor")), "Id", "FullName"); ViewData["type"] = new SelectList(type, "Name", "Name"); return(View()); }