예제 #1
0
        // 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));
        }
예제 #2
0
        public async Task <IActionResult> Edit(int id, EducationBodyEditViewModel bodyEdu)
        {
            if (id != bodyEdu.Id)
            {
                Response.StatusCode = 404;
                return(View("EducationalNotFound"));
            }

            if (ModelState.IsValid)
            {
                string uniqFileName    = null;
                string filenameForEdit = null;
                if (bodyEdu.StampFile != null && bodyEdu.StampFile.Length > 0)
                {
                    if (bodyEdu.Stamp != null)
                    {
                        string filePathForDelete = Path.Combine(_ihostingEnvironment.WebRootPath,
                                                                "img/stamps", bodyEdu.Stamp);
                        System.IO.File.Delete(filePathForDelete);
                    }
                    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));
                    }
                }
                filenameForEdit = uniqFileName == null ? bodyEdu.Stamp : uniqFileName;
                var eduEdit = new EducationalBody()
                {
                    City   = bodyEdu.City, Stamp = filenameForEdit,
                    UserId = bodyEdu.UserId, EntityType = bodyEdu.EntityType,
                    Id     = bodyEdu.Id, Name = bodyEdu.Name
                };
                _context.Update(eduEdit);
                _f.Flash("success", "تم التعديل بنجاح");
                await _context.SaveChangesAsync();

                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));
        }