Esempio n. 1
0
        public SettingRegRespObj ApproveStaffMemo(ApprovaStaffMemoObj regObj)
        {
            var response = new SettingRegRespObj
            {
                Status = new APIResponseStatus
                {
                    IsSuccessful = false,
                    Message      = new APIResponseMessage()
                }
            };

            try
            {
                if (regObj.Equals(null))
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Unable to proceed with your request";
                    response.Status.Message.TechnicalMessage = "Registration Object is empty / invalid";
                    return(response);
                }

                if (!EntityValidatorHelper.Validate(regObj, out var valResults))
                {
                    var errorDetail = new StringBuilder();
                    if (!valResults.IsNullOrEmpty())
                    {
                        errorDetail.AppendLine("Following error occurred:");
                        valResults.ForEachx(m => errorDetail.AppendLine(m.ErrorMessage));
                    }

                    else
                    {
                        errorDetail.AppendLine(
                            "Validation error occurred! Please check all supplied parameters and try again");
                    }
                    response.Status.Message.FriendlyMessage  = errorDetail.ToString();
                    response.Status.Message.TechnicalMessage = errorDetail.ToString();
                    response.Status.IsSuccessful             = false;
                    return(response);
                }


                if (!HelperMethods.IsUserValid(regObj.AdminUserId, regObj.SysPathCode,
                                               HelperMethods.getAdminRoles(), ref response.Status.Message))
                {
                    return(response);
                }


                //var searchObj = new StaffMemoSearchObj
                //{
                //    AdminUserId = 0,
                //    StaffMemoId = 0,
                //    StaffId = regObj.AdminUserId,
                //    Status = 0,
                //    SysPathCode = ""
                //};

                //retrieve previous contacts and validate with the new one
                var staffMemos = getStaffMemos(regObj.StaffId);

                if (staffMemos == null || !staffMemos.Any())
                {
                    response.Status.Message.FriendlyMessage  = "No Staff Memo Information found";
                    response.Status.Message.TechnicalMessage = "No Staff Memo Information found";
                    return(response);
                }
                var thisMemoFind         = staffMemos.Find(m => m.StaffMemoId == regObj.StaffMemoId);
                var staffWorkflowlog     = GetWorkflowLog(thisMemoFind.StaffId);
                var thisStaffWorkFlowLog = staffWorkflowlog.Find(m => m.StaffId == thisMemoFind.StaffId);
                if (thisMemoFind.StaffMemoId < 1)
                {
                    response.Status.Message.FriendlyMessage  = "This Staff Memo Information not found";
                    response.Status.Message.TechnicalMessage = "This Staff Memo Request Information not found";
                    return(response);
                }
                if (thisStaffWorkFlowLog.StaffId < 1)
                {
                    response.Status.Message.FriendlyMessage  = "This Staff Work flow Log  Information not found";
                    response.Status.Message.TechnicalMessage = "This Staff Work flow Log Information not found";
                    return(response);
                }


                thisMemoFind.MemoType   = (MemoType)regObj.MemoType;
                thisMemoFind.ApprovedBy = regObj.ApprovedBy;
                thisMemoFind.Status     = (ApprovalStatus)regObj.Status;

                thisStaffWorkFlowLog.WorkflowOrderItemId = regObj.WorkflowOrderItemId;
                thisStaffWorkFlowLog.ApprovalType        = WorkflowApprovalType.HR_Head;
                thisStaffWorkFlowLog.ProcessorId         = regObj.AdminUserId;
                thisStaffWorkFlowLog.Comment             = regObj.MemoDetail;
                thisStaffWorkFlowLog.LogTimeStamp        = DateMap.CurrentTimeStamp();
                thisStaffWorkFlowLog.Status = (ApprovalStatus)regObj.Status;

                using (var db = _uoWork.BeginTransaction())
                {
                    try
                    {
                        var added = _staffMemoRepository.Update(thisMemoFind);
                        _uoWork.SaveChanges();
                        if (added.StaffMemoId < 1)
                        {
                            db.Rollback();
                            response.Status.Message.FriendlyMessage =
                                "Error Occurred! Unable to complete your request. Please try again later";
                            response.Status.Message.TechnicalMessage = "Unable to save to database";
                            return(response);
                        }


                        var retVal = _workflowLogRepository.Update(thisStaffWorkFlowLog);
                        _uoWork.SaveChanges();
                        if (retVal.WorkflowLogId < 1)
                        {
                            db.Rollback();
                            response.Status.Message.FriendlyMessage =
                                "Error Occurred! Unable to complete your request. Please try again later";
                            response.Status.Message.TechnicalMessage = "Unable to save to database";
                            return(response);
                        }
                        response.Status.IsSuccessful       = true;
                        response.SettingId                 = added.StaffMemoId;
                        thisStaffWorkFlowLog.WorkflowLogId = thisStaffWorkFlowLog.WorkflowLogId;
                        db.Commit();
                    }
                    catch (DbEntityValidationException ex)
                    {
                        db.Rollback();
                        ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                        response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                        response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                        response.Status.IsSuccessful             = false;
                        return(response);
                    }
                    catch (Exception ex)
                    {
                        db.Rollback();
                        ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                        response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                        response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                        response.Status.IsSuccessful             = false;
                        return(response);
                    }
                }
            }
            catch (DbEntityValidationException ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                response.Status.Message.FriendlyMessage  = "Error Occurred! Please try again later";
                response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message;
                response.Status.IsSuccessful             = false;
                return(response);
            }
            return(response);
        }
Esempio n. 2
0
 public static SettingRegRespObj ApproveStaffMemo(ApprovaStaffMemoObj regObj)
 {
     return(new StaffRepository().ApproveStaffMemo(regObj));
 }