コード例 #1
0
        private bool IsWorkflowOrderItemDuplicate(string name, int workFlowOrderId, int order, int callType,
                                                  ref SettingRegRespObj response)
        {
            try
            {
                var sql1 =
                    $"Select coalesce(Count(\"WorkflowOrderItemId\"), 0) FROM  \"GPlus\".\"WorkflowOrderItem\"  WHERE lower(\"Name\") = lower('{name.Replace("'", "''")}') AND \"WorkflowOrderId\" = {workFlowOrderId} AND \"Order\" = {order}";
                var check = _repository.RepositoryContext().Database.SqlQuery <long>(sql1).ToList();


                if (check.IsNullOrEmpty())
                {
                    response.Status.Message.FriendlyMessage =
                        "Unable to complete your request due to validation error. Please try again later";
                    response.Status.Message.TechnicalMessage = "Unable to check for duplicate";
                    return(true);
                }

                if (check.Count != 1)
                {
                    response.Status.Message.FriendlyMessage =
                        "Unable to complete your request due to validation error. Please try again later";
                    response.Status.Message.TechnicalMessage = "Unable to check for duplicate";
                    return(true);
                }

                if (check[0] < 1)
                {
                    return(false);
                }


                if (check[0] > 0)
                {
                    if (callType != 2 || check[0] > 1)
                    {
                        response.Status.Message.FriendlyMessage =
                            "Duplicate Error!WorkflowOrderItem Name already exist";
                        response.Status.Message.TechnicalMessage =
                            "Duplicate Error! WorkflowOrderItem Name already exist";
                        return(true);
                    }

                    return(false);
                }


                return(false);
            }
            catch (Exception ex)
            {
                response.Status.Message.FriendlyMessage =
                    "Unable to complete your request due to validation error. Please try again later";
                response.Status.Message.TechnicalMessage = "Duplicate Check Error: " + ex.Message;
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                return(true);
            }
        }
コード例 #2
0
        public SettingRegRespObj AddJobLevel(RegJobLevelObj 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.getSeniorAccountant(), ref response.Status.Message))
                {
                    return(response);
                }

                if (IsJobLevelDuplicate(regObj.Name, 1, ref response))
                {
                    return(response);
                }

                var jobLevel = new JobLevel
                {
                    Name   = regObj.Name,
                    Status = (ItemStatus)regObj.Status
                };

                var added = _repository.Add(jobLevel);

                _uoWork.SaveChanges();

                if (added.JobLevelId < 1)
                {
                    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);
                }
                resetCache();
                response.Status.IsSuccessful = true;
                response.SettingId           = added.JobLevelId;
            }
            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);
        }
コード例 #3
0
        public SettingRegRespObj DeleteInstitution(DeleteInstitutionObj 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.getStaffRoles(),
                                               ref response.Status.Message))
                {
                    return(response);
                }
                var thisInstitution = GetInstitutionInfo(regObj.InstitutionId);

                if (thisInstitution == null)
                {
                    response.Status.Message.FriendlyMessage =
                        "No Institution Information found for the specified Institution Id";
                    response.Status.Message.TechnicalMessage = "No Institution Information found!";
                    return(response);
                }
                thisInstitution.Name =
                    thisInstitution.Name + "_Deleted_" + DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss");
                thisInstitution.Status = ItemStatus.Deleted;
                var added = _repository.Update(thisInstitution);
                _uoWork.SaveChanges();

                if (added.InstitutionId < 1)
                {
                    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);
                }
                resetCache();
                response.Status.IsSuccessful = true;
                response.SettingId           = added.InstitutionId;
            }
            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);
        }
コード例 #4
0
        public SettingRegRespObj UpdatekPIndex(EditKPIndexObj 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.getSeniorAccountant(), ref response.Status.Message))
                {
                    return(response);
                }

                var thiskPIndex = GetkPIndexInfo(regObj.KPIndexId);

                if (thiskPIndex == null)
                {
                    response.Status.Message.FriendlyMessage =
                        "No Key Performance Indicator Information found for the specified KPIndex Id";
                    response.Status.Message.TechnicalMessage = "No Key Performance Indicator Information found!";
                    return(response);
                }

                if (IskPIndexDuplicate(regObj.Name, 2, ref response))
                {
                    return(response);
                }

                if (regObj.MinRating > regObj.MaxRating)
                {
                    response.Status.Message.FriendlyMessage  = "Minimum Rating cannot be higher than Maximum Rating";
                    response.Status.Message.TechnicalMessage = "Unable to save to database";
                    return(response);
                }
                if (regObj.MinRating == regObj.MaxRating)
                {
                    response.Status.Message.FriendlyMessage  = "Minimum/Maximum Rating cannot be equal to each other";
                    response.Status.Message.TechnicalMessage = "Unable to save to database";
                    return(response);
                }
                thiskPIndex.Name      = regObj.Name;
                thiskPIndex.Indicator = regObj.Indicator;
                thiskPIndex.MinRating = regObj.MinRating;
                thiskPIndex.MaxRating = regObj.MaxRating;
                thiskPIndex.Status    = (ItemStatus)regObj.Status;
                var added = _repository.Update(thiskPIndex);
                _uoWork.SaveChanges();

                if (added.KPIndexId < 1)
                {
                    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);
                }
                resetCache();
                response.Status.IsSuccessful = true;
                response.SettingId           = added.KPIndexId;
            }
            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);
        }
コード例 #5
0
        public SettingRegRespObj UpdateCompany(EditCompanyObj 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.getSeniorAccountant(), ref response.Status.Message))
                {
                    return(response);
                }

                var thisCompany = getCompanyInfo(regObj.CompanyId);

                if (thisCompany == null)
                {
                    response.Status.Message.FriendlyMessage =
                        "No Company Information found for the specified Company Id";
                    response.Status.Message.TechnicalMessage = "No Company Information found!";
                    return(response);
                }

                if (IsCompanyDuplicate(regObj.Name, 2, ref response))
                {
                    return(response);
                }
                thisCompany.Name = regObj.Name;
                thisCompany.BusinessDescription = regObj.BusinessDescription;
                thisCompany.Address             = regObj.Address;
                thisCompany.CompanyType         = (CompanyType)regObj.CompanyType;
                thisCompany.Email  = regObj.Email;
                thisCompany.Status = (ItemStatus)regObj.Status;
                var added = _repository.Update(thisCompany);
                _uoWork.SaveChanges();

                if (added.CompanyId < 1)
                {
                    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);
                }
                resetCache();
                response.Status.IsSuccessful = true;
                response.SettingId           = added.CompanyId;
            }
            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);
        }
コード例 #6
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);
        }
コード例 #7
0
        public SettingRegRespObj AddStaffMemo(RegStaffMemoObj 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.getStaffRoles(), ref response.Status.Message))
                {
                    return(response);
                }

                var staffMemo = new StaffMemo
                {
                    StaffId           = regObj.StaffId,
                    Title             = regObj.Title,
                    MemoType          = (MemoType)regObj.MemoType,
                    MemoDetail        = regObj.MemoDetail,
                    IsReplied         = false,
                    RegisterBy        = regObj.AdminUserId,
                    ApprovedBy        = 0,
                    Status            = ApprovalStatus.Registered,
                    TimeStampRegister = DateMap.CurrentTimeStamp()
                };



                using (var db = _uoWork.BeginTransaction())
                {
                    try
                    {
                        var added = _staffMemoRepository.Add(staffMemo);
                        _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);
                        }
                        workFlowSourceId = added.StaffMemoId;
                        var workflow = new WorkflowSetup
                        {
                            Description           = regObj.Title,
                            InitiatorId           = regObj.AdminUserId,
                            InitiatorType         = WorkflowInitiatorType.HR,
                            Item                  = WorkflowItem.Staff_Memo,
                            WorkflowOrderId       = regObj.WorkflowOrderId,
                            WorkflowSourceId      = workFlowSourceId,
                            LastTimeStampModified = DateMap.CurrentTimeStamp(),
                            StaffId               = regObj.StaffId,
                            TimeStampInitiated    = DateMap.CurrentTimeStamp(),
                            Status                = WorkflowStatus.Initiated
                        };

                        var retVal = _workflowSetupRepository.Add(workflow);
                        _uoWork.SaveChanges();
                        if (retVal.WorkflowSetupId < 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;
                        workflow.WorkflowSourceId    = added.StaffMemoId;
                        db.Commit();
                    }
                    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);
                }
            }
            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);
            }
        }
コード例 #8
0
        public SettingRegRespObj AddBulkStaffMemo(RegBulkStaffMemoObj regObj)
        {
            var response = new SettingRegRespObj
            {
                Status = new APIResponseStatus
                {
                    IsSuccessful = false,
                    Message      = new APIResponseMessage()
                }
            };

            try
            {
                if (regObj?.StaffMemoItem == null || !regObj.StaffMemoItem.Any())
                {
                    response.Status.Message.FriendlyMessage  = "Empty Request Item! Please try again later";
                    response.Status.Message.TechnicalMessage = "Registration Object is empty / invalid";
                    return(response);
                }

                foreach (var reqitem in regObj.StaffMemoItem)
                {
                    if (!EntityValidatorHelper.Validate(reqitem, out var valItemResults))
                    {
                        var errorDetail = new StringBuilder();
                        if (!valItemResults.IsNullOrEmpty())
                        {
                            errorDetail.AppendLine("Following error occurred:");
                            valItemResults.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.getStaffRoles(), ref response.Status.Message))
                {
                    return(response);
                }

                var staffMemoList = new List <StaffMemo>();
                var workflowList  = new List <WorkflowSetup>();
                var results       = staffMemoList.GroupBy(e => e.StaffMemoId, (key, g) => new
                {
                    StaffMemoId    = key,
                    StaffMemoItems = g.ToList()
                }).ToList();

                if (!results.Any())
                {
                    response.Status.Message.FriendlyMessage  = "Invalid Expense Item list";
                    response.Status.Message.TechnicalMessage = "Invalid Expense Item list";
                    response.Status.IsSuccessful             = false;
                    return(response);
                }

                foreach (var reqItem in results)
                {
                    if (reqItem.StaffMemoItems.Count > 1)
                    {
                        response.Status.Message.FriendlyMessage =
                            $"Duplicate Staff Memo Item {getStaffMemo(reqItem.StaffMemoItems[0].StaffId).MemoType.ToString()}";
                        response.Status.Message.TechnicalMessage =
                            $"Duplicate Staff Memo Item {getStaffMemo(reqItem.StaffMemoItems[0].StaffId).MemoType.ToString()}";
                        response.Status.IsSuccessful = false;
                        return(response);
                    }
                    staffMemoList.Add(new StaffMemo
                    {
                        StaffId           = reqItem.StaffMemoItems[0].StaffId,
                        Title             = reqItem.StaffMemoItems[0].Title,
                        MemoType          = reqItem.StaffMemoItems[0].MemoType,
                        MemoDetail        = reqItem.StaffMemoItems[0].MemoDetail,
                        IsReplied         = false,
                        RegisterBy        = regObj.AdminUserId,
                        ApprovedBy        = 0,
                        Status            = ApprovalStatus.Approved,
                        TimeStampRegister = DateMap.CurrentTimeStamp()
                    });
                    workFlowSourceId = staffMemoList[0].StaffMemoId;
                    workflowList.Add(new WorkflowSetup
                    {
                        Description           = reqItem.StaffMemoItems[0].Title,
                        InitiatorId           = regObj.AdminUserId,
                        InitiatorType         = WorkflowInitiatorType.HR,
                        Item                  = WorkflowItem.Staff_Memo,
                        WorkflowOrderId       = regObj.StaffMemoItem[0].WorkflowOrderId,
                        WorkflowSourceId      = workFlowSourceId,
                        LastTimeStampModified = DateMap.CurrentTimeStamp(),
                        StaffId               = reqItem.StaffMemoItems[0].StaffId,
                        TimeStampInitiated    = DateMap.CurrentTimeStamp(),
                        Status                = WorkflowStatus.Initiated
                    });
                }

                using (var db = _uoWork.BeginTransaction())
                {
                    try
                    {
                        var added = _staffMemoRepository.AddRange(staffMemoList);
                        _uoWork.SaveChanges();
                        if (added == null || !added.Any())
                        {
                            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 = _workflowSetupRepository.AddRange(workflowList);
                        _uoWork.SaveChanges();
                        if (retVal == null || !retVal.Any())
                        {
                            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;
                        workflowList[0].WorkflowSourceId = staffMemoList[0].StaffMemoId;
                        db.Commit();
                    }
                    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);
                }
            }
            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);
            }
        }