コード例 #1
0
ファイル: LeaveController.cs プロジェクト: iorilan/Samples
        public ActionResult Reject(int ID)
        {
            ViewBag.Title = "Leave Reject";
            var  model     = new List <LeaveApplicationObj>();
            bool isSuccess = false;

            try
            {
                var result = LeaveService.Instance.RejectLeaveApplication(ID);
                if (result.IsSuccess)
                {
                    isSuccess = true;
                    ViewBag.IsShowSuccessfullMessage = true;
                    ViewBag.Message = string.Format("Leave application {0} to {1} has been rejected.",
                                                    result.Data.StartDate.ToString("yyyy-MM-dd"),
                                                    result.Data.EndDate.ToString("yyyy-MM-dd"));

                    var leaveRecord = LeaveService.Instance.GetLeaveApplication(ID);
                    if (leaveRecord.IsSuccess)
                    {
                        var broadCastRecord = BroadcastService.Instance.GetBusCaptainGCMID(leaveRecord.Data.PersonnelNumber);
                        var err             = GoogleNotification.CallGoogleAPI(broadCastRecord.Data.GcmID, "Leave Rejected", ViewBag.Message);
                        if (err != "")
                        {
                            _log.ErrorFormat("error while doing google notification on leave reject");
                        }
                    }
                    else
                    {
                        ViewBag.IsShowSuccessfullMessage = true;
                        ViewBag.Message = leaveRecord.ErrorInfo;
                    }
                }
                else
                {
                    ViewBag.IsShowSuccessfullMessage = true;
                    ViewBag.Message = result.ErrorInfo;
                }
            }
            catch (Exception ex)
            {
                ViewBag.IsShowErrorMessage = true;
                ViewBag.Message            = this.CleanJavaScriptString(ex.ToString());
                _log.Error(ex);
            }

            BusCaptainService.Instance.saveActivity(Activities.LeaveReject.ToString(), User.Identity.Name,
                                                    "", "", isSuccess, ID);

            return(View("Index", model));
        }
コード例 #2
0
ファイル: LeaveController.cs プロジェクト: iorilan/Samples
        public ActionResult Approve(int ID)
        {
            var actionCodes = RoleModuleMappingService.Instance.GetActionCodesOfModule(User.Identity.Name,
                                                                                       ModuleRoleConstants.Module_LeaveRequest);
            var hasViewAccess   = actionCodes.Data.Contains(ModuleRoleConstants.ActionView);
            var hasUpdateAccess = actionCodes.Data.Contains(ModuleRoleConstants.ActionUpdate);

            if (!hasViewAccess || !hasUpdateAccess)
            {
                this.ShowMessage(false, "", ModuleRoleConstants.NoAccessErrorMsg);
                return(View("Index"));
            }



            ViewBag.Title = "Leave Approval";
            var  model     = new List <LeaveApplicationObj>();
            bool isSuccess = false;

            try
            {
                var result = LeaveService.Instance.ApproveLeaveApplication(ID);
                if (result.IsSuccess)
                {
                    isSuccess = true;
                    ViewBag.IsShowSuccessfullMessage = true;
                    ViewBag.Message = string.Format("Leave application {0} to {1} has been approved.",
                                                    result.Data.StartDate.ToString("yyyy-MM-dd"),
                                                    result.Data.EndDate.ToString("yyyy-MM-dd"));

                    var leaveRecord = LeaveService.Instance.GetLeaveApplication(ID);
                    if (leaveRecord.IsSuccess)
                    {
                        var broadCastRecord = BroadcastService.Instance.GetBusCaptainGCMID(leaveRecord.Data.PersonnelNumber);

                        var err = GoogleNotification.CallGoogleAPI(broadCastRecord.Data.GcmID, "Leave Approval",
                                                                   ViewBag.Message);

                        var  broadcast = new BroadcastController();
                        bool apnsErr   = AppleNotification.Push(broadCastRecord.Data.GcmID, ViewBag.Message);

                        if (err != "")
                        {
                            _log.ErrorFormat("error while doing google notification on leave approval");
                        }
                    }
                    else
                    {
                        ViewBag.IsShowErrorMessage = true;
                        ViewBag.Message            = leaveRecord.ErrorInfo;
                    }
                }
                else
                {
                    ViewBag.IsShowErrorMessage = true;
                    ViewBag.Message            = result.ErrorInfo;
                }
            }
            catch (Exception ex)
            {
                ViewBag.IsShowErrorMessage = true;
                ViewBag.Message            = this.CleanJavaScriptString(ex.ToString());
                _log.Error(ex);
            }

            BusCaptainService.Instance.saveActivity(Activities.LeaveApprove.ToString(), User.Identity.Name,
                                                    "", "", isSuccess, ID);

            return(View("Index", model));
        }