Exemplo n.º 1
0
        public IActionResult EditSchool(int schoolId)
        {
            School      dbModel = _schoolActions.GetSchool(schoolId);
            AddSchoolVM model   = new AddSchoolVM
            {
                SchoolName        = dbModel.SchoolName,
                SchoolDescription = dbModel.SchoolDescription,
                SchoolAddress     = dbModel.SchoolAddress,
                SchoolCity        = dbModel.SchoolCity,
                SchoolState       = dbModel.SchoolState,
                SchoolEmail       = dbModel.SchoolEmail,
                PrincipalName     = dbModel.PrincipalName,
                SchoolPhone       = dbModel.SchoolPhone,
                SchoolPhone2      = dbModel.SchoolPhone2,
                SchoolWeb         = dbModel.SchoolWeb,
                SchoolId          = dbModel.SchoolId,
                ProfileImagePath  = dbModel.ProfileImagePath,
                IsBoarding        = dbModel.IsBoarding,
                IsReligious       = dbModel.IsReligious,
                AgeRange          = dbModel.AgeRange,
                NumberOfStudents  = dbModel.NumberOfStudents,
                NumberOfTeachers  = dbModel.NumberOfTeachers,
                YearFounded       = dbModel.YearFounded,
            };

            return(View("AddSchool", model));
        }
Exemplo n.º 2
0
        public IActionResult AddSchool(AddSchoolVM modelData)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (modelData != null)
                    {
                        if (modelData.ProfileImagePath == null && modelData.SchoolId > 0)
                        {
                            modelData.ProfileImagePath = _schoolActions.GetSchoolProfileImagePath(modelData.SchoolId);
                        }

                        if (modelData.ProfileImage != null)
                        {
                            string fileName      = null;
                            string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "img");
                            fileName = Guid.NewGuid().ToString() + "_" + modelData.ProfileImage.FileName;
                            string filePath = Path.Combine(uploadsFolder, fileName);
                            // For proper disposal of fileStream
                            using (var fileStream = new FileStream(filePath, FileMode.Create))
                            {
                                modelData.ProfileImage.CopyTo(fileStream);
                            }
                            modelData.ProfileImagePath = fileName;
                        }

                        School schoolData = new School
                        {
                            SchoolId          = modelData.SchoolId,
                            SchoolName        = modelData.SchoolName,
                            SchoolDescription = modelData.SchoolDescription,
                            SchoolAddress     = modelData.SchoolAddress,
                            SchoolCity        = modelData.SchoolCity,
                            SchoolState       = modelData.SchoolState,
                            SchoolEmail       = modelData.SchoolEmail,
                            SchoolPhone       = modelData.SchoolPhone,
                            SchoolPhone2      = modelData.SchoolPhone2,
                            PrincipalName     = modelData.PrincipalName,
                            SchoolWeb         = modelData.SchoolWeb,
                            IsBoarding        = modelData.IsBoarding,
                            IsReligious       = modelData.IsReligious,
                            AgeRange          = modelData.AgeRange,
                            NumberOfStudents  = modelData.NumberOfStudents,
                            NumberOfTeachers  = modelData.NumberOfTeachers,
                            YearFounded       = modelData.YearFounded,
                            ProfileImagePath  = modelData.ProfileImagePath
                                                //ProfileImagePath = !string.IsNullOrWhiteSpace(fileName) ? fileName : _schoolActions.GetSchoolProfileImagePath(modelData.SchoolId),
                        };

                        var res = _schoolActions.SaveSchool(schoolData);
                        return(View("School", res));
                    }
                    else
                    {
                        return(View());
                    }
                }
                else
                {
                    return(View());
                }
            }
            catch
            {
                return(RedirectToAction("Error"));
            }
            //catch
            //{
            //    throw;
            //}
        }