public ActionResult Delete(int id) { int result = 0; Student2Repository objStudent2Repository = new Student2Repository(); Student2ViewModel objEntity = new Student2ViewModel(); CountryStateRepository objCountryStateRepository = new CountryStateRepository(); objEntity = objStudent2Repository.Select(StudentFlags.SelectByID.GetHashCode(), new Student2ViewModel() { StudentId = id }).FirstOrDefault(); if (objEntity == null) { //delete old file ApplicationHelpers.DeleteFile(Path.Combine(Server.MapPath(ApplicationConstant.UPLOADED_STUDENT_IMAGE_PATH), objEntity.FileName)); } result = objStudent2Repository.Delete(StudentFlags.DeleteByID.GetHashCode(), new Student2ViewModel() { StudentId = id, }); if (result == ResultFlags.Success.GetHashCode()) { this.Flash("success", "Student Delete successfully"); return(RedirectToAction("Index")); } else if (result == ResultFlags.Failure.GetHashCode()) { this.Flash("error", "Faild to Delete Student"); return(RedirectToAction("Index")); } return(RedirectToAction("Index")); }
public ActionResult Edit(int id, Student2ViewModel objEntity) { Student2Repository objStudent2Repository = new Student2Repository(); CountryStateRepository objCountryStateRepository = new CountryStateRepository(); string fileName = string.Empty; string oldFileName = string.Empty; if (ModelState.IsValid) { objEntity.Name = objEntity.Name.Trim(); objEntity.StudentId = id; oldFileName = objEntity.FileName; #region FileUpload if (objEntity.UploadFile != null) { fileName = Guid.NewGuid().ToString() + Path.GetExtension(objEntity.UploadFile.FileName); objEntity.FileName = fileName; } #endregion objEntity = objStudent2Repository.Update(StudentFlags.UpdateByID.GetHashCode(), objEntity); if (objEntity.Result == ResultFlags.Success.GetHashCode()) { #region FileUpload //delete old file //file name if (objEntity.UploadFile != null) { if (!string.IsNullOrEmpty(objEntity.UploadFile.FileName)) { ApplicationHelpers.DeleteFile(Path.Combine(Server.MapPath(ApplicationConstant.UPLOADED_STUDENT_IMAGE_PATH), oldFileName)); } string path = Path.Combine(Server.MapPath(ApplicationConstant.UPLOADED_STUDENT_IMAGE_PATH), fileName); // WebImage.Save() objEntity.UploadFile.SaveAs(path); } #endregion this.Flash("success", "Student Details updated successfully"); return(RedirectToAction("Index")); } else if (objEntity.Result == ResultFlags.Failure.GetHashCode()) { this.Flash("error", "Student Details failed to Update"); } else if (objEntity.Result == ResultFlags.Duplicate.GetHashCode()) { this.Flash("warning", "Student Name is Already Exist"); } } #region DatabaseDropdown var objCourseRepository = new CourseRepository(); var objCourseViewModelEntity = objCourseRepository.Select(CourseFlags.SelectAll.GetHashCode(), new CourseViewModel()); objEntity.CourseList = new SelectList(objCourseViewModelEntity.Select(model => new { model.CourseId, model.CourseTitle }), "CourseId", "CourseTitle"); #endregion #region DatabaseOptionGroup var objCountryStateEntityList = objCountryStateRepository.Select(CountryStateFlags.SelectAllForOptionGroup.GetHashCode(), new CountryStateViewModel()); objEntity.SelectCountryList = new SelectList(objCountryStateEntityList, "StateId", "StateName", "CountryName", 1); #endregion return(View(objEntity)); }
public ActionResult ProfileEdit(int id, RegistrationUpdateViewModel objUpdateEntity) { var objRegistrationRepository = new RegistrationRepository(); string fileName = string.Empty; string oldFileName = string.Empty; if (ModelState.IsValid) { #region FileUpload if (objUpdateEntity.UploadPhoto != null) { fileName = Guid.NewGuid().ToString() + Path.GetExtension(objUpdateEntity.UploadPhoto.FileName); oldFileName = objUpdateEntity.PhotoName; objUpdateEntity.PhotoName = fileName; } #endregion objUpdateEntity.FirstName = objUpdateEntity.FirstName.Trim(); objUpdateEntity.LastName = objUpdateEntity.LastName.Trim(); objUpdateEntity.PhotoName = objUpdateEntity.PhotoName; objUpdateEntity.Location = objUpdateEntity.Location.Trim(); objUpdateEntity.MobileNumber = objUpdateEntity.MobileNumber.Trim(); objUpdateEntity.RegistrationId = id; var objEntity = new RegistrationViewModel() { RegistrationId = objUpdateEntity.RegistrationId, UserId = objUpdateEntity.UserId, FirstName = objUpdateEntity.FirstName, LastName = objUpdateEntity.LastName, PhotoName = objUpdateEntity.PhotoName, DateOfBirth = objUpdateEntity.DateOfBirth, Gender = objUpdateEntity.Gender, Location = objUpdateEntity.Location, MobileNumber = objUpdateEntity.MobileNumber }; objEntity = objRegistrationRepository.Update(RegistrationFlags.UpdateByID.GetHashCode(), objEntity); if (objEntity.Result == ResultFlags.Success.GetHashCode()) { #region FileUpload //delete old file //file name if (objUpdateEntity.UploadPhoto != null) { if (!string.IsNullOrEmpty(objUpdateEntity.UploadPhoto.FileName)) { ApplicationHelpers.DeleteFile(Path.Combine(Server.MapPath(ApplicationConstant.UPLOADED_USER_PHOTO_PATH), oldFileName)); } string path = Path.Combine(Server.MapPath(ApplicationConstant.UPLOADED_USER_PHOTO_PATH), fileName); // WebImage.Save() objUpdateEntity.UploadPhoto.SaveAs(path); } #endregion this.Flash("success", "My Profile updated successfully "); //reload admin profile SessionWrapper.UserAccount = null; AccountRepository objAccountRepository = new AccountRepository(); objAccountRepository.SetAccountByUser(objEntity.UserId); return(RedirectToAction("Dashboard", "User")); } else if (objEntity.Result == ResultFlags.Failure.GetHashCode()) { this.Flash("Error", "My Profile failed to update"); } else if (objEntity.Result == ResultFlags.Duplicate.GetHashCode()) { this.Flash("Warning", "It already exist"); } } return(View(objUpdateEntity)); }