Esempio n. 1
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);
            }
        }
Esempio n. 2
0
 public static SettingRegRespObj AddStaffMemo(RegStaffMemoObj regObj)
 {
     return(new StaffRepository().AddStaffMemo(regObj));
 }