Пример #1
0
        public SettingRegRespObj AddCompany(RegCompanyObj 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 (IsCompanyDuplicate(regObj.Name, 1, ref response))
                {
                    return(response);
                }

                var company = new Company
                {
                    Name = regObj.Name,
                    BusinessDescription = regObj.BusinessDescription,
                    Address             = regObj.Address,
                    CompanyType         = (CompanyType)regObj.CompanyType,
                    Email             = regObj.Email,
                    RegisteredBy      = regObj.AdminUserId,
                    TimeStampRegister = DateMap.CurrentTimeStamp(),
                    Status            = (ItemStatus)regObj.Status
                };

                var added = _repository.Add(company);

                _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);
        }
Пример #2
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);
        }
Пример #3
0
        public UserInformation RemoteLoginUser(string username, string password, string hostServer)
        {
            var userInformation = new UserInformation
            {
                UserInfo = new User()
            };

            #region Null Validation

            if (username.IsNullOrEmpty() || password.IsNullOrEmpty() || hostServer.IsNullOrEmpty())
            {
                _status.Message.FriendlyMessage = _status.Message.TechnicalMessage = "Login Failed! Reason: All the inputs are required";
                userInformation.Status          = _status;
                return(userInformation);
            }
            #endregion

            var stationInfo = new StationInfo
            {
                //Address = "",
                APIAccessKey        = "",
                HostServerAddress   = hostServer,
                StationKey          = "",
                StationName         = "",
                TimeStampRegistered = DateMap.CurrentTimeStamp(),
                Status = true,
            };

            #region Super Admin User Profile

            var superUserProfileInfo = new UserProfile
            {
                DateLastModified   = DateTime.Now.ToString("yyyy/MM/dd"),
                Email              = "*****@*****.**",
                FirstName          = "SuperAdmin",
                MobileNumber       = "2348036975694",
                ModifiedBy         = 1,
                OtherNames         = "",
                ProfileNumber      = "0001",
                ResidentialAddress = "EpayPlus Limited",
                Sex              = 1,
                Status           = 1,
                Surname          = "Epay",
                TimeLastModified = DateTime.Now.ToString("hh:mm:ss tt")
            };

            var superUserInfo = new User
            {
                Email = "*****@*****.**",
                FailedPasswordAttemptCount = 0,
                IsApproved              = true,
                IsLockedOut             = false,
                Password                = "******",
                RegisteredDateTimeStamp = DateTime.Now.ToString("yyyy/MM/dd - hh:mm:ss tt"),
                RoleId   = 1,
                UserName = "******",
                LastLockedOutTimeStamp       = "",
                LastLoginTimeStamp           = "",
                LastPasswordChangedTimeStamp = ""
            };

            #endregion


            using (var db = _uoWork.BeginTransaction())
            {
                try
                {
                    #region Remotely Connect & Login

                    #region Access Parameter - Authorize Access

                    var networkInterface = InternetHelp.GetMainNetworkInterface();
                    var loginParameter   = new RemoteLoginParameter
                    {
                        DeviceIP = InternetHelp.GetIpAddress(networkInterface),
                        DeviceId = InternetHelp.GetMACAddress(),
                        UserName = username,
                        Password = password
                    };
                    #endregion

                    string msg;
                    var    remoteLoginRespObj = new RemoteMessanger(RemoteProcessType.RemoteLogin, hostServer).RemoteLogin(loginParameter, out msg);
                    if (remoteLoginRespObj == null)
                    {
                        _status.Message.FriendlyMessage = _status.Message.TechnicalMessage = "Process Failed! " + (string.IsNullOrEmpty(msg) ? "Unable to register Station Information" : msg);
                        userInformation.Status          = _status;
                        return(userInformation);
                    }
                    if (!remoteLoginRespObj.ResponseStatus.IsSuccessful || string.IsNullOrEmpty(remoteLoginRespObj.APIAccessKey) || remoteLoginRespObj.APIAccessKey.Length != 10)
                    {
                        _status.Message.FriendlyMessage = _status.Message.TechnicalMessage = string.IsNullOrEmpty(remoteLoginRespObj.ResponseStatus.Message.FriendlyMessage) ? "Unable to complete your request! Please try again later" : remoteLoginRespObj.ResponseStatus.Message.FriendlyMessage;
                        userInformation.Status          = _status;
                        return(userInformation);
                    }

                    #endregion

                    #region Station Info

                    stationInfo.RemoteStationId = remoteLoginRespObj.ClientStationId;
                    stationInfo.APIAccessKey    = remoteLoginRespObj.APIAccessKey;
                    stationInfo.StationName     = remoteLoginRespObj.StationName;
                    stationInfo.StationKey      = remoteLoginRespObj.StationId;
                    stationInfo.Status          = Convert.ToBoolean(remoteLoginRespObj.StationStatus);
                    var addStationInfo = _stationInfoRepository.Add(stationInfo);
                    _uoWork.SaveChanges();

                    stationInfo.StationInfoId = addStationInfo.StationInfoId;
                    if (stationInfo.StationInfoId < 1)
                    {
                        db.Rollback();
                        _status.Message.FriendlyMessage = _status.Message.TechnicalMessage = "Process Failed! Unable to register Station Information";
                        userInformation.Status          = _status;
                        return(userInformation);
                    }

                    #endregion

                    #region Company

                    var companyInfo = new CompanyInfo
                    {
                        StationName       = remoteLoginRespObj.StationName,
                        StationKey        = remoteLoginRespObj.StationId,
                        HostServerAddress = hostServer,
                        //Address = "",
                        Status = Convert.ToBoolean(remoteLoginRespObj.StationStatus),
                    };

                    var addCompanyInfo = _companyRepository.Add(companyInfo);
                    _uoWork.SaveChanges();
                    if (addCompanyInfo.CompanyInfoId < 1)
                    {
                        db.Rollback();
                        _status.Message.FriendlyMessage = _status.Message.TechnicalMessage = "Unable to save Station's profile to the database";
                        userInformation.Status          = _status;
                        return(userInformation);
                    }
                    #endregion

                    #region User Profile

                    var staffRegistration = new UserProfile
                    {
                        StationInfoId      = stationInfo.StationInfoId,
                        Surname            = remoteLoginRespObj.Surname,
                        FirstName          = remoteLoginRespObj.FirstName,
                        OtherNames         = remoteLoginRespObj.Othernames,
                        ResidentialAddress = remoteLoginRespObj.ResidentialAddress,
                        MobileNumber       = remoteLoginRespObj.MobileNumber,
                        Email               = remoteLoginRespObj.Email,
                        ProfileNumber       = remoteLoginRespObj.EnrollerRegId,
                        UserProfileRemoteId = remoteLoginRespObj.EnrollerId,
                        Sex              = remoteLoginRespObj.Sex,
                        Status           = remoteLoginRespObj.EnrollerStatus,
                        TimeLastModified = DateTime.Now.ToString("hh:mm:ss tt"),
                        DateLastModified = DateTime.Now.ToString("yyyy/MM/dd"),
                        ModifiedBy       = 1
                    };

                    var userProfile = _userProfileRepository.Add(staffRegistration);
                    _uoWork.SaveChanges();
                    if (userProfile.UserProfileId < 1)
                    {
                        db.Rollback();
                        _status.Message.FriendlyMessage = _status.Message.TechnicalMessage = "Error Occurred! Unable to add new user record";
                        userInformation.Status          = _status;
                        return(userInformation);
                    }

                    #endregion

                    #region User

                    var user = new User
                    {
                        UserName    = username,
                        Password    = password,
                        Email       = remoteLoginRespObj.Email,
                        RoleId      = 2,
                        IsApproved  = true,
                        IsLockedOut = false,
                        FailedPasswordAttemptCount   = 0,
                        LastLockedOutTimeStamp       = "",
                        LastLoginTimeStamp           = "",
                        LastPasswordChangedTimeStamp = "",
                        RegisteredDateTimeStamp      = DateTime.Now.ToString("yyyy/MM/dd - hh:mm:ss tt")
                    };

                    var thisUser = new UserRepository().GetUser(user.UserName);
                    if (thisUser != null)
                    {
                        if (thisUser.UserProfileId > 0)
                        {
                            db.Rollback();
                            _status.Message.FriendlyMessage = _status.Message.TechnicalMessage = "Duplicate Error! This username already exist in local database";
                            userInformation.Status          = _status;
                            return(userInformation);
                        }
                    }

                    user.UserCode         = Crypto.HashPassword(user.Password);
                    user.Salt             = EncryptionHelper.GenerateSalt(30, 50);
                    user.Password         = Crypto.GenerateSalt(16);
                    user.IsFirstTimeLogin = true;
                    user.UserProfileId    = userProfile.UserProfileId;

                    var addUser = _repository.Add(user);
                    _uoWork.SaveChanges();
                    if (addUser.UserId < 1)
                    {
                        db.Rollback();
                        _status.Message.FriendlyMessage = _status.Message.TechnicalMessage = "Error Occurred! Unable to add new user account";
                        userInformation.Status          = _status;
                        return(userInformation);
                    }

                    #endregion


                    #region Default Admin Profiles

                    var check = new UserRepository().GetUser("useradmin");
                    if (check == null || check.UserProfileId < 1)
                    {
                        superUserInfo.UserCode         = Crypto.HashPassword(superUserInfo.Password);
                        superUserInfo.Salt             = EncryptionHelper.GenerateSalt(30, 50);
                        superUserInfo.Password         = Crypto.GenerateSalt(16);
                        superUserInfo.IsFirstTimeLogin = false;
                        var processSuperProfile = _userProfileRepository.Add(superUserProfileInfo);
                        _uoWork.SaveChanges();
                        if (processSuperProfile.UserProfileId < 1)
                        {
                            db.Rollback();
                            _status.Message.FriendlyMessage = _status.Message.TechnicalMessage = "Error Occurred! Unable to add new user account";
                            userInformation.Status          = _status;
                            return(userInformation);
                        }

                        superUserInfo.UserProfileId = processSuperProfile.UserProfileId;
                        var processSuperUser = _repository.Add(superUserInfo);
                        _uoWork.SaveChanges();
                        if (processSuperUser.UserId < 1)
                        {
                            db.Rollback();
                            _status.Message.FriendlyMessage = _status.Message.TechnicalMessage = "Error Occurred! Unable to add new user account";
                            userInformation.Status          = _status;
                            return(userInformation);
                        }
                    }

                    #endregion

                    db.Commit();
                    user.UserProfile            = userProfile;
                    _status.IsSuccessful        = true;
                    userInformation.Status      = _status;
                    userInformation.UserInfo    = user;
                    userInformation.StationInfo = stationInfo;
                    return(userInformation);
                }
                catch (DbEntityValidationException ex)
                {
                    ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                    _status.Message.FriendlyMessage  = "Login Failed! Reason: " + ex.Message;
                    _status.Message.TechnicalMessage = "Error: " + ex.Message;
                    userInformation.Status           = _status;
                    return(userInformation);
                }
                catch (Exception ex)
                {
                    db.Rollback();
                    ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                    _status.Message.FriendlyMessage  = "Login Failed! Reason: " + ex.Message;
                    _status.Message.TechnicalMessage = "Error: " + ex.Message;
                    userInformation.Status           = _status;
                    return(userInformation);
                }
            }
        }
Пример #4
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);
            }
        }
Пример #5
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);
            }
        }
        public CardDeliveryRegRespObj AddCardDelivery(RegCardDeliveryObj regObj)
        {
            var response = new CardDeliveryRegRespObj
            {
                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.getRequesterRoles(), ref response.Status.Message))
                {
                    return(response);
                }

                var associatedCard = GetCardInfo(regObj.CardId);
                if (associatedCard == null)
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! No Card  Information Found";
                    response.Status.Message.TechnicalMessage = "Error Occurred! No Card  Information Found";
                    return(response);
                }

                var associatedCardItem = GetCardItemInfo(regObj.CardItemId);
                if (associatedCardItem == null)
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! No Card Item  Information Found";
                    response.Status.Message.TechnicalMessage = "Error Occurred! No Card Item Information Found";
                    return(response);
                }

                if (associatedCard.Status != CardStatus.Registered)
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! This Card Item Is Not Available For Delivery";
                    response.Status.Message.TechnicalMessage = "Error Occurred! This Card Item Is Not Available For Delivery";
                    return(response);
                }

                //check validity of start/stop batch number

                if ((int.Parse(regObj.StopBatchNumber) - int.Parse(regObj.StartBatchNumber) + 1) !=
                    associatedCard.QuantityPerBatch)
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Incorrect StopBatchNumber/StartBatchNumber Data";
                    response.Status.Message.TechnicalMessage = "Error Occurred! Incorrect StopBatchNumber/StartBatchNumber Data";
                    return(response);
                }

                if (regObj.BatchId != associatedCardItem.BatchId)
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Incorrect BatchId";
                    response.Status.Message.TechnicalMessage = "Error Occurred! Incorrect BatchId";
                    return(response);
                }
                if (regObj.DeliveredQuantity < 1)
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! You Cannot Register An empty delivery ";
                    response.Status.Message.TechnicalMessage = "Error Occurred! Incorrect quantity Delivered Data";
                    return(response);
                }

                if (regObj.DeliveredQuantity + associatedCardItem.DeliveredQuantity > associatedCardItem.BatchQuantity)
                {
                    if (associatedCardItem.BatchQuantity - (associatedCardItem.DeliveredQuantity) > 0)
                    {
                        response.Status.Message.FriendlyMessage = $"Incorrect Quantity Delivered,{associatedCardItem.BatchQuantity - (associatedCardItem.DeliveredQuantity)} is only available for delivery";
                    }
                    else if (associatedCardItem.BatchQuantity - (associatedCardItem.DeliveredQuantity) == 0)
                    {
                        response.Status.Message.FriendlyMessage = $"This Delivery is Complete";
                    }

                    response.Status.Message.TechnicalMessage = "Error Occurred! Incorrect Quantity Delivered";
                    return(response);
                }

                if (DateTime.Parse(regObj.TimeStampDelivered) > DateTime.Now)
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! You Cannot Register A delivery before DeliveryDate";
                    response.Status.Message.TechnicalMessage = "Error Occurred! Incorrect Delivery Date Data";
                    return(response);
                }

                using (var db = _uoWork.BeginTransaction())
                {
                    var newCardDelivery = new CardDelivery
                    {
                        CardId             = regObj.CardId,
                        CardItemId         = regObj.CardItemId,
                        CardTypeId         = regObj.CardTypeId,
                        BatchId            = associatedCardItem.BatchId,
                        Status             = CardStatus.Registered,
                        ApprovedBy         = 0,
                        ApproverComment    = regObj.ApproverComment,
                        TimeStampApproved  = "",
                        DefectiveQuantity  = regObj.DefectiveQuantity,
                        TimeStampDelivered = regObj.TimeStampDelivered,
                        MissingQuantity    = regObj.MissingQuantity,
                        DeliveredQuantity  = regObj.DeliveredQuantity,
                        StartBatchNumber   = associatedCardItem.BatchId + "" + "000",
                        StopBatchNumber    = associatedCardItem.BatchId + "" + "999",
                        ReceivedBy         = regObj.AdminUserId,
                        TimeStampRegisered = DateMap.CurrentTimeStamp(),
                    };

                    var deliveryAdded = _repository.Add(newCardDelivery);
                    _uoWork.SaveChanges();
                    if (deliveryAdded.CardDeliveryId < 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);
                    }
                    associatedCardItem.MissingQuantity     += regObj.MissingQuantity;
                    associatedCardItem.DefectiveQuantity   += regObj.DefectiveQuantity;
                    associatedCardItem.DeliveredQuantity   += regObj.DeliveredQuantity;
                    associatedCardItem.AvailableQuantity   += regObj.DeliveredQuantity - (regObj.MissingQuantity + regObj.DefectiveQuantity);
                    associatedCardItem.TimeStampDelivered   = deliveryAdded.TimeStampRegisered;
                    associatedCardItem.DefectiveBatchNumber = regObj.DefectiveBatchNumber;
                    associatedCardItem.Status = CardStatus.Registered;

                    var updateCardItem = _cardItemRepository.Update(associatedCardItem);
                    _uoWork.SaveChanges();
                    if (updateCardItem.CardItemId < 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);
                    }


                    associatedCard.Status = CardStatus.Registered;
                    var updateCard = _cardRepository.Update(associatedCard);
                    _uoWork.SaveChanges();
                    if (updateCard.CardId < 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);
                    }
                    db.Commit();

                    response.Status.IsSuccessful            = true;
                    response.CardDeliveryId                 = deliveryAdded.CardDeliveryId;
                    response.Status.Message.FriendlyMessage = "Card Delivery Added Successfully";
                }
            }
            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);
        }
        public BeneficiaryPaymentRegRespObj AddBeneficiaryPayment(RegBeneficiaryPaymentObj regObj)
        {
            var response = new BeneficiaryPaymentRegRespObj
            {
                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.getRequesterRoles(), ref response.Status.Message))
                {
                    return(response);
                }

                var associatedBeneficiary = GetBeneficiaryInfo(regObj.BeneficiaryId);
                if (associatedBeneficiary == null)
                {
                    response.Status.Message.FriendlyMessage  = "Ooops ! Beneficiary Does not Exist!";
                    response.Status.Message.TechnicalMessage = "No Beneficiary Information Found";
                    return(response);
                }

                if (associatedBeneficiary.Status != Status.Active)
                {
                    response.Status.Message.FriendlyMessage  = "Sorry!This Beneficiary Cannot Perform Any Transaction Yet! Please Contact Administrator";
                    response.Status.Message.TechnicalMessage = "Beneficiary Isn't Approved yet";
                    return(response);
                }
                var associatedBeneAccount = GetBeneficiaryAccountInfo(associatedBeneficiary.BeneficiaryAccountId);
                if (associatedBeneAccount == null)
                {
                    response.Status.Message.FriendlyMessage  = "Ooops ! Beneficiary Account Does not Exist!";
                    response.Status.Message.TechnicalMessage = "No Beneficiary Account Information Found";
                    return(response);
                }

                if (!string.IsNullOrWhiteSpace(regObj.PaymentReference))
                {
                    if (DataCheck.IsNumeric(regObj.PaymentReference))
                    {
                        response.Status.Message.FriendlyMessage  = "Error Occurred! Payment reference must be Numbers Only";
                        response.Status.Message.TechnicalMessage = "Payment Reference  is invalid";
                        return(response);
                    }

                    var associatedBenPayment = GetBeneficiaryPayment(new SettingSearchObj {
                        Status = -2
                    });
                    if (associatedBenPayment.Any())
                    {
                        if (associatedBenPayment.FindAll(payment => payment.PaymentReference == regObj.PaymentReference)
                            .Any())
                        {
                            response.Status.Message.FriendlyMessage  = "Error Occurred! Payment reference is Invalid";
                            response.Status.Message.TechnicalMessage = "Duplicate Error! Payment Reference  is Invalid!";
                            return(response);
                        }
                    }
                }

                //store date for Concurrency...
                var nowDateTime = DateMap.CurrentTimeStamp();
                var nowDate     = nowDateTime.Substring(0, nowDateTime.IndexOf(' '));
                var nowTime     = nowDateTime.Substring(nowDateTime.IndexOf('-') + 1);

                using (var db = _uoWork.BeginTransaction())
                {
                    #region Beneficiary Account Transaction Operation
                    var newBeneficiaryTransaction = new BeneficiaryAccountTransaction
                    {
                        BeneficiaryAccountId = associatedBeneAccount.BeneficiaryAccountId,
                        BeneficiaryId        = regObj.BeneficiaryId,
                        Amount              = regObj.AmountPaid,
                        PreviousBalance     = associatedBeneAccount.AvailableBalance,
                        NewBalance          = (associatedBeneAccount.AvailableBalance + regObj.AmountPaid),
                        TransactionSource   = TransactionSourceType.Account_TopUp,
                        TransactionType     = TransactionType.Credit,
                        Status              = Status.Active,
                        RegisteredBy        = regObj.AdminUserId,
                        TimeStampRegistered = nowDateTime,
                    };

                    var transactionAdded = _beneAccTransRepository.Add(newBeneficiaryTransaction);
                    _uoWork.SaveChanges();
                    if (transactionAdded.BeneficiaryAccountTransactionId < 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);
                    }

                    #endregion

                    #region Beneficiary Payment Operation

                    var newBeneficiaryPayment = new BeneficiaryPayment
                    {
                        BeneficiaryId        = regObj.BeneficiaryId,
                        BeneficiaryAccountId = associatedBeneAccount.BeneficiaryAccountId,
                        PaymentDate          = regObj.PaymentDate,
                        PaymentReference     = regObj.PaymentReference,
                        PaySource            = (PaySource)regObj.PaySource,
                        PaymentSourceName    = ((PaySource)regObj.PaySource).ToString().Replace("_", " "),
                        RegisteredBy         = regObj.AdminUserId,
                        TimeStampRegistered  = nowDateTime,
                        Status     = Status.Active,
                        AmountPaid = regObj.AmountPaid,
                        BeneficiaryAccountTransactionId = transactionAdded.BeneficiaryAccountTransactionId,
                    };

                    var paymentAdded = _repositiory.Add(newBeneficiaryPayment);
                    _uoWork.SaveChanges();
                    if (paymentAdded.BeneficiaryPaymentId < 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);
                    }
                    #endregion

                    #region Beneficiary Account Update

                    associatedBeneAccount.AvailableBalance      = transactionAdded.NewBalance;
                    associatedBeneAccount.CreditLimit           = 0;
                    associatedBeneAccount.LastTransactionAmount = transactionAdded.Amount;
                    associatedBeneAccount.LastTransactionType   = transactionAdded.TransactionType;
                    associatedBeneAccount.Status                   = Status.Active;
                    associatedBeneAccount.LastTransactionId        = transactionAdded.BeneficiaryAccountTransactionId;
                    associatedBeneAccount.LastTransactionTimeStamp = DateMap.CurrentTimeStamp();

                    var updateBeneAccount = _beneAccRepository.Update(associatedBeneAccount);
                    _uoWork.SaveChanges();
                    if (updateBeneAccount.BeneficiaryAccountId < 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);
                    }

                    #endregion

                    db.Commit();
                    response.Status.IsSuccessful            = true;
                    response.PaymentId                      = paymentAdded.BeneficiaryPaymentId;
                    response.Status.Message.FriendlyMessage = "Payment Successful";
                }
            }
            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);
        }
Пример #8
0
        public CardRegRespObj AddCard(RegCardObj regObj)
        {
            var response = new CardRegRespObj
            {
                Status = new APIResponseStatus
                {
                    IsSuccessful = false,
                    Message      = new APIResponseMessage()
                }
            };

            try
            {
                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.getRequesterRoles(), ref response.Status.Message))
                {
                    return(response);
                }

                if (!DataCheck.IsNumeric(regObj.BatchKey))
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Batch Key Invalid";
                    response.Status.Message.TechnicalMessage = "Batch Prefix Number Must be greater than 0";
                    return(response);
                }
                if (!DataCheck.IsNumeric(regObj.StartBatchId))
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Invalid Start Batch Id";
                    response.Status.Message.TechnicalMessage = "Start Batch Id Is not numeric";
                    return(response);
                }
                if (!DataCheck.IsNumeric(regObj.StopBatchId))
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Invalid Stop Batch Id";
                    response.Status.Message.TechnicalMessage = "Stop Batch Id Is not numeric";
                    return(response);
                }

                if ((int.Parse(regObj.StopBatchId) - int.Parse(regObj.StartBatchId)) + 1 != regObj.NumberOfBatches)
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Incorrect StopBatchId/StartBatchId/NumberOfBatches";
                    response.Status.Message.TechnicalMessage = "Incorrect StopBatchId/StartBatchId/NumberOfBatches";
                    return(response);
                }
                if (regObj.QuantityPerBatch < 1)
                {
                    response.Status.Message.FriendlyMessage  = "Error Occurred! Quantity Per Batch Is Required";
                    response.Status.Message.TechnicalMessage = "Error Occurred! Quantity Per Batch must be greater than zero!";
                    return(response);
                }
                //..................Continue here
                #region Batch Id Computation
                //var qtyPerBatchLength = regObj.QuantityPerBatch.
                #endregion

                //store date for Concurrency...
                var nowDateTime = DateMap.CurrentTimeStamp();
                var nowDate     = nowDateTime.Substring(0, nowDateTime.IndexOf(' '));
                var nowTime     = nowDateTime.Substring(nowDateTime.IndexOf('-') + 1);

                var cardItemList = new List <CardItem>();

                for (int i = int.Parse(regObj.StartBatchId); i < int.Parse(regObj.StopBatchId + 1); i++)
                {
                    cardItemList.Add(new CardItem
                    {
                        CardTypeId           = regObj.CardTypeId,
                        BatchId              = i.ToString(),
                        StartBatchNumber     = i.ToString() + "" + "000", //77001 000
                        StopBatchNumber      = i.ToString() + "" + "999", //77001999
                        DefectiveBatchNumber = "",
                        AvailableQuantity    = 0,
                        BatchQuantity        = 1000,
                        DeliveredQuantity    = 0,
                        MissingQuantity      = 0,
                        DefectiveQuantity    = 0,
                        IssuedQuantity       = 0,
                        RegisteredBy         = regObj.AdminUserId,
                        TimeStampRegisered   = nowDateTime,
                        TimeStampDelivered   = "",
                        TimeStampLastIssued  = "",
                        Status = CardStatus.Registered
                    });
                }

                var card = new Card
                {
                    CardTitle          = $"Card Production On {nowDate} At {nowTime}",
                    CardTypeId         = regObj.CardTypeId,
                    BatchKey           = regObj.BatchKey,
                    StartBatchId       = regObj.BatchKey + "000",
                    StopBatchId        = (Int32.Parse(regObj.BatchKey + "000") + (regObj.NumberOfBatches - 1)).ToString(),
                    NumberOfBatches    = regObj.NumberOfBatches,
                    QuantityPerBatch   = 1000,
                    TotalQuantity      = regObj.NumberOfBatches * regObj.QuantityPerBatch,
                    Status             = CardStatus.Registered,
                    TimeStampRegisered = nowDateTime,
                    CardItems          = cardItemList
                };

                var added = _repository.Add(card);
                _uoWork.SaveChanges();
                if (added.CardId < 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);
                }

                response.Status.IsSuccessful = true;
                response.CardId = added.CardId;
            }
            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);
        }