public ActionResult UpdateAllowance(MedicalAllowanceInfo medicalAllowanceInfo) { try { if (!ModelState.IsValid) { return(View()); } using (MedicalAllowanceRepository Repo = new MedicalAllowanceRepository()) { medicalAllowanceInfo.Category = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(medicalAllowanceInfo.Category.ToLower()); Repo.UpdateMedicalAllowance(medicalAllowanceInfo); TempData["Msg"] = AlertMessageProvider.SuccessMessage("Allowance updated successfully."); return(RedirectToAction("Allowance", "Medical")); } } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Medical", "UpdateAllowance"))); } }
public ActionResult Delete(string LeaveId = "", string EmployeeInfoId = "") { try { int _leaveId; int _employeeInfoId; LeaveRequestInfo _leave = null; if (!int.TryParse(LeaveId, out _leaveId) || !int.TryParse(EmployeeInfoId, out _employeeInfoId)) { return(RedirectToAction("Manage", "Leave")); } using (LeaveRequestRepository Repo = new LeaveRequestRepository()) { _leave = Repo.GetLeaveRequestById(_leaveId); if (_leave == null) { return(RedirectToAction("Manage", "Leave")); } Repo.DeleteLeaveRequest(_leaveId); } TempData["Msg"] = AlertMessageProvider.SuccessMessage("Leave(s) deleted successfully."); return(RedirectToAction("Manage", "Leave", new { id = EmployeeInfoId })); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Leave", "Delete"))); } }
public ActionResult DeletePhoto(string PhotoId = "", string AlbumId = "") { try { int _photoId; int _albumId; PhotoInfo _photoInfo = null; AlbumInfo _albumInfo = null; if (!int.TryParse(PhotoId, out _photoId) || !int.TryParse(AlbumId, out _albumId)) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later."); return(RedirectToAction("Manage", "Gallery")); } using (AlbumRepository Repo = new AlbumRepository()) { _albumInfo = Repo.GetAlbumById(_albumId); } if (_albumInfo == null) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Album does not exist."); return(RedirectToAction("Manage", "Gallery")); } using (PhotoRepository Repo = new PhotoRepository()) { _photoInfo = Repo.GetPhotoById(_photoId); if (_photoInfo == null) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Photo does not exist."); return(RedirectToAction("Manage", "Gallery")); } string fullPath = Request.MapPath(_photoInfo.Path); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } Repo.DeletePhoto(_photoId); TempData["Msg"] = AlertMessageProvider.SuccessMessage("Photos deleted successfully."); return(RedirectToAction("UploadPhotos", "Gallery", new { id = AlbumId })); } } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Gallery", "DeletePhoto"))); } }
public ActionResult ApplyMedical(string id = "") { try { int _id; MedicalCheckoutInfo _medicalCheckout = null; if (!int.TryParse(id, out _id)) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong please try again later."); return(RedirectToAction("Details", "Medical")); } using (MedicalPrescriptionRepository Repo = new MedicalPrescriptionRepository()) { var _prescriptions = Repo.GetMedicalPrescriptionsListByMedicalCheckoutId(_id); if (_prescriptions.Count() == 0) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Please upload prescription(s)."); return(RedirectToAction("Details", "Medical", new { id = _id })); } } using (MedicalCheckoutRepository Repo = new MedicalCheckoutRepository()) { _medicalCheckout = Repo.GetMedicalCheckoutById(_id); if (_medicalCheckout == null || _medicalCheckout.EmployeeInfoId != CurrentUser.EmployeeInfoId || _medicalCheckout.Status == "Approved") { TempData["Msg"] = AlertMessageProvider.FailureMessage("Checkout not found."); return(RedirectToAction("Details", "Medical")); } _medicalCheckout.RequestDate = DateTime.Now; _medicalCheckout.IsCreatedByAdmin = false; _medicalCheckout.Status = "Pending"; Repo.UpdateMedicalCheckout(_medicalCheckout); TempData["Msg"] = AlertMessageProvider.SuccessMessage("You have applied for medical successfully."); } return(RedirectToAction("Details", "Medical")); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Medical", "ApplyMedical"))); } }
public ActionResult Update(FamilyMemberInfo familyMemberInfo) { try { int id; FamilyMemberInfo _familyMember = null; if (!int.TryParse(familyMemberInfo.Id.ToString(), out id)) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later."); return(RedirectToAction("Details", "Family")); } if (!ModelState.IsValid) { return(RedirectToAction("Details", "Family")); } if (familyMemberInfo.Relation != "Wife" && familyMemberInfo.Relation != "Son" && familyMemberInfo.Relation != "Daughter") { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later."); return(RedirectToAction("Details", "Family")); } using (FamilyMemberRepository Repo = new FamilyMemberRepository()) { _familyMember = Repo.GetFamilyMemberById(familyMemberInfo.Id); if (_familyMember == null || _familyMember.EmployeeInfoId != CurrentUser.EmployeeInfoId) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later."); return(RedirectToAction("Details", "Family")); } Repo.UpdateFamilyMember(familyMemberInfo); } TempData["Msg"] = AlertMessageProvider.SuccessMessage("Family member updated successfully."); return(RedirectToAction("Details", "Family")); } catch (Exception ex) { TempData["Msg"] = AlertMessageProvider.FailureMessage(ex.ToString()); return(View()); } }
public ActionResult DeleteDocument(string DocumentId = "") { try { int _id; DocumentInfo _document = null; if (!int.TryParse(DocumentId, out _id)) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Invalid document id, please provide valid document id."); return(RedirectToAction("Manage", "Profile")); } using (DocumentRepository Repo = new DocumentRepository()) { _document = Repo.GetDocumentById(_id); if (_document == null) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Document does not exist."); return(RedirectToAction("Manage", "Profile")); } string _docPath = Request.MapPath(_document.DocumentPath); if (System.IO.File.Exists(_docPath)) { System.IO.File.Delete(_docPath); Repo.DeleteDocument(_document.Id); } else { TempData["Msg"] = AlertMessageProvider.FailureMessage("Document does not exist."); return(RedirectToAction("Manage", "Profile", new { id = _document.EmployeeInfoId })); } } TempData["Msg"] = AlertMessageProvider.SuccessMessage("Document deleted successfully."); return(RedirectToAction("Manage", "Profile", new { id = _document.EmployeeInfoId })); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Profile", "DeleteDocument"))); } }
public ActionResult ChangePassword(ChangePasswordViewModel passwordInfo) { try { if (!ModelState.IsValid) { return(View()); } var _account = new AccountInfo(); using (AccountRepository Repo = new AccountRepository()) { _account = Repo.GetEmployeeAccountById(CurrentUser.AccountId); } string decryptedPassword = RijndaelCrypt.DecryptPassword(_account.PasswordHash, _account.Salt); if (decryptedPassword != passwordInfo.CurrentPassword) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Current password is invalid."); return(View()); } if (decryptedPassword == passwordInfo.NewPassword) { TempData["Msg"] = AlertMessageProvider.FailureMessage("New password should not be same as current password."); return(View()); } _account.Salt = RandomPassword.Generate(18, 20); _account.PasswordHash = RijndaelCrypt.EncryptPassword(passwordInfo.NewPassword, _account.Salt); using (AccountRepository Repo = new AccountRepository()) { Repo.ChangeNewPassword(_account); } TempData["Msg"] = AlertMessageProvider.SuccessMessage("Password changed successfully."); return(View()); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Auth", "ChangePassword"))); } }
public ActionResult DeletePrescription(string PrescriptionId) { try { int id; MedicalPrescriptionInfo _prescription = null; if (!int.TryParse(PrescriptionId, out id)) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later."); return(RedirectToAction("Details", "Medical")); } using (MedicalPrescriptionRepository Repo = new MedicalPrescriptionRepository()) { _prescription = Repo.GetMedicalPrescriptionById(id); if (_prescription == null || _prescription.EmployeeInfoId != CurrentUser.EmployeeInfoId || _prescription.CheckoutStatus == "Approved") { TempData["Msg"] = AlertMessageProvider.FailureMessage("Prescription not found."); return(RedirectToAction("Details", "Medical")); } string _prescriptionPath = Request.MapPath(_prescription.PrescriptionPath); if (System.IO.File.Exists(_prescriptionPath)) { System.IO.File.Delete(_prescriptionPath); Repo.DeleteMedicalPrescription(_prescription.Id); } else { TempData["Msg"] = AlertMessageProvider.FailureMessage("Prescription does not exist physically."); } } TempData["Msg"] = AlertMessageProvider.SuccessMessage("Prescription deleted successfully."); return(RedirectToAction("Apply", "Medical", new { id = _prescription.MedicalCheckoutId })); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Medical", "DeletePrescription"))); } }
public ActionResult DeletePayslip(string PayslipId = "") { try { int _id; PaySlipInfo _paySlip = null; string previousMonth = DateTime.Now.AddMonths(-1).ToString("MMMM - yyyy"); string currentMonth = DateTime.Now.ToString("MMMM - yyyy"); string nextMonth = DateTime.Now.AddMonths(1).ToString("MMMM - yyyy"); if (!int.TryParse(PayslipId, out _id)) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later."); return(RedirectToAction("Details", "Salary")); } using (PaySlipRepository Repo = new PaySlipRepository()) { _paySlip = Repo.GetPayslipById(_id); if (_paySlip == null) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Payslip does not exist."); return(RedirectToAction("Details", "Salary")); } if (_paySlip.SalaryDate.ToString("MMMM - yyyy") != previousMonth && _paySlip.SalaryDate.ToString("MMMM - yyyy") != currentMonth && _paySlip.SalaryDate.ToString("MMMM - yyyy") != nextMonth) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Selected payslip cannot be deleted."); return(RedirectToAction("Details", "Salary", new { id = _paySlip.EmployeeInfoId })); } Repo.DeletePayslip(_id); TempData["Msg"] = AlertMessageProvider.SuccessMessage("Payslip deleted successfully."); } return(RedirectToAction("Details", "Salary", new { id = _paySlip.EmployeeInfoId })); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Salary", "DeletePayslip"))); } }
public ActionResult Add(FamilyMemberInfo familyMemberInfo) { try { EmployeeInfo _employee = null; if (!ModelState.IsValid) { return(RedirectToAction("Manage", "Profile")); } if (familyMemberInfo.Relation != "Wife" && familyMemberInfo.Relation != "Son" && familyMemberInfo.Relation != "Daughter") { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later."); return(RedirectToAction("Manage", "Profile")); } familyMemberInfo.Name = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(familyMemberInfo.Name.ToLower()); using (EmployeeRepository Repo = new EmployeeRepository()) { _employee = Repo.GetEmployeeInfoById(familyMemberInfo.EmployeeInfoId); if (_employee == null) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later."); return(RedirectToAction("Manage", "Profile")); } } using (FamilyMemberRepository Repo = new FamilyMemberRepository()) { Repo.SaveFamilyMember(familyMemberInfo); } TempData["Msg"] = AlertMessageProvider.SuccessMessage("Family member added successfully."); return(RedirectToAction("Manage", "Profile", new { id = familyMemberInfo.EmployeeInfoId })); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Family", "Add"))); } }
public ActionResult Delete(int id) { try { AccountInfo _accountInfo = null; using (AccountRepository Repo = new AccountRepository()) { _accountInfo = Repo.GetEmployeeAccountById(id); if (_accountInfo == null) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong! please try again later."); return(RedirectToAction("Manage")); } if (_accountInfo.IsCheckListCompleted == true) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Unable to delete activated account."); return(RedirectToAction("Manage", "Account")); } var result = Repo.IsDeletedUnActivatedAccount(id); if (result == true) { TempData["Msg"] = AlertMessageProvider.SuccessMessage("Account has been deleted successfully."); } else { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong! please try again later."); } } return(RedirectToAction("Manage", "Account")); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Account", "Delete"))); } }
public ActionResult DeleteAllowance(int id) { try { using (MedicalAllowanceRepository Repo = new MedicalAllowanceRepository()) { Repo.DeleteMedicalAllowance(id); TempData["Msg"] = AlertMessageProvider.SuccessMessage("Allowance deleted successfully."); return(RedirectToAction("Allowance", "Medical")); } } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Medical", "DeleteAllowance"))); } }
public ActionResult CancelCheckout(string CheckoutId) { try { int id; MedicalCheckoutInfo _checkout = null; var _prescriptionsList = new List <MedicalPrescriptionInfo>(); if (!int.TryParse(CheckoutId, out id)) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later."); return(RedirectToAction("Details", "Medical")); } using (MedicalCheckoutRepository Repo = new MedicalCheckoutRepository()) { _checkout = Repo.GetMedicalCheckoutById(id); if (_checkout == null || _checkout.EmployeeInfoId != CurrentUser.EmployeeInfoId || _checkout.Status == "Approved") { TempData["Msg"] = AlertMessageProvider.FailureMessage("Checkout not found."); return(RedirectToAction("Details", "Medical")); } _checkout.Status = "Incomplete"; Repo.UpdateMedicalCheckout(_checkout); } TempData["Msg"] = AlertMessageProvider.SuccessMessage("Checkout canceled successfully."); return(RedirectToAction("Details", "Medical")); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Medical", "CancelCheckout"))); } }
public ActionResult Delete(string FamilyMemberId = "") { try { int id; FamilyMemberInfo _familyMember = null; if (!int.TryParse(FamilyMemberId, out id)) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later."); return(RedirectToAction("Details", "Family")); } using (FamilyMemberRepository Repo = new FamilyMemberRepository()) { _familyMember = Repo.GetFamilyMemberById(int.Parse(FamilyMemberId)); if (_familyMember == null || _familyMember.EmployeeInfoId != CurrentUser.EmployeeInfoId) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later."); return(RedirectToAction("Details", "Family")); } Repo.DeleteFamilyMember(int.Parse(FamilyMemberId)); } TempData["Msg"] = AlertMessageProvider.SuccessMessage("Family member deleted successfully."); return(RedirectToAction("Details", "Family")); } catch (Exception ex) { TempData["Msg"] = AlertMessageProvider.FailureMessage(ex.ToString()); return(View()); } }
public ActionResult Update(LeaveRequestInfo leaveRequestInfo) { try { leaveRequestInfo.RequestProcessDate = DateTime.Now; leaveRequestInfo.RequestProcessByAccountId = CurrentUser.AccountId; using (LeaveRequestRepository Repo = new LeaveRequestRepository()) { Repo.UpdateLeaveRequest(leaveRequestInfo); } TempData["Msg"] = AlertMessageProvider.SuccessMessage("Leave(s) updated successfully."); return(RedirectToAction("Manage", "Leave", new { id = leaveRequestInfo.EmployeeInfoId })); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Leave", "Update"))); } }
public ActionResult Create(AnnouncementInfo announcementInfo) { try { announcementInfo.CreatedByAccountId = CurrentUser.AccountId; announcementInfo.CreatedOn = DateTime.Now; using (AnnouncementRepository Repo = new AnnouncementRepository()) { Repo.SaveAnnouncement(announcementInfo); } TempData["Msg"] = AlertMessageProvider.SuccessMessage("Announcement created successfully."); return(RedirectToAction("Manage", "Announcement")); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Announcement", "Create"))); } }
public ActionResult Delete(string FamilyMemberId = "") { try { int id; FamilyMemberInfo _familyMember = null; if (!int.TryParse(FamilyMemberId, out id)) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later."); return(RedirectToAction("Manage", "Profile")); } using (FamilyMemberRepository Repo = new FamilyMemberRepository()) { _familyMember = Repo.GetFamilyMemberById(int.Parse(FamilyMemberId)); if (_familyMember == null) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later."); return(RedirectToAction("Manage", "Profile")); } Repo.DeleteFamilyMember(int.Parse(FamilyMemberId)); } TempData["Msg"] = AlertMessageProvider.SuccessMessage("Family member deleted successfully."); return(RedirectToAction("Manage", "Profile", new { id = _familyMember.EmployeeInfoId })); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Family", "Delete"))); } }
public ActionResult Delete(string id = "") { try { int _id; AnnouncementInfo _announcement = null; if (!int.TryParse(id, out _id)) { return(RedirectToAction("Manage", "Announcement")); } using (AnnouncementRepository Repo = new AnnouncementRepository()) { _announcement = Repo.GetAnnouncementById(_id); } if (_announcement == null) { return(RedirectToAction("Manage", "Announcement")); } using (AnnouncementRepository Repo = new AnnouncementRepository()) { Repo.DeleteAnnouncement(_id); } TempData["Msg"] = AlertMessageProvider.SuccessMessage("Announcement deleted successfully."); return(RedirectToAction("Manage", "Announcement")); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Announcement", "Delete"))); } }
public ActionResult Add(FamilyMemberInfo familyMemberInfo) { try { if (!ModelState.IsValid) { return(RedirectToAction("Details", "Family")); } if (familyMemberInfo.Relation != "Wife" && familyMemberInfo.Relation != "Son" && familyMemberInfo.Relation != "Daughter") { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later."); return(RedirectToAction("Details", "Family")); } familyMemberInfo.EmployeeInfoId = CurrentUser.EmployeeInfoId; familyMemberInfo.Name = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(familyMemberInfo.Name.ToLower()); using (FamilyMemberRepository Repo = new FamilyMemberRepository()) { Repo.SaveFamilyMember(familyMemberInfo); } TempData["Msg"] = AlertMessageProvider.SuccessMessage("Family member added successfully."); return(RedirectToAction("Details", "Family")); } catch (Exception ex) { TempData["Msg"] = AlertMessageProvider.FailureMessage(ex.ToString()); return(View()); } }
public ActionResult UploadPhotos(IEnumerable <HttpPostedFileBase> files, AlbumInfo albumInfo) { try { int _albumId; int count = 0; var photoInfo = new PhotoInfo(); AlbumInfo _albumInfo = null; if (!int.TryParse(albumInfo.Id.ToString(), out _albumId)) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later."); return(RedirectToAction("Manage", "Gallery")); } using (AlbumRepository Repo = new AlbumRepository()) { _albumInfo = Repo.GetAlbumById(_albumId); } if (_albumInfo == null) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Album not found."); return(RedirectToAction("Manage", "Gallery")); } photoInfo.UploadOn = DateTime.Now; photoInfo.UploadByAccountId = CurrentUser.AccountId; photoInfo.AlbumId = albumInfo.Id; if (files != null) { foreach (var file in files) { if (file.ContentType.Contains("image")) { if (file.ContentLength < 2 * 1024 * 1024) { if (file.FileName.Contains(".jpeg") || file.FileName.Contains(".jpg")) { photoInfo.Name = file.FileName; string _dirPath = Server.MapPath(Url.Content("~/Content/Album_photos")); bool _isDirectoryExists = System.IO.Directory.Exists(_dirPath); if (!_isDirectoryExists) { System.IO.Directory.CreateDirectory(Server.MapPath(Url.Content("~/Content/Album_photos"))); } photoInfo.Path = Url.Content("~/Content/Album_photos/" + Guid.NewGuid() + "_" + file.FileName); string imgPath = Server.MapPath(photoInfo.Path); file.SaveAs(imgPath); using (PhotoRepository Repo = new PhotoRepository()) { Repo.SavePhoto(photoInfo); } count++; } else { TempData["Msg"] = AlertMessageProvider.FailureMessage("Please select jpeg, jpg format only."); return(RedirectToAction("UploadPhotos", "Gallery", new { id = albumInfo.Id })); } } else { TempData["Msg"] = AlertMessageProvider.FailureMessage("Please select size upto 2 MB or smaller."); return(RedirectToAction("UploadPhotos", "Gallery", new { id = albumInfo.Id })); } } else { TempData["Msg"] = AlertMessageProvider.FailureMessage("Invalid content type, please select image only."); return(RedirectToAction("UploadPhotos", "Gallery", new { id = albumInfo.Id })); } } } else { TempData["Msg"] = AlertMessageProvider.FailureMessage("Please select photo(s)."); return(RedirectToAction("UploadPhotos", "Admin", new { id = albumInfo.Id })); } TempData["Msg"] = AlertMessageProvider.SuccessMessage(count + " Photos uploaded successfully."); return(RedirectToAction("UploadPhotos", "Gallery", new { id = albumInfo.Id })); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Gallery", "UploadPhotos"))); } }
public ActionResult ProcessRequest(string CheckoutId = "", string ProcessBtn = "") { try { int _id; MedicalCheckoutInfo _checkout = null; EmployeeInfo _employeeInfo = null; MedicalAllowanceInfo _medicalAllowance = null; if (!int.TryParse(CheckoutId, out _id)) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later."); return(RedirectToAction("Requests", "Medical")); } using (MedicalCheckoutRepository CheckoutRepo = new MedicalCheckoutRepository()) { _checkout = CheckoutRepo.GetMedicalCheckoutById(_id); if (_checkout == null) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Checkout not found."); return(RedirectToAction("Requests", "Medical")); } if (ProcessBtn != "Approve" && ProcessBtn != "Reject") { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later."); return(RedirectToAction("RequestDetails", "Medical", new { id = _checkout.Id })); } if (ProcessBtn == "Approve") { using (EmployeeRepository EmployeeRepo = new EmployeeRepository()) { _employeeInfo = EmployeeRepo.GetEmployeeInfoById(_checkout.EmployeeInfoId); } using (MedicalAllowanceRepository AllowanceRepo = new MedicalAllowanceRepository()) { if (_employeeInfo.MaritalStatus == "Single") { _medicalAllowance = AllowanceRepo.GetMedicalAllowanceByCategory("Single"); } else { _medicalAllowance = AllowanceRepo.GetMedicalAllowanceByCategory("Married"); } } var _availedMedical = CheckoutRepo.GetAvailedMedicalCheckoutsListByEmployeeIdYearwise(_checkout.EmployeeInfoId, DateTime.Now.ToString("yyyy")); var remainingMedicalAmount = _medicalAllowance.Amount - _availedMedical.Sum(x => x.Amount); if (_checkout.Amount > remainingMedicalAmount) { TempData["Msg"] = AlertMessageProvider.FailureMessage("This request cannot be process, employee has insufficient medical amount."); return(RedirectToAction("RequestDetails", "Medical", new { id = _checkout.EmployeeInfoId })); } _checkout.Status = "Approved"; TempData["Msg"] = AlertMessageProvider.SuccessMessage("Medical request approved successfully."); } else { _checkout.Status = "Incomplete"; TempData["Msg"] = AlertMessageProvider.SuccessMessage("Medical request rejected successfully."); } CheckoutRepo.UpdateMedicalCheckout(_checkout); } return(RedirectToAction("RequestDetails", "Medical", new { id = _checkout.EmployeeInfoId })); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Medical", "ProcessRequest"))); } }
public ActionResult Update(HttpPostedFileBase file, EmployeeInfo employeeInfo) { try { if (!ModelState.IsValid) { return(View()); } int empId; EmployeeInfo _employee = null; if (!int.TryParse(employeeInfo.Id.ToString(), out empId)) { return(RedirectToAction("Manage", "Profile")); } using (EmployeeRepository Repo = new EmployeeRepository()) { _employee = Repo.GetEmployeeInfoById(empId); } if (_employee == null) { return(RedirectToAction("Manage", "Profile")); } if (_employee.RoleName == "SuperAdmin") { return(RedirectToAction("Manage", "Profile")); } bool isImgSelected = false; if (file != null) { if (file.ContentType.Contains("image")) { if (file.ContentLength < 2 * 1024 * 1024) { if (file.FileName.Contains(".jpg")) { isImgSelected = true; } else { TempData["Msg"] = AlertMessageProvider.FailureMessage("Please select 'jpg' format only."); return(View()); } } else { TempData["Msg"] = AlertMessageProvider.FailureMessage("Please select size upto 2 MB or smaller."); return(View()); } } else { TempData["Msg"] = AlertMessageProvider.FailureMessage("Invalid content type, please select image only."); return(View()); } } employeeInfo.ModifiedDate = DateTime.Now; employeeInfo.ModifiedByAccountId = CurrentUser.AccountId; using (EmployeeRepository Repo = new EmployeeRepository()) { Repo.UpdateEmployeeInfo(employeeInfo); TempData["Msg"] = AlertMessageProvider.SuccessMessage("Employee info updated successfully."); } if (isImgSelected == true) { string imgPath = Server.MapPath(Url.Content("~/Content/Employee_pictures/" + employeeInfo.AccountId + ".jpg")); file.SaveAs(imgPath); } return(RedirectToAction("Manage", "Profile", new { id = employeeInfo.Id })); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Profile", "Update"))); } }
public ActionResult Add(LeaveRequestInfo leaveRequestInfo, string LeaveDate = "") { try { string[] _dateRange = LeaveDate.Split(new string[] { " - " }, StringSplitOptions.None); DateTime _leaveStartDate; DateTime _leaveEndDate; if (!DateTime.TryParse(_dateRange[0], out _leaveStartDate) || !DateTime.TryParse(_dateRange[1], out _leaveEndDate)) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Invalid leave date, please select valid date."); return(RedirectToAction("Add", "Leave", new { id = leaveRequestInfo.EmployeeInfoId })); } if (leaveRequestInfo.LeaveType != "Annual" && leaveRequestInfo.LeaveType != "Casual") { TempData["Msg"] = AlertMessageProvider.FailureMessage("Invalid leave type, please select valid leave type."); return(RedirectToAction("Add", "Leave", new { id = leaveRequestInfo.EmployeeInfoId })); } //if (_leaveStartDate.Date < DateTime.Now.Date) //{ // TempData["Msg"] = AlertMessageProvider.FailureMessage("Start date cannot be later than today."); // return RedirectToAction("Add", "Leave", new { id = leaveRequestInfo.EmployeeInfoId }); //} if (_leaveEndDate.Date < _leaveStartDate.Date) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Start date cannot be later than end date."); return(RedirectToAction("Add", "Leave", new { id = leaveRequestInfo.EmployeeInfoId })); } int _totalSelectedLeaves = LeavesCounter.CountLeavesWithoutWeekend(_leaveStartDate, _leaveEndDate); if (_totalSelectedLeaves == 0) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Leave cannot add to saturday and sunday."); return(RedirectToAction("Add", "Leave", new { id = leaveRequestInfo.EmployeeInfoId })); } leaveRequestInfo.RequestDate = DateTime.Now; leaveRequestInfo.StartDate = _leaveStartDate; leaveRequestInfo.EndDate = _leaveEndDate; leaveRequestInfo.Reason = "N/A"; leaveRequestInfo.Status = "Approved"; leaveRequestInfo.IsCreatedByAdmin = true; leaveRequestInfo.RequestProcessDate = DateTime.Now; leaveRequestInfo.RequestProcessByAccountId = CurrentUser.AccountId; using (LeaveRequestRepository Repo = new LeaveRequestRepository()) { Repo.SaveLeaveRequest(leaveRequestInfo); } TempData["Msg"] = AlertMessageProvider.SuccessMessage("Leave(s) add successfully."); return(RedirectToAction("Manage", "Leave", new { id = leaveRequestInfo.EmployeeInfoId })); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Leave", "Add"))); } }
public ActionResult UploadDocuments(HttpPostedFileBase file, EmployeeInfo employeeInfo, string EmployeeId = "") { try { int _id; var _document = new DocumentInfo(); EmployeeInfo _employee = null; if (!int.TryParse(EmployeeId, out _id)) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later."); return(RedirectToAction("Manage", "Profile")); } using (EmployeeRepository Repo = new EmployeeRepository()) { _employee = Repo.GetEmployeeInfoById(_id); } if (_employee == null) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Employee does not exist."); return(RedirectToAction("Manage", "Profile")); } if (string.IsNullOrEmpty(employeeInfo.DocumentName)) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Document name is required."); return(RedirectToAction("Manage", "Profile")); } if (file != null) { if (file.ContentType.Contains("image") || file.ContentType.Contains("application/pdf")) { if (file.ContentLength < 2 * 1024 * 1024) { if (file.FileName.Contains(".jpeg") || file.FileName.Contains(".jpg") || file.FileName.Contains(".pdf") || file.FileName.Contains("*.pdf")) { _document.FileName = employeeInfo.DocumentName + Path.GetExtension(file.FileName);; _document.UploadDate = DateTime.Now; _document.DocumentType = "Other"; _document.EmployeeInfoId = _id; string _dirPath = Server.MapPath(Url.Content("~/Content/Employee_documents")); bool _isDirectoryExists = System.IO.Directory.Exists(_dirPath); if (!_isDirectoryExists) { System.IO.Directory.CreateDirectory(Server.MapPath(Url.Content("~/Content/Employee_documents"))); } Guid guid = Guid.NewGuid(); _document.DocumentPath = Url.Content("~/Content/Employee_documents/" + _document.EmployeeInfoId + "-" + guid + "-" + _document.FileName); string _docPath = Server.MapPath(_document.DocumentPath); file.SaveAs(_docPath); using (DocumentRepository Repo = new DocumentRepository()) { Repo.SaveDocument(_document); } } else { TempData["Msg"] = AlertMessageProvider.FailureMessage("Please select jpeg, jpg, pdf format only."); return(RedirectToAction("Manage", "Profile", new { id = _id })); } } else { TempData["Msg"] = AlertMessageProvider.FailureMessage("Please select size upto 2 MB or smaller."); return(RedirectToAction("Manage", "Profile", new { id = _id })); } } else { TempData["Msg"] = AlertMessageProvider.FailureMessage("Invalid content type, please select image and pdf only."); return(RedirectToAction("Manage", "Profile", new { id = _id })); } } else { TempData["Msg"] = AlertMessageProvider.FailureMessage("Please select document."); return(RedirectToAction("Manage", "Profile", new { id = _id })); } TempData["Msg"] = AlertMessageProvider.SuccessMessage("Document uploaded successfully."); return(RedirectToAction("Manage", "Profile", new { id = _id })); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Profile", "UploadDocuments"))); } }
public ActionResult Reset(LeaveAllowedInfo leaveAllowedInfo) { try { //if (CurrentUser.Role != "SuperAdmin") //{ // TempData["Msg"] = AlertMessageProvider.FailureMessage("You don't have permission to access this feature."); // return RedirectToAction("Manage", "Leave"); //} if (!ModelState.IsValid) { return(View()); //return RedirectToAction("Reset", "Leave", new { id = leaveAllowedInfo.EmployeeInfoId }); } LeaveAllowedInfo leavesAllowed = null; using (LeaveAllowedRepository Repo = new LeaveAllowedRepository()) { leavesAllowed = Repo.GetLeaveAllowedByEmployeeId(leaveAllowedInfo.EmployeeInfoId); if (leavesAllowed == null) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later."); return(RedirectToAction("Manage", "Leave")); } if (leaveAllowedInfo.Casual > 5) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Maximum 15 casual leaves allowed."); return(RedirectToAction("Reset", "Leave", new { id = leaveAllowedInfo.EmployeeInfoId })); } if (leaveAllowedInfo.Annual > 15) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Maximum 30 annual leaves allowed."); return(RedirectToAction("Reset", "Leave", new { id = leaveAllowedInfo.EmployeeInfoId })); } leaveAllowedInfo.Id = leavesAllowed.Id; leaveAllowedInfo.ModifiedDate = DateTime.Now; leaveAllowedInfo.ModifiedByAccountId = CurrentUser.AccountId; Repo.UpdateLeaveAllowed(leaveAllowedInfo); } TempData["Msg"] = AlertMessageProvider.SuccessMessage("Leave(s) has been reset successfully."); return(RedirectToAction("Manage", "Leave", new { id = leaveAllowedInfo.EmployeeInfoId })); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Leave", "Update"))); } }
public ActionResult Create(AccountInfo accountInfo) { try { if (ModelState.IsValid) { var _employeeInfo = new Model.EmployeeInfo(); _employeeInfo.CreatedByAccountId = CurrentUser.AccountId; _employeeInfo.CreatedDate = DateTime.Now; int employeeInfoId; int accountId; string saltValue = RandomPassword.Generate(18, 20); string password = RijndaelCrypt.EncryptPassword(RandomPassword.Generate(), saltValue); accountInfo.CompanyEmail = accountInfo.CompanyEmail.ToLower(); accountInfo.PasswordHash = password; accountInfo.Salt = saltValue; accountInfo.LastLoginDate = DateTime.Now; accountInfo.LastLoginIp = ""; accountInfo.IsActive = true; accountInfo.IsFirstTimeLogin = true; using (var transaction = new System.Transactions.TransactionScope()) { using (AccountRepository Repo = new AccountRepository()) { if (Repo.IsEmailExist(accountInfo.CompanyEmail) == true) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Email already exist."); return(View()); } int roleId = Repo.GetRoleIdByName("Anonymous"); accountInfo.RoleId = roleId; accountId = Repo.CreateAccount(accountInfo); } using (AccountCheckListRepository Repo = new AccountCheckListRepository()) { var _accountCheckList = new AccountCheckListInfo(accountId); Repo.SaveAccountCheckList(_accountCheckList); } using (EmployeeRepository Repo = new EmployeeRepository()) { _employeeInfo.AccountId = accountId; employeeInfoId = Repo.SaveEmployeeInfo(_employeeInfo); } using (LeaveAllowedRepository Repo = new LeaveAllowedRepository()) { LeaveAllowedInfo _leaveAllowed = new LeaveAllowedInfo(0, 0, employeeInfoId, CurrentUser.AccountId); Repo.SaveLeaveAllowed(_leaveAllowed); } using (SalaryRepository Repo = new SalaryRepository()) { var _salaryInfo = new SalaryInfo(CurrentUser.AccountId, employeeInfoId); Repo.SaveSalary(_salaryInfo); } using (FamilyMemberRepository Repo = new FamilyMemberRepository()) { var _familyMember = new FamilyMemberInfo { Name = "Self", Relation = "Selef", EmployeeInfoId = employeeInfoId }; Repo.SaveFamilyMember(_familyMember); } transaction.Complete(); } List <string> To = new List <string>() { accountInfo.CompanyEmail }; string Subject = "LPS Online Account Information"; var LoginUrl = Url.Action("Login", "Auth", new { Area = "" }, protocol: Request.Url.Scheme); string Body = "Dear Employee, <br/><br/>" + "Your account has been created.<br/>" + "Please ensure to save the username and password written below:<br/><br/>" + "Username: <b>" + accountInfo.CompanyEmail + "</b><br/>" + "Password: <b>" + RijndaelCrypt.DecryptPassword(accountInfo.PasswordHash, accountInfo.Salt) + "</b><br/><br/>" + "<a href='" + LoginUrl + "' target='_blank'>" + LoginUrl + "</a><br/>" + "You can login to your account to use LPS online services.<br/><br/>" + "Thanks,<br/>" + "<b>Logic Powered Solutions</b>"; bool result = EmailSender.Send(Subject, Body, To); if (result) { TempData["Msg"] = AlertMessageProvider.SuccessMessage("Account created, email has been sent to employee successfully."); } else { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong! email not sent, please try again later."); } return(RedirectToAction("Manage", "Account")); } return(View()); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Account", "Create"))); } }
public ActionResult UpdateMyInfo(HttpPostedFileBase file, AdminInfoViewModel _adminInfoModel) { try { if (!ModelState.IsValid) { return(View()); } if (CurrentUser.Role != "SuperAdmin") { return(RedirectToAction("Dashboard", "Home")); } bool isImgSelected = false; if (file != null) { if (file.ContentType.Contains("image")) { if (file.ContentLength < 2 * 1024 * 1024) { if (file.FileName.Contains(".jpeg") || file.FileName.Contains(".jpg")) { isImgSelected = true; } else { TempData["Msg"] = AlertMessageProvider.FailureMessage("Please select jpeg, jpg format only."); return(View()); } } else { TempData["Msg"] = AlertMessageProvider.FailureMessage("Please select size upto 2 MB or smaller."); return(View()); } } else { TempData["Msg"] = AlertMessageProvider.FailureMessage("Invalid content type, please select image only."); return(View()); } } _adminInfoModel.EmployeeInfoId = CurrentUser.EmployeeInfoId; _adminInfoModel.ModifiedDate = DateTime.Now; _adminInfoModel.ModifiedByAccountId = CurrentUser.AccountId; using (EmployeeRepository Repo = new EmployeeRepository()) { Repo.UpdateAdminIfo(_adminInfoModel); TempData["Msg"] = AlertMessageProvider.SuccessMessage("Information updated successfully."); } if (isImgSelected == true) { string imgPath = Server.MapPath(Url.Content("~/Content/Employee_pictures/" + CurrentUser.AccountId + ".jpg")); file.SaveAs(imgPath); } return(RedirectToAction("UpdateMyInfo", "Profile")); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Profile", "UpdateMyInfo"))); } }
public ActionResult RequestDetails(LeaveRequestInfo leaveRequestInfo, string ProceedBtn = "") { try { if (!ModelState.IsValid) { return(RedirectToAction("RequestDetails", "Leave", new { id = leaveRequestInfo.Id })); } using (LeaveRequestRepository Repo = new LeaveRequestRepository()) { LeaveRequestInfo leaveRequest = null; leaveRequest = Repo.GetLeaveRequestById(leaveRequestInfo.Id); if (leaveRequest == null) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong! please try again later."); return(RedirectToAction("Requests", "Leave")); } leaveRequest.Remark = leaveRequestInfo.Remark; leaveRequest.RequestProcessByAccountId = CurrentUser.AccountId; leaveRequest.RequestProcessDate = DateTime.Now; bool isApproved = false; if (ProceedBtn == "Approve") { leaveRequest.Status = "Approved"; Repo.ApproveLeaveRequest(leaveRequest); isApproved = true; } else if (ProceedBtn == "Reject") { leaveRequest.Status = "Disapproved"; Repo.DeleteLeaveRequest(leaveRequest.Id); } else { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong! please try again later."); return(RedirectToAction("RequestDetails", "Leave", new { id = leaveRequest.Id })); } string Subject = "Leave(s) Request Response"; string Body = "<b>Status: </b>" + leaveRequest.Status + ".<br/><br/>" + "<b>Remark: </b>" + leaveRequest.Remark + ".<br/><br/>" + "Thanks.<br/>"; var To = new List <string>() { leaveRequest.EmployeeCompanyEmail }; var status = EmailSender.Send(Subject, Body, To); if (isApproved == true) { TempData["Msg"] = AlertMessageProvider.SuccessMessage("Leave request approved successfully."); } else { TempData["Msg"] = AlertMessageProvider.SuccessMessage("Leave request rejected successfully."); } return(RedirectToAction("Requests", "Leave")); } } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Leave", "RequestDetails"))); } }
public ActionResult DeleteAlbum(string AlbumId = "") { try { var _photos = new List <PhotoInfo>(); int _albumId; AlbumInfo _albumInfo = null; if (!int.TryParse(AlbumId, out _albumId)) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later."); return(RedirectToAction("Manage", "Gallery")); } using (var transaction = new System.Transactions.TransactionScope()) { using (AlbumRepository AlbumRepo = new AlbumRepository()) { _albumInfo = AlbumRepo.GetAlbumById(_albumId); if (_albumInfo == null) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later."); return(RedirectToAction("Manage", "Gallery")); } using (PhotoRepository PhotoRepo = new PhotoRepository()) { _photos = PhotoRepo.GetPhotoListByAlbumId(_albumId); foreach (var item in _photos) { string fullPath = Request.MapPath(item.Path); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } PhotoRepo.DeletePhoto(item.Id); } } string _imgPath = Server.MapPath(_albumInfo.CoverPhotoPath); if (!_imgPath.Contains("default-album-cover.jpg")) { if (System.IO.File.Exists(_imgPath)) { System.IO.File.Delete(_imgPath); } } AlbumRepo.DeleteAlbum(_albumId); } transaction.Complete(); } TempData["Msg"] = AlertMessageProvider.SuccessMessage("Album deleted successfully."); return(RedirectToAction("Manage", "Gallery")); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Gallery", "DeleteAlbum"))); } }
public ActionResult ApplyLeaves(LeaveRequestInfo leaveRequestInfo) { try { if (leaveRequestInfo.LeaveType != "Casual" && leaveRequestInfo.LeaveType != "Annual" || string.IsNullOrEmpty(leaveRequestInfo.LeaveDate)) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later."); return(RedirectToAction("Status", "Leave")); } string[] _dateRange = leaveRequestInfo.LeaveDate.Split(new string[] { " - " }, StringSplitOptions.None); DateTime _leaveStartDate; DateTime _leaveEndDate; var _leaveAllowed = new LeaveAllowedInfo(); if (!DateTime.TryParse(_dateRange[0], out _leaveStartDate) || !DateTime.TryParse(_dateRange[1], out _leaveEndDate)) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Invalid leave date, please select valid date."); return(RedirectToAction("Details", "Leave")); } _leaveStartDate = DateTime.Parse(_dateRange[0]); _leaveEndDate = DateTime.Parse(_dateRange[1]); int _totalSelectedLeaves = LeavesCounter.CountLeavesWithoutWeekend(_leaveStartDate, _leaveEndDate); //(_leaveStartDate - _leaveEndDate).Days + 1; if (_leaveStartDate.Date < DateTime.Now.Date) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Start date cannot be later than today."); return(RedirectToAction("Details", "Leave")); } int _monthsDiff = ((_leaveStartDate.Year - DateTime.Now.Year) * 12) + _leaveStartDate.Month - DateTime.Now.Month; if (_monthsDiff > 1) { TempData["Msg"] = AlertMessageProvider.FailureMessage("You cannot apply for leaves earlier than 1 month."); return(RedirectToAction("Details", "Leave")); } if (_leaveEndDate.Date < _leaveStartDate.Date) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Start date cannot be later than end date."); return(RedirectToAction("Details", "Leave")); } if (_totalSelectedLeaves == 0) { TempData["Msg"] = AlertMessageProvider.FailureMessage("You can't apply for saturday and sunday."); return(RedirectToAction("Details", "Leave")); } using (LeaveAllowedRepository Repo = new LeaveAllowedRepository()) { _leaveAllowed = Repo.GetLeaveAllowedByEmployeeId(CurrentUser.EmployeeInfoId); } using (LeaveRequestRepository Repo = new LeaveRequestRepository()) { LeaveRequestInfo _leaveRequest = null; _leaveRequest = Repo.GetLeaveRequestLastRecordByEmployeeId(CurrentUser.EmployeeInfoId); if (_leaveRequest != null) { if (_leaveRequest.EndDate.Date == _leaveStartDate.Date) { TempData["Msg"] = AlertMessageProvider.FailureMessage("You have already a leave today."); return(RedirectToAction("Details", "Leave")); } if (_leaveRequest.Status == "Pending" || _leaveRequest.Status == "Approved" && _leaveRequest.EndDate.Date > DateTime.Now.Date) { TempData["Msg"] = AlertMessageProvider.FailureMessage("You have already applied for leaves."); return(RedirectToAction("Details", "Leave")); } } if (leaveRequestInfo.LeaveType == "Casual") { var _leavesList = Repo.GetCasualLeaveRequestListByEmployeeId(CurrentUser.EmployeeInfoId); int _totalAvailedCasualLeaves = LeavesCounter.GetRemainingLeaves(_leavesList, _leaveAllowed.Casual); if (_totalSelectedLeaves > _totalAvailedCasualLeaves) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Please select upto remaining casual leaves."); return(RedirectToAction("Details", "Leave")); } } else if (leaveRequestInfo.LeaveType == "Annual") { var _leavesList = Repo.GetAnnualLeaveRequestListByEmployeeId(CurrentUser.EmployeeInfoId); int _totalAvailedAnnualLeaves = LeavesCounter.GetRemainingLeaves(_leavesList, _leaveAllowed.Annual); if (_totalSelectedLeaves > _totalAvailedAnnualLeaves) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Please select upto remaining annual leaves."); return(RedirectToAction("Details", "Leave")); } } } leaveRequestInfo.RequestDate = DateTime.Now; leaveRequestInfo.StartDate = _leaveStartDate; leaveRequestInfo.EndDate = _leaveEndDate; leaveRequestInfo.Status = "Pending"; leaveRequestInfo.Remark = ""; leaveRequestInfo.IsCreatedByAdmin = false; leaveRequestInfo.EmployeeInfoId = CurrentUser.EmployeeInfoId; string Subject = "Leave(s) Request"; string Body = "<b>Employee: </b>" + CurrentUser.Name + ".<br/>" + "<b>Total Leaves: </b>" + _totalSelectedLeaves + ".<br/>" + "<b>Leave Date: </b>" + leaveRequestInfo.LeaveDate + ".<br/><br/>" + "<b>Leave Reason: </b><br/>" + leaveRequestInfo.Reason + "<br/><br/>" + "Thanks.<br/>"; var status = EmailSender.Send(Subject, Body); if (status) { using (LeaveRequestRepository Repo = new LeaveRequestRepository()) { Repo.SaveLeaveRequest(leaveRequestInfo); } TempData["Msg"] = AlertMessageProvider.SuccessMessage("You have applied for leaves successfully, please wait for approval."); } else { TempData["Msg"] = AlertMessageProvider.FailureMessage("Email sending failed! please try again later."); } return(RedirectToAction("Details", "Leave")); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Leave", "ApplyLeaves"))); } }