protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L2SH_SSSH_1313 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();

            //Put your code here
            var account = new ORM_USR_Account();
            account.Load(Connection, Transaction, securityTicket.AccountID);

            var statusPickingFinished = ORM_LOG_SHP_Shipment_Status.Query.Search(Connection, Transaction,
                                                                                 new ORM_LOG_SHP_Shipment_Status.Query()
            {
                GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(Parameter.ShipmentHeaderStatus),
                Tenant_RefID             = securityTicket.TenantID,
                IsDeleted = false
            }).Single();

            var shipmentStatusHistory = new CL1_LOG_SHP.ORM_LOG_SHP_Shipment_StatusHistory();
            shipmentStatusHistory.LOG_SHP_Shipment_Header_RefID         = Parameter.ShipmentHeaderID;
            shipmentStatusHistory.LOG_SHP_Shipment_Status_RefID         = statusPickingFinished.LOG_SHP_Shipment_StatusID;
            shipmentStatusHistory.PerformedBy_BusinessParticipant_RefID = account.BusinessParticipant_RefID;
            shipmentStatusHistory.Tenant_RefID = securityTicket.TenantID;
            shipmentStatusHistory.Save(Connection, Transaction);

            return(returnValue);

            #endregion UserCode
        }
Пример #2
0
		protected static FR_Guid Execute(DbConnection Connection,DbTransaction Transaction,P_L3CO_AO_1648 Parameter,CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null){
			//Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here
            var confirmedStatus = ORM_ORD_CUO_CustomerOrder_Status.Query.Search(Connection, Transaction,
            new ORM_ORD_CUO_CustomerOrder_Status.Query
            {
                GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(ECustomerOrderStatus.Confirmed),
                Tenant_RefID = securityTicket.TenantID,
                IsDeleted = false
            }).Single().ORD_CUO_CustomerOrder_StatusID;

            var customerOrder = new ORM_ORD_CUO_CustomerOrder_Header();
            customerOrder.Load(Connection, Transaction, Parameter.CustomerOrderHeaderID);
            customerOrder.Current_CustomerOrderStatus_RefID = confirmedStatus;
            customerOrder.IsCustomerOrderFinalized = true;
            customerOrder.WasAutoApprovedUponReceipt = Parameter.IsAutomaticallyApprovedOnReceipt;

            ORM_USR_Account account = new ORM_USR_Account();
            account.Load(Connection, Transaction, securityTicket.AccountID);

            ORM_ORD_CUO_CustomerOrder_StatusHistory newStatusInHistory = new ORM_ORD_CUO_CustomerOrder_StatusHistory();
            newStatusInHistory.CustomerOrder_Header_RefID = customerOrder.ORD_CUO_CustomerOrder_HeaderID;
            newStatusInHistory.StatusHistoryComment = Parameter.Message;
            newStatusInHistory.Tenant_RefID = securityTicket.TenantID;
            newStatusInHistory.CustomerOrder_Status_RefID = confirmedStatus;
            newStatusInHistory.PerformedBy_BusinessParticipant_RefID = account.BusinessParticipant_RefID;
            newStatusInHistory.Save(Connection, Transaction);

            returnValue.Result = new FR_Guid(customerOrder.Save(Connection, Transaction), customerOrder.ORD_CUO_CustomerOrder_HeaderID).Result;

            return returnValue;
            #endregion UserCode
		}
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5OF_SOfA_1652 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here

            var userAccount = new ORM_USR_Account();
            userAccount.Load(Connection, Transaction, Parameter.AccountID);

            //Get business participant for current user account
            var businessParticipantQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
            businessParticipantQuery.CMN_BPT_BusinessParticipantID = userAccount.BusinessParticipant_RefID;
            businessParticipantQuery.Tenant_RefID = securityTicket.TenantID;
            var foundBusinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, businessParticipantQuery).Single();

            //Get employee using business participant
            var employeeQuery = new ORM_CMN_BPT_EMP_Employee.Query();
            employeeQuery.BusinessParticipant_RefID = foundBusinessParticipant.CMN_BPT_BusinessParticipantID;
            employeeQuery.Tenant_RefID = securityTicket.TenantID;
            var foundEmployee = ORM_CMN_BPT_EMP_Employee.Query.Search(Connection, Transaction, employeeQuery).Single();

            //clear all assignment tables (connection with offices) for found employee before new save
            var assignmentQuery = new ORM_CMN_BPT_EMP_Employee_2_Office.Query();
            if (foundEmployee != null)
            {
                assignmentQuery.CMN_BPT_EMP_Employee_RefID = foundEmployee.CMN_BPT_EMP_EmployeeID;
                assignmentQuery.Tenant_RefID = securityTicket.TenantID;
            }
            else
            {
                return(new FR_Guid("Employee not created", FR_Status.Error_Internal));
            }

            var foundAssignments = ORM_CMN_BPT_EMP_Employee_2_Office.Query.Search(Connection, Transaction, assignmentQuery);

            foreach (var assignment in foundAssignments)
            {
                assignment.IsDeleted = true;
                assignment.Save(Connection, Transaction);
            }

            //save offices
            foreach (var office in Parameter.Offices)
            {
                P_L5OF_SSOfA_1652 officeSaveParam = new P_L5OF_SSOfA_1652();
                officeSaveParam.OfficeID   = office;
                officeSaveParam.EmployeeID = foundEmployee.CMN_BPT_EMP_EmployeeID;
                cls_Save_SingleOffice_for_Account.Invoke(Connection, Transaction, officeSaveParam, securityTicket);
            }

            return(returnValue);

            #endregion UserCode
        }
Пример #4
0
        protected static FR_Base Execute(DbConnection Connection, DbTransaction Transaction, P_L3US_SUAI_1642 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Base();
            returnValue.Status = FR_Status.Error_Internal;
            //Put your code here

            //EDIT
            if (Parameter.AccountID != null && Parameter.AccountID != Guid.Empty)
            {
                var item = new ORM_USR_Account();
                if (item.Load(Connection, Transaction, Parameter.AccountID) == null)
                {
                    returnValue.Status = FR_Status.Error_Internal;
                    return(returnValue);
                }

                ORM_CMN_PER_PersonInfo_2_Account.Query searchConnection = new CL1_CMN_PER.ORM_CMN_PER_PersonInfo_2_Account.Query();
                searchConnection.IsDeleted         = false;
                searchConnection.Tenant_RefID      = securityTicket.TenantID;
                searchConnection.USR_Account_RefID = Parameter.AccountID;

                ORM_CMN_PER_PersonInfo_2_Account personInfo2Account = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, searchConnection).FirstOrDefault();

                if (personInfo2Account != null)
                {
                    ORM_CMN_PER_PersonInfo PersonInfo = new ORM_CMN_PER_PersonInfo();
                    PersonInfo.Load(Connection, Transaction, personInfo2Account.CMN_PER_PersonInfo_RefID);

                    if (PersonInfo != null)
                    {
                        PersonInfo.FirstName = Parameter.FirstName;
                        PersonInfo.LastName  = Parameter.LastName;

                        PersonInfo.Save(Connection, Transaction);

                        returnValue.Status = FR_Status.Success;
                        return(returnValue);
                    }
                }
            }



            return(returnValue);

            #endregion UserCode
        }
Пример #5
0
        protected static FR_L5CO_RCO_2302_Array Execute(DbConnection Connection, DbTransaction Transaction, P_L5CO_RCO_2302[] Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5CO_RCO_2302_Array();
            List <L5CO_RCO_2302> rejectedOrders = new List <L5CO_RCO_2302>();
            foreach (var param in Parameter)
            {
                L5CO_RCO_2302 rejectedProcurementOrder = new L5CO_RCO_2302();
                var           orderedStatusID          = ORM_ORD_CUO_CustomerOrder_Status.Query.Search(Connection, Transaction,
                                                                                                       new ORM_ORD_CUO_CustomerOrder_Status.Query
                {
                    GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(ECustomerOrderStatus.Rejected),
                    Tenant_RefID             = securityTicket.TenantID,
                    IsDeleted = false
                }).SingleOrDefault().ORD_CUO_CustomerOrder_StatusID;

                var customerOrderQuery = new ORM_ORD_CUO_CustomerOrder_Header.Query();
                customerOrderQuery.ORD_CUO_CustomerOrder_HeaderID = param.CustomerOrderHeaderID;
                customerOrderQuery.Tenant_RefID = securityTicket.TenantID;
                var foundCustomerOrder = ORM_ORD_CUO_CustomerOrder_Header.Query.Search(Connection, Transaction, customerOrderQuery).SingleOrDefault();

                foundCustomerOrder.Current_CustomerOrderStatus_RefID = orderedStatusID;
                foundCustomerOrder.IsCustomerOrderFinalized          = true;
                foundCustomerOrder.Save(Connection, Transaction);
                ORM_USR_Account account = new ORM_USR_Account();
                account.Load(Connection, Transaction, securityTicket.AccountID);

                ORM_ORD_CUO_CustomerOrder_StatusHistory newStatusInHistory = new ORM_ORD_CUO_CustomerOrder_StatusHistory();
                newStatusInHistory.CustomerOrder_Header_RefID = foundCustomerOrder.ORD_CUO_CustomerOrder_HeaderID;
                newStatusInHistory.StatusHistoryComment       = param.Message;
                newStatusInHistory.Tenant_RefID = securityTicket.TenantID;
                newStatusInHistory.CustomerOrder_Status_RefID            = orderedStatusID;
                newStatusInHistory.PerformedBy_BusinessParticipant_RefID = account.BusinessParticipant_RefID;

                //saving new status in history and customer order header
                newStatusInHistory.Save(Connection, Transaction);
                rejectedProcurementOrder.ProcurementOrderITL = foundCustomerOrder.ProcurementOrderITL;
                rejectedProcurementOrder.ProcuringTenatID    = foundCustomerOrder.OrderingCustomer_BusinessParticipant_RefID.ToString();
                rejectedProcurementOrder.Message             = param.Message;
                rejectedOrders.Add(rejectedProcurementOrder);
            }
            returnValue.Result = rejectedOrders.ToArray();
            //Put your code here
            return(returnValue);

            #endregion UserCode
        }
Пример #6
0
        protected static FR_L5CA_GAGfSC_1456_Array Execute(DbConnection Connection, DbTransaction Transaction, P_L5CA_GAGfSC_1456 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_L5CA_GAGfSC_1456_Array();

            ORM_CMN_PRO_SubscribedCatalog.Query query = new ORM_CMN_PRO_SubscribedCatalog.Query();
            query.CMN_PRO_SubscribedCatalogID = Parameter.SubscribedCatalogID;
            query.Tenant_RefID = securityTicket.TenantID;
            query.IsDeleted    = false;
            ORM_CMN_PRO_SubscribedCatalog subscribedCatalog = ORM_CMN_PRO_SubscribedCatalog.Query.Search(Connection, Transaction, query).SingleOrDefault();
            if (subscribedCatalog != null && subscribedCatalog.CMN_PRO_SubscribedCatalogID == Parameter.SubscribedCatalogID)
            {
                string matching = subscribedCatalog.IsCatalogPublic ? EnumUtils.GetEnumDescription(EProductGroup.ABDA) : EnumUtils.GetEnumDescription(EProductGroup.HauseList);

                ORM_USR_Account.Query query2 = new ORM_USR_Account.Query();
                query2.USR_AccountID = securityTicket.AccountID;
                query2.Tenant_RefID  = securityTicket.TenantID;
                query2.IsDeleted     = false;
                ORM_USR_Account account = ORM_USR_Account.Query.Search(Connection, Transaction, query2).SingleOrDefault();
                if (account != null && account.USR_AccountID == query2.USR_AccountID)
                {
                    ORM_CMN_PRO_ProductGroup.Query query3 = new ORM_CMN_PRO_ProductGroup.Query();
                    query3.GlobalPropertyMatchingID = matching; //+ account.BusinessParticipant_RefID;
                    query3.Tenant_RefID             = securityTicket.TenantID;
                    query3.IsDeleted = false;

                    var productGroups = ORM_CMN_PRO_ProductGroup.Query.Search(Connection, Transaction, query3);

                    returnValue.Result = productGroups.Select(x =>
                                                              new L5CA_GAGfSC_1456
                    {
                        CMN_PRO_ProductGroupID   = x.CMN_PRO_ProductGroupID,
                        Parent_RefID             = x.Parent_RefID,
                        ProductGroup_Name        = x.ProductGroup_Name,
                        ProductGroup_Description = x.ProductGroup_Description
                    }
                                                              ).ToArray();
                }
            }

            return(returnValue);

            #endregion UserCode
        }
Пример #7
0
        protected static FR_Guids Execute(DbConnection Connection, DbTransaction Transaction, P_L3CO_SCONfH_1413 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guids();
            var results     = new List <Guid>();

            #region Get Account Bussiness participant id
            var resultAccount = new ORM_USR_Account();
            resultAccount.Load(Connection, Transaction, securityTicket.AccountID);
            #endregion

            foreach (var note in Parameter.Notes)
            {
                var result = cls_Save_ORD_CUO_CustomerOrder_Note.Invoke(
                    Connection
                    , Transaction
                    , new P_L2CO_SCON_1442()
                {
                    CustomerOrder_Header_RefID           = Parameter.CustomerOrderHeaderId,
                    CustomerOrder_Position_RefID         = note.CustomerOrderPositionId,
                    CMN_BPT_CTM_OrganizationalUnit_RefID = note.OrganizationslUnitId,
                    CreatedBy_BusinessParticipant_RefID  = resultAccount.BusinessParticipant_RefID,
                    Title               = note.Title,
                    Comment             = note.Comment,
                    NotePublishDate     = note.NotePublichDate,
                    SequenceOrderNumber = -1      // TODO:Marko - leve it empty, for now
                }
                    , securityTicket);
                if (result.Status != FR_Status.Success)
                {
                    returnValue.Status = FR_Status.Error_Internal;
                    returnValue.Result = null;
                    return(returnValue);
                }
                results.Add(result.Result);
            }
            returnValue.Status = FR_Status.Success;
            returnValue.Result = results.ToArray();

            return(returnValue);

            #endregion UserCode
        }
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L2BN_SBNfBH_1630 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here
            var account = new ORM_USR_Account();
            account.Load(Connection, Transaction, securityTicket.AccountID);

            var note = new CL1_BIL.ORM_BIL_Note();
            if (Parameter.NoteID != Guid.Empty)
            {
                var result = note.Load(Connection, Transaction, Parameter.NoteID);
            }
            else
            {
                note.Tenant_RefID       = securityTicket.TenantID;
                note.BIL_Note           = Guid.NewGuid();
                note.Creation_Timestamp = DateTime.Now;
                note.CreatedBy_BusinessParticipant_RefID = account.BusinessParticipant_RefID;
            }

            if (Parameter.IsDeleted == true)
            {
                note.IsDeleted = true;
                return(new FR_Guid(note.Save(Connection, Transaction), note.BIL_Note));
            }

            if (Parameter.BillHeaderID != Guid.Empty)
            {
                note.BillHeader_RefID = Parameter.BillHeaderID;
            }

            note.NoteText            = Parameter.NoteText == null ? String.Empty : Parameter.NoteText;
            note.Title               = Parameter.NoteTitle == null ? String.Empty : Parameter.NoteTitle;
            note.SequenceOrderNumber = Parameter.SequenceOrderNumber;
            note.Save(Connection, Transaction);

            returnValue.Result = note.BIL_Note;

            return(returnValue);

            #endregion UserCode
        }
Пример #9
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L3CO_RO_1101 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here
            var orderedStatusID = ORM_ORD_CUO_CustomerOrder_Status.Query.Search(Connection, Transaction,
                                                                                new ORM_ORD_CUO_CustomerOrder_Status.Query
            {
                GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(ECustomerOrderStatus.Rejected),
                Tenant_RefID             = securityTicket.TenantID,
                IsDeleted = false
            }).SingleOrDefault().ORD_CUO_CustomerOrder_StatusID;

            var customerOrderQuery = new ORM_ORD_CUO_CustomerOrder_Header.Query();
            customerOrderQuery.ORD_CUO_CustomerOrder_HeaderID = Parameter.CustomerOrderHeaderID;
            customerOrderQuery.Tenant_RefID = securityTicket.TenantID;
            var foundCustomerOrder = ORM_ORD_CUO_CustomerOrder_Header.Query.Search(Connection, Transaction, customerOrderQuery).SingleOrDefault();

            foundCustomerOrder.Current_CustomerOrderStatus_RefID = orderedStatusID;
            foundCustomerOrder.IsCustomerOrderFinalized          = true;

            ORM_USR_Account account = new ORM_USR_Account();
            account.Load(Connection, Transaction, securityTicket.AccountID);

            ORM_ORD_CUO_CustomerOrder_StatusHistory newStatusInHistory = new ORM_ORD_CUO_CustomerOrder_StatusHistory();
            newStatusInHistory.CustomerOrder_Header_RefID = foundCustomerOrder.ORD_CUO_CustomerOrder_HeaderID;
            newStatusInHistory.StatusHistoryComment       = Parameter.Message;
            newStatusInHistory.Tenant_RefID = securityTicket.TenantID;
            newStatusInHistory.CustomerOrder_Status_RefID            = orderedStatusID;
            newStatusInHistory.PerformedBy_BusinessParticipant_RefID = account.BusinessParticipant_RefID;

            //saving new status in history and customer order header
            newStatusInHistory.Save(Connection, Transaction);
            returnValue.Result = new FR_Guid(foundCustomerOrder.Save(Connection, Transaction), foundCustomerOrder.ORD_CUO_CustomerOrder_HeaderID).Result;

            return(returnValue);

            #endregion UserCode
        }
Пример #10
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L2P_SPN_1655 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here

            var account = new ORM_USR_Account();
            account.Load(Connection, Transaction, securityTicket.AccountID);

            var item = new CL1_CMN_PRO.ORM_CMN_PRO_Product_Note();
            if (Parameter.Product_NoteID != Guid.Empty)
            {
                var result = item.Load(Connection, Transaction, Parameter.Product_NoteID);
            }

            if (Parameter.IsDeleted == true)
            {
                item.IsDeleted = true;
                return(new FR_Guid(item.Save(Connection, Transaction), item.CMN_PRO_Product_NoteID));
            }

            //Creation specific parameters (Tenant, Account ... )
            if (Parameter.Product_NoteID == Guid.Empty)
            {
                item.Tenant_RefID = securityTicket.TenantID;

                item.CMN_PRO_Product_NoteID = Guid.NewGuid();
            }

            item.Product_RefID = Parameter.Product_RefID;
            item.IsImportant   = Parameter.IsImportant;
            item.NoteContent   = Parameter.NoteContent;
            item.CreatedBy_BusinessParticipant_RefID = account.BusinessParticipant_RefID;

            return(new FR_Guid(item.Save(Connection, Transaction), item.CMN_PRO_Product_NoteID));

            return(returnValue);

            #endregion UserCode
        }
Пример #11
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L2SH_SSN_1655 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();

            var account = new ORM_USR_Account();
            account.Load(Connection, Transaction, securityTicket.AccountID);

            var item = new CL1_LOG_SHP.ORM_LOG_SHP_Shipment_Note();
            if (Parameter.LOG_SHP_Shipment_NoteID != Guid.Empty)
            {
                var result = item.Load(Connection, Transaction, Parameter.LOG_SHP_Shipment_NoteID);
            }

            if (Parameter.IsDeleted == true)
            {
                item.IsDeleted = true;
                return(new FR_Guid(item.Save(Connection, Transaction), item.LOG_SHP_Shipment_NoteID));
            }

            //Creation specific parameters (Tenant, Account ... )
            if (Parameter.LOG_SHP_Shipment_NoteID == Guid.Empty)
            {
                item.Tenant_RefID = securityTicket.TenantID;
            }

            item.Shipment_Header_RefID        = Parameter.Shipment_Header_RefID;
            item.Shipment_Position_RefID      = Parameter.Shipment_Position_RefID;
            item.IsNotePrintedOnDeliveryPaper = Parameter.IsNotePrintedOnDeliveryPaper;
            item.Title               = Parameter.Title;
            item.Comment             = Parameter.Comment;
            item.NotePublishDate     = Parameter.NotePublishDate;
            item.SequenceOrderNumber = Parameter.SequenceOrderNumber;
            item.CreatedBy_BusinessParticipant_RefID = account.BusinessParticipant_RefID;

            return(new FR_Guid(item.Save(Connection, Transaction), item.LOG_SHP_Shipment_NoteID));

            #endregion UserCode
        }
        protected static FR_L5CO_ACOaCS_2108_Array Execute(DbConnection Connection, DbTransaction Transaction, P_L5CO_ACOaCS_2108[] Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5CO_ACOaCS_2108_Array();
            List <L5CO_ACOaCS_2108> confirmedProcurementOrders = new List <L5CO_ACOaCS_2108>();
            foreach (var param in Parameter)
            {
                L5CO_ACOaCS_2108 procurementOrderITL = new L5CO_ACOaCS_2108();
                var confirmedStatus = ORM_ORD_CUO_CustomerOrder_Status.Query.Search(Connection, Transaction,
                                                                                    new ORM_ORD_CUO_CustomerOrder_Status.Query
                {
                    GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(ECustomerOrderStatus.Confirmed),
                    Tenant_RefID             = securityTicket.TenantID,
                    IsDeleted = false
                }).Single().ORD_CUO_CustomerOrder_StatusID;

                var customerOrder = new ORM_ORD_CUO_CustomerOrder_Header();
                customerOrder.Load(Connection, Transaction, param.CustomerOrderHeaderID);
                customerOrder.Current_CustomerOrderStatus_RefID = confirmedStatus;
                customerOrder.IsCustomerOrderFinalized          = true;
                customerOrder.Save(Connection, Transaction);

                ORM_USR_Account account = new ORM_USR_Account();
                account.Load(Connection, Transaction, securityTicket.AccountID);

                ORM_ORD_CUO_CustomerOrder_StatusHistory newStatusInHistory = new ORM_ORD_CUO_CustomerOrder_StatusHistory();
                newStatusInHistory.CustomerOrder_Header_RefID = customerOrder.ORD_CUO_CustomerOrder_HeaderID;
                newStatusInHistory.StatusHistoryComment       = param.Message;
                newStatusInHistory.Tenant_RefID = securityTicket.TenantID;
                newStatusInHistory.CustomerOrder_Status_RefID            = confirmedStatus;
                newStatusInHistory.PerformedBy_BusinessParticipant_RefID = account.BusinessParticipant_RefID;
                newStatusInHistory.Save(Connection, Transaction);


                procurementOrderITL.ProcurementOrderITL = customerOrder.ProcurementOrderITL;
                procurementOrderITL.ProcuringTenatID    = customerOrder.OrderingCustomer_BusinessParticipant_RefID.ToString();



                ORM_CMN_NumberRange_UsageArea numberRangeUsageArea = ORM_CMN_NumberRange_UsageArea.Query.Search(Connection, Transaction, new ORM_CMN_NumberRange_UsageArea.Query()
                {
                    IsDeleted              = false,
                    Tenant_RefID           = securityTicket.TenantID,
                    GlobalStaticMatchingID = NumberRangeGlobalPropertyMatchingID
                }).FirstOrDefault();


                if (numberRangeUsageArea == null)
                {
                    throw new Exception(String.Format("Number range usage area with GPMID = {0} was not found.", NumberRangeGlobalPropertyMatchingID));
                }

                ORM_CMN_NumberRange numberRange = ORM_CMN_NumberRange.Query.Search(Connection, Transaction, new ORM_CMN_NumberRange.Query()
                {
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID,
                    NumberRange_UsageArea_RefID = numberRangeUsageArea.CMN_NumberRange_UsageAreaID
                }).FirstOrDefault();

                if (numberRange == null)
                {
                    throw new Exception(String.Format("Number range for area with GPMID = {0} was not found.", NumberRangeGlobalPropertyMatchingID));
                }

                numberRange.Value_Current++;
                numberRange.Save(Connection, Transaction);
                string shipmentNumber = numberRange.FixedPrefix + numberRange.Value_Current.ToString().PadLeft(numberRange.Formatting_NumberLength, numberRange.Formatting_LeadingFillCharacter[0]);

                ORM_LOG_SHP_Shipment_Header shipmentHeader = new ORM_LOG_SHP_Shipment_Header();
                shipmentHeader.LOG_SHP_Shipment_HeaderID          = Guid.NewGuid();
                shipmentHeader.RecipientBusinessParticipant_RefID = customerOrder.OrderingCustomer_BusinessParticipant_RefID;
                shipmentHeader.ShipmentHeaderITL              = shipmentHeader.LOG_SHP_Shipment_HeaderID.ToString();
                shipmentHeader.ShipmentHeader_Number          = shipmentNumber;
                shipmentHeader.Shippipng_AddressUCD_RefID     = customerOrder.ShippingAddressUCD_RefID;
                shipmentHeader.ShipmentPriority               = 0;
                shipmentHeader.ShipmentHeader_ValueWithoutTax = customerOrder.TotalValue_BeforeTax;
                shipmentHeader.ShipmentHeader_Currency_RefID  = customerOrder.CustomerOrder_Currency_RefID;
                shipmentHeader.Tenant_RefID = securityTicket.TenantID;
                shipmentHeader.IsDeleted    = false;
                shipmentHeader.Save(Connection, Transaction);

                var customerOrderPositions = ORM_ORD_CUO_CustomerOrder_Position.Query.Search(Connection, Transaction, new ORM_ORD_CUO_CustomerOrder_Position.Query()
                {
                    CustomerOrder_Header_RefID = customerOrder.ORD_CUO_CustomerOrder_HeaderID,
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID
                });

                if (customerOrderPositions != null)
                {
                    foreach (var customerOrderPosition in customerOrderPositions)
                    {
                        ORM_LOG_SHP_Shipment_Position shipmentPosition = new ORM_LOG_SHP_Shipment_Position();
                        shipmentPosition.LOG_SHP_Shipment_PositionID   = Guid.NewGuid();
                        shipmentPosition.ShipmentPositionITL           = shipmentPosition.LOG_SHP_Shipment_PositionID.ToString();
                        shipmentPosition.LOG_SHP_Shipment_Header_RefID = shipmentHeader.LOG_SHP_Shipment_HeaderID;
                        shipmentPosition.CMN_PRO_Product_RefID         = customerOrderPosition.CMN_PRO_Product_RefID;
                        shipmentPosition.CMN_PRO_ProductVariant_RefID  = customerOrderPosition.CMN_PRO_Product_Variant_RefID;
                        shipmentPosition.CMN_PRO_ProductRelease_RefID  = customerOrderPosition.CMN_PRO_Product_Release_RefID;
                        shipmentPosition.QuantityToShip = customerOrderPosition.Position_Quantity;
                        shipmentPosition.ShipmentPosition_PricePerUnitValueWithoutTax = customerOrderPosition.Position_ValuePerUnit;
                        shipmentPosition.ShipmentPosition_ValueWithoutTax             = customerOrderPosition.Position_ValueTotal;
                        shipmentPosition.IsCancelled  = false;
                        shipmentPosition.Tenant_RefID = securityTicket.TenantID;
                        shipmentPosition.IsDeleted    = false;
                        shipmentPosition.Save(Connection, Transaction);
                        ORM_ORD_CUO_CustomerOrder_Position_2_ShipmentPosition customerOrderPositionToShipmentPosition = new ORM_ORD_CUO_CustomerOrder_Position_2_ShipmentPosition();
                        customerOrderPositionToShipmentPosition.AssignmentID = Guid.NewGuid();
                        customerOrderPositionToShipmentPosition.LOG_SHP_Shipment_Position_RefID      = shipmentPosition.LOG_SHP_Shipment_PositionID;
                        customerOrderPositionToShipmentPosition.ORD_CUO_CustomerOrder_Position_RefID = customerOrderPosition.ORD_CUO_CustomerOrder_PositionID;
                        customerOrderPositionToShipmentPosition.Tenant_RefID = securityTicket.TenantID;
                        customerOrderPositionToShipmentPosition.IsDeleted    = false;
                        customerOrderPositionToShipmentPosition.Save(Connection, Transaction);
                    }
                }


                //TO DO: UNCOMMENT AFTER JANKO ADD STATUSES
                //var shipmentStatusHistoryStatusID = ORM_LOG_SHP_Shipment_Status.Query.Search(Connection, Transaction, new ORM_LOG_SHP_Shipment_Status.Query()
                //{
                //    GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(EShipmentStatus.Created),
                //    Tenant_RefID = securityTicket.TenantID,
                //    IsDeleted = false
                //}).Single().LOG_SHP_Shipment_StatusID;

                //ORM_LOG_SHP_Shipment_StatusHistory shipmentStatusHistory = new ORM_LOG_SHP_Shipment_StatusHistory();
                //shipmentStatusHistory.LOG_SHP_Shipment_StatusHistoryID = Guid.NewGuid();
                //shipmentStatusHistory.LOG_SHP_Shipment_Header_RefID = shipmentHeader.LOG_SHP_Shipment_HeaderID;
                //shipmentStatusHistory.LOG_SHP_Shipment_Status_RefID = shipmentStatusHistoryStatusID;
                //shipmentStatusHistory.PerformedBy_BusinessParticipant_RefID = securityTicket.TenantID;
                //shipmentStatusHistory.Tenant_RefID = securityTicket.TenantID;
                //shipmentStatusHistory.IsDeleted = false;
                //shipmentStatusHistory.Save(Connection, Transaction);

                ORM_LOG_SHP_ShipmentHeader_2_CustomerOrderHeader shipmentToCustomerOrderHeader = new ORM_LOG_SHP_ShipmentHeader_2_CustomerOrderHeader();
                shipmentToCustomerOrderHeader.AssignmentID = Guid.NewGuid();
                shipmentToCustomerOrderHeader.LOG_SHP_Shipment_Header_RefID      = shipmentHeader.LOG_SHP_Shipment_HeaderID;
                shipmentToCustomerOrderHeader.ORD_CUO_CustomerOrder_Header_RefID = customerOrder.ORD_CUO_CustomerOrder_HeaderID;
                shipmentToCustomerOrderHeader.Tenant_RefID = securityTicket.TenantID;
                shipmentToCustomerOrderHeader.IsDeleted    = false;
                shipmentToCustomerOrderHeader.Save(Connection, Transaction);


                confirmedProcurementOrders.Add(procurementOrderITL);
            }
            returnValue.Result = confirmedProcurementOrders.ToArray();
            return(returnValue);

            #endregion UserCode
        }
Пример #13
0
        protected static FR_Guids Execute(DbConnection Connection, DbTransaction Transaction, P_CAS_SCME_1741 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guids();
            //Put your code here


            ORM_CMN_Language.Query all_languagesQ = new ORM_CMN_Language.Query();
            all_languagesQ.Tenant_RefID = securityTicket.TenantID;
            all_languagesQ.IsDeleted    = false;

            var all_languagesL = ORM_CMN_Language.Query.Search(Connection, Transaction, all_languagesQ).ToArray();

            var treatment_doctor_details = cls_Get_Doctor_Details_for_DoctorID.Invoke(Connection, Transaction, new P_DO_GDDfDID_0823()
            {
                DoctorID = Parameter.treatment_doctor_id
            }, securityTicket).Result.SingleOrDefault();
            var aftercare_doctor_details = cls_Get_Doctor_Details_for_DoctorID.Invoke(Connection, Transaction, new P_DO_GDDfDID_0823()
            {
                DoctorID = Parameter.aftercare_doctor_id
            }, securityTicket).Result.SingleOrDefault();
            var aftercare_practice_details = cls_Get_Practice_Details_for_PracticeID.Invoke(Connection, Transaction, new P_DO_GPDfPID_1432()
            {
                PracticeID = Parameter.aftercare_doctor_id
            }, securityTicket).Result.FirstOrDefault();
            List <string> aftercare_ids           = new List <string>();
            List <string> withdrawn_aftercare_ids = new List <string>();
            List <string> new_aftercare_ids       = new List <string>();

            ORM_USR_Account treatment_doctor_account = null;
            if (Parameter.treatment_doctor_id != Guid.Empty)
            {
                treatment_doctor_account = ORM_USR_Account.Query.Search(Connection, Transaction, new ORM_USR_Account.Query()
                {
                    USR_AccountID = cls_Get_Doctor_AccountID_for_DoctorID.Invoke(Connection, Transaction, new P_DO_GDAIDfDID_1549()
                    {
                        DoctorID = Parameter.treatment_doctor_id
                    }, securityTicket).Result.accountID,
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false
                }).SingleOrDefault();
            }

            ORM_USR_Account aftercare_doctor_account = null;
            if (Parameter.aftercare_doctor_id != Guid.Empty)
            {
                if (aftercare_doctor_details != null)
                {
                    aftercare_doctor_account = ORM_USR_Account.Query.Search(Connection, Transaction, new ORM_USR_Account.Query()
                    {
                        USR_AccountID = cls_Get_Doctor_AccountID_for_DoctorID.Invoke(Connection, Transaction, new P_DO_GDAIDfDID_1549()
                        {
                            DoctorID = Parameter.aftercare_doctor_id
                        }, securityTicket).Result.accountID,
                        Tenant_RefID = securityTicket.TenantID,
                        IsDeleted    = false
                    }).SingleOrDefault();
                }
                else
                {
                    aftercare_doctor_account = ORM_USR_Account.Query.Search(Connection, Transaction, new ORM_USR_Account.Query()
                    {
                        USR_AccountID = cls_Get_Practice_AccountID_for_PracticeID.Invoke(Connection, Transaction, new P_DO_GPAIDfPID_1351()
                        {
                            PracticeID = Parameter.aftercare_doctor_id
                        }, securityTicket).Result.accountID,
                        Tenant_RefID = securityTicket.TenantID,
                        IsDeleted    = false
                    }).SingleOrDefault();
                }
            }

            foreach (var case_id in Parameter.case_ids)
            {
                if (treatment_doctor_details != null && Parameter.is_treatment)
                {
                    #region UPDATE TREATMENT DOCTOR
                    var treatment_planned_action_id = cls_Get_Treatment_Planned_Action_for_CaseID.Invoke(Connection, Transaction, new P_CAS_GTPAfCID_0946()
                    {
                        CaseID = case_id
                    }, securityTicket).Result;
                    if (treatment_planned_action_id != null)
                    {
                        var treatment_planned_action = ORM_HEC_ACT_PlannedAction.Query.Search(Connection, Transaction, new ORM_HEC_ACT_PlannedAction.Query()
                        {
                            HEC_ACT_PlannedActionID = treatment_planned_action_id.planned_action_id,
                            Tenant_RefID            = securityTicket.TenantID,
                            IsDeleted   = false,
                            IsCancelled = false
                        }).SingleOrDefault();

                        if (treatment_planned_action != null)
                        {
                            treatment_planned_action.Modification_Timestamp = DateTime.Now;
                            treatment_planned_action.ToBePerformedBy_BusinessParticipant_RefID = treatment_doctor_account.BusinessParticipant_RefID;

                            treatment_planned_action.Save(Connection, Transaction);
                        }
                    }
                    #endregion
                }

                #region UPDATE AFTERCARE DOCTOR
                if (!string.IsNullOrEmpty(Parameter.aftercare_performed_date) || aftercare_doctor_details != null || aftercare_practice_details != null)
                {
                    var aftercare_planned_action_id = cls_Get_Aftercare_Planned_Action_for_CaseID.Invoke(Connection, Transaction, new P_CAS_GAPAfCID_0959()
                    {
                        CaseID = case_id
                    }, securityTicket).Result;
                    if (aftercare_planned_action_id != null)
                    {
                        aftercare_ids.Add(aftercare_planned_action_id.planned_action_id.ToString());
                        if (aftercare_doctor_details != null || aftercare_practice_details != null)
                        {
                            var aftercare_planned_action = ORM_HEC_ACT_PlannedAction.Query.Search(Connection, Transaction, new ORM_HEC_ACT_PlannedAction.Query()
                            {
                                HEC_ACT_PlannedActionID = aftercare_planned_action_id.planned_action_id,
                                Tenant_RefID            = securityTicket.TenantID,
                                IsDeleted   = false,
                                IsCancelled = false
                            }).SingleOrDefault();

                            if (aftercare_planned_action != null)
                            {
                                if (aftercare_planned_action.ToBePerformedBy_BusinessParticipant_RefID != Guid.Empty)
                                {
                                    if (aftercare_doctor_account.BusinessParticipant_RefID != aftercare_planned_action.ToBePerformedBy_BusinessParticipant_RefID)
                                    {
                                        bool is_current_aftercare_practice = false;
                                        CAS_GPIDfPBPTID_1336 current_aftercare_practice = null;
                                        var current_aftercare_doctor = cls_Get_PracticeID_for_Doctor_BusinessParticipantID.Invoke(
                                            Connection,
                                            Transaction,
                                            new P_CAS_GPIDfDBPTID_1205()
                                        {
                                            BusinessParticipantID = aftercare_planned_action.ToBePerformedBy_BusinessParticipant_RefID
                                        },
                                            securityTicket).Result;

                                        if (current_aftercare_doctor == null)
                                        {
                                            current_aftercare_practice = cls_Get_PracticeID_for_Practice_BusinessParticipantID.Invoke(Connection, Transaction, new P_CAS_GPIDfPBPTID_1336()
                                            {
                                                BusinessParticipantID = aftercare_planned_action.ToBePerformedBy_BusinessParticipant_RefID
                                            }, securityTicket).Result;
                                            is_current_aftercare_practice = true;
                                        }

                                        var new_aftercare_practice_id     = aftercare_doctor_details != null ? aftercare_doctor_details.practice_id : aftercare_practice_details.practiceID;
                                        var current_aftercare_practice_id = is_current_aftercare_practice ? current_aftercare_practice.practice_id : current_aftercare_doctor.practice_id;

                                        if (new_aftercare_practice_id != current_aftercare_practice_id)
                                        {
                                            aftercare_planned_action.IsCancelled            = true;
                                            aftercare_planned_action.Modification_Timestamp = DateTime.Now;
                                            aftercare_planned_action.Save(Connection, Transaction);

                                            withdrawn_aftercare_ids.Add(aftercare_planned_action.HEC_ACT_PlannedActionID.ToString());

                                            #region NEW AFTERCARE PLANNED ACTION

                                            #region DELETE CURRENT PLANNED ACTION TO CASE
                                            ORM_HEC_CAS_Case_RelevantPlannedAction.Query current_aftercare_action_2_caseQ = new ORM_HEC_CAS_Case_RelevantPlannedAction.Query();
                                            current_aftercare_action_2_caseQ.Case_RefID          = case_id;
                                            current_aftercare_action_2_caseQ.PlannedAction_RefID = aftercare_planned_action_id.planned_action_id;
                                            current_aftercare_action_2_caseQ.Tenant_RefID        = securityTicket.TenantID;
                                            current_aftercare_action_2_caseQ.IsDeleted           = false;

                                            var current_aftercare_action_2_case = ORM_HEC_CAS_Case_RelevantPlannedAction.Query.Search(Connection, Transaction, current_aftercare_action_2_caseQ).SingleOrDefault();
                                            if (current_aftercare_action_2_case != null)
                                            {
                                                current_aftercare_action_2_case.IsDeleted = true;
                                                current_aftercare_action_2_case.Save(Connection, Transaction);
                                            }
                                            #endregion

                                            var new_aftercare_id = cls_Create_Aftercare_Planned_Action.Invoke(Connection, Transaction, new P_CAS_CAPA_1237()
                                            {
                                                aftercare_doctor_practice_id = Parameter.aftercare_doctor_id,
                                                all_languagesL = all_languagesL,
                                                case_id        = case_id,
                                                patient_id     = aftercare_planned_action.Patient_RefID,
                                                practice_id    = Parameter.practice_id,
                                                treatment_date = string.IsNullOrEmpty(Parameter.aftercare_performed_date) ? DateTime.Now : DateTime.ParseExact(Parameter.aftercare_performed_date, "dd.MM.yyyy", new System.Globalization.CultureInfo("de", true))
                                            }, securityTicket).Result;

                                            new_aftercare_ids.Add(new_aftercare_id.ToString());

                                            #endregion NEW AFTERCARE PLANNED ACTION
                                        }
                                        else
                                        {
                                            aftercare_planned_action.Modification_Timestamp = DateTime.Now;
                                            aftercare_planned_action.ToBePerformedBy_BusinessParticipant_RefID = aftercare_doctor_account.BusinessParticipant_RefID;

                                            aftercare_planned_action.Save(Connection, Transaction);
                                        }
                                    }
                                }
                                else
                                {
                                    aftercare_planned_action.Modification_Timestamp = DateTime.Now;
                                    aftercare_planned_action.ToBePerformedBy_BusinessParticipant_RefID = aftercare_doctor_account.BusinessParticipant_RefID;

                                    aftercare_planned_action.Save(Connection, Transaction);
                                }
                            }
                        }
                    }
                    else
                    {
                        var treatment_planned_action_id = cls_Get_Treatment_Planned_Action_for_CaseID.Invoke(Connection, Transaction, new P_CAS_GTPAfCID_0946()
                        {
                            CaseID = case_id
                        }, securityTicket).Result;
                        if (treatment_planned_action_id != null)
                        {
                            var treatment_planned_action = ORM_HEC_ACT_PlannedAction.Query.Search(Connection, Transaction, new ORM_HEC_ACT_PlannedAction.Query()
                            {
                                HEC_ACT_PlannedActionID = treatment_planned_action_id.planned_action_id,
                                Tenant_RefID            = securityTicket.TenantID,
                                IsDeleted   = false,
                                IsCancelled = false
                            }).SingleOrDefault();

                            var result = cls_Create_Aftercare_Planned_Action.Invoke(Connection, Transaction, new P_CAS_CAPA_1237()
                            {
                                aftercare_doctor_practice_id = Parameter.aftercare_doctor_id,
                                all_languagesL = ORM_CMN_Language.Query.Search(Connection, Transaction, new ORM_CMN_Language.Query()
                                {
                                    Tenant_RefID = securityTicket.TenantID, IsDeleted = false
                                }).ToArray(),
                                case_id        = case_id,
                                patient_id     = treatment_planned_action.Patient_RefID,
                                practice_id    = aftercare_doctor_details != null ? aftercare_doctor_details.practice_id : Parameter.aftercare_doctor_id,
                                treatment_date = treatment_planned_action.PlannedFor_Date
                            }, securityTicket);

                            aftercare_ids.Add(result.Result.ToString());
                        }
                    }
                }
                #endregion
            }

            #region UPDATE LAST USED AFTERCARES
            if (aftercare_doctor_details != null || aftercare_practice_details != null)
            {
                var aftercare_name = aftercare_doctor_details == null ? aftercare_practice_details.practice_name :
                                     GenericUtils.GetDoctorName(aftercare_doctor_details);

                var ac_practice_id = aftercare_doctor_details != null ? aftercare_doctor_details.practice_id : aftercare_practice_details.practiceID;

                var last_used_practices_doctors = Get_Practices_and_Doctors.Get_Last_Used_Doctors_Practices(Guid.Empty, securityTicket);
                if (last_used_practices_doctors.Count != 0)
                {
                    last_used_practices_doctors = last_used_practices_doctors.OrderBy(l => l.date_of_use).ToList();
                    var last_used = last_used_practices_doctors.SingleOrDefault(l => l.id.ToLower().Equals(Parameter.aftercare_doctor_id.ToString().ToLower()));
                    if (last_used != null)
                    {
                        last_used.date_of_use = DateTime.Now;
                    }
                    else
                    {
                        Practice_Doctor_Last_Used_Model practice_last_used_model = new Practice_Doctor_Last_Used_Model();
                        practice_last_used_model.id           = Parameter.aftercare_doctor_id.ToString();
                        practice_last_used_model.display_name = aftercare_name;
                        practice_last_used_model.date_of_use  = DateTime.Now;
                        practice_last_used_model.practice_id  = ac_practice_id.ToString();

                        last_used_practices_doctors.Add(practice_last_used_model);
                    }
                }
                else
                {
                    Practice_Doctor_Last_Used_Model practice_last_used_model = new Practice_Doctor_Last_Used_Model();
                    practice_last_used_model.id           = Parameter.aftercare_doctor_id.ToString();
                    practice_last_used_model.display_name = aftercare_name;
                    practice_last_used_model.date_of_use  = DateTime.Now;
                    practice_last_used_model.practice_id  = ac_practice_id.ToString();

                    last_used_practices_doctors.Add(practice_last_used_model);
                }

                Add_New_Practice_Last_Used.Import_Practice_Last_Used_Data_to_ElasticDB(last_used_practices_doctors, securityTicket.TenantID.ToString(), securityTicket.AccountID.ToString());

                last_used_practices_doctors = Get_Practices_and_Doctors.Get_Last_Used_Doctors_Practices(Guid.Empty, securityTicket);

                if (last_used_practices_doctors.Count() > 3)
                {
                    var id_to_delete = last_used_practices_doctors.OrderBy(pd => pd.date_of_use).First().id;
                    Add_New_Practice_Last_Used.Delete_Practice_Last_Used(securityTicket.TenantID.ToString(), "user_" + securityTicket.AccountID.ToString(), id_to_delete);
                }
            }
            #endregion

            returnValue.Result = Parameter.case_ids;
            return(returnValue);

            #endregion UserCode
        }
Пример #14
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5US_SSU_1847 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();

            var userAccount = new ORM_USR_Account();
            var result      = userAccount.Load(Connection, Transaction, Parameter.USR_AccountID);

            if (result.Status == FR_Status.Success)
            {
                //Get business participant via userAccount
                var businessParticipant = new ORM_CMN_BPT_BusinessParticipant();
                businessParticipant.Load(Connection, Transaction, userAccount.BusinessParticipant_RefID);

                //Load person
                var personInfo = new ORM_CMN_PER_PersonInfo();
                personInfo.Load(Connection, Transaction, businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID);

                //Load communication contacts for person
                P_L2CN_GCCfPI_1222 contactsParam = new P_L2CN_GCCfPI_1222();
                contactsParam.PersonInfoID = personInfo.CMN_PER_PersonInfoID;
                var contactsForPersonInfo = cls_Get_ComunicationContacts_for_PersonInfoID.Invoke(Connection, Transaction, contactsParam, securityTicket).Result.ToList();

                if (!Parameter.IsInitialSave)
                {
                    if (Parameter.IsDeleted)
                    {
                        #region Delete

                        var queryApplicationSubscription = new ORM_CMN_Account_ApplicationSubscription.Query();
                        queryApplicationSubscription.Application_RefID = Parameter.ApplicationID;
                        queryApplicationSubscription.Account_RefID     = userAccount.USR_AccountID;
                        queryApplicationSubscription.Tenant_RefID      = securityTicket.TenantID;

                        var foundApplicationSubscription = ORM_CMN_Account_ApplicationSubscription.Query.SoftDelete(Connection, Transaction, queryApplicationSubscription);

                        return(new FR_Guid(FR_Base.Status_OK, userAccount.USR_AccountID));

                        #endregion
                    }

                    #region Edit


                    personInfo.FirstName = Parameter.FirstName_ContactPerson;
                    personInfo.LastName  = Parameter.LastName_ContactPerson;
                    personInfo.Save(Connection, Transaction);

                    var employeeTemp = ORM_CMN_BPT_EMP_Employee.Query.Search(Connection, Transaction, new ORM_CMN_BPT_EMP_Employee.Query()
                    {
                        BusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID,
                        Tenant_RefID = securityTicket.TenantID,
                        IsDeleted    = false
                    }).SingleOrDefault();

                    if (employeeTemp == null)
                    {
                        var newEmployee = new ORM_CMN_BPT_EMP_Employee();
                        newEmployee.CMN_BPT_EMP_EmployeeID    = Guid.NewGuid();
                        newEmployee.BusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID;
                        newEmployee.StandardFunction          = "APOAdminEmployee";
                        newEmployee.Tenant_RefID = securityTicket.TenantID;
                        newEmployee.Save(Connection, Transaction);
                    }


                    var address = new ORM_CMN_Address();
                    address.Load(Connection, Transaction, personInfo.Address_RefID);
                    address.Street_Name     = Parameter.Street_Name;
                    address.Street_Number   = Parameter.Street_Number;
                    address.City_Name       = Parameter.Town;
                    address.City_PostalCode = Parameter.ZIP;
                    address.Save(Connection, Transaction);


                    try
                    {
                        //telephone
                        var telephone = contactsForPersonInfo.Where(i => i.Type == EnumUtils.GetEnumDescription(EComunactionContactType.Phone))
                                        .First().Contacts;

                        if (telephone.Count() == 1)
                        {
                            var contactID = telephone[0].CMN_PER_CommunicationContactID;

                            var contactTelephone = new ORM_CMN_PER_CommunicationContact();
                            contactTelephone.Load(Connection, Transaction, contactID);
                            contactTelephone.Content = Parameter.Contact_Telephone;
                            contactTelephone.Save(Connection, Transaction);
                        }
                    }
                    catch
                    {
                        //Log this
                    }

                    #region CommentedUsefull-PreviousWayOfContactEmailHandling

                    //try
                    //{
                    //    //email
                    //    var email = contactsForPersonInfo.Where(i => i.Type == EnumUtils.GetEnumDescription(EComunactionContactType.Email))
                    //        .First().Contacts;

                    //    if (email.Count() == 1)
                    //    {
                    //        var contactID = email[0].CMN_PER_CommunicationContactID;

                    //        var contactEmail = new ORM_CMN_PER_CommunicationContact();
                    //        contactEmail.Load(Connection, Transaction, contactID);
                    //        contactEmail.Content = Parameter.Contact_Email;
                    //        contactEmail.Save(Connection, Transaction);
                    //    }

                    //}
                    //catch
                    //{

                    //    //Log this
                    //}

                    #endregion

                    #endregion
                }

                #region SaveGroup

                var userAccountToGroup = ORM_USR_Account_2_Group.Query.Search(Connection, Transaction, new ORM_USR_Account_2_Group.Query()
                {
                    USR_Account_RefID = userAccount.USR_AccountID,
                    Tenant_RefID      = securityTicket.TenantID,
                    IsDeleted         = false
                }).SingleOrDefault();


                if (userAccountToGroup == null)
                {
                    var newGroup = new ORM_USR_Account_2_Group();
                    newGroup.AssignmentID       = Guid.NewGuid();
                    newGroup.USR_Account_RefID  = userAccount.USR_AccountID;
                    newGroup.USR_Group_RefID    = Parameter.USR_GroupID;
                    newGroup.Creation_Timestamp = DateTime.Now;
                    newGroup.Tenant_RefID       = securityTicket.TenantID;
                    newGroup.Save(Connection, Transaction);
                }
                else
                {
                    userAccountToGroup.USR_Group_RefID = Parameter.USR_GroupID;
                    userAccountToGroup.Save(Connection, Transaction);
                }

                #endregion

                #region SaveEmployee

                var employee = ORM_CMN_BPT_EMP_Employee.Query.Search(Connection, Transaction, new ORM_CMN_BPT_EMP_Employee.Query()
                {
                    BusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID,
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false
                }).SingleOrDefault();

                if (employee == null)
                {
                    var newEmployee = new ORM_CMN_BPT_EMP_Employee();
                    newEmployee.CMN_BPT_EMP_EmployeeID    = Guid.NewGuid();
                    newEmployee.BusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID;
                    newEmployee.StandardFunction          = "APOAdminEmployee";
                    newEmployee.Tenant_RefID = securityTicket.TenantID;
                    newEmployee.Save(Connection, Transaction);
                }

                #endregion

                #region CreateOrUpdateContactEmail

                var emailTypeProperty     = EnumUtils.GetEnumDescription(EComunactionContactType.Email);
                var contactEmailTypeQuery = new ORM_CMN_PER_CommunicationContact_Type.Query();
                contactEmailTypeQuery.Type         = emailTypeProperty;
                contactEmailTypeQuery.Tenant_RefID = securityTicket.TenantID;
                var contactEmailType = ORM_CMN_PER_CommunicationContact_Type.Query.Search(Connection, Transaction, contactEmailTypeQuery).FirstOrDefault();

                //Search for default contact email and create it if don't exist

                var defaultContactEmailQuery = new ORM_CMN_PER_CommunicationContact.Query();
                defaultContactEmailQuery.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                defaultContactEmailQuery.Contact_Type     = contactEmailType.CMN_PER_CommunicationContact_TypeID;
                defaultContactEmailQuery.Tenant_RefID     = securityTicket.TenantID;
                var defaultContactEmail = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, defaultContactEmailQuery).FirstOrDefault();

                if (defaultContactEmail == null)
                {
                    defaultContactEmail = new ORM_CMN_PER_CommunicationContact();
                    defaultContactEmail.PersonInfo_RefID        = personInfo.CMN_PER_PersonInfoID;
                    defaultContactEmail.Contact_Type            = contactEmailType.CMN_PER_CommunicationContact_TypeID;
                    defaultContactEmail.IsDefaultForContactType = true;
                    defaultContactEmail.Tenant_RefID            = securityTicket.TenantID;
                }

                defaultContactEmail.Content = Parameter.Contact_Email;
                defaultContactEmail.IsDefaultForContactType = true;
                defaultContactEmail.Save(Connection, Transaction);

                #endregion
            }
            else
            {
                FR_Guid error = new FR_Guid();
                error.ErrorMessage = "No Such ID.";
                error.Status       = FR_Status.Error_Internal;
                return(error);
            }

            return(new FR_Guid(FR_Base.Status_OK, userAccount.USR_AccountID));

            #endregion UserCode
        }
        protected static FR_L5CA_PNCV_1603 Execute(DbConnection Connection, DbTransaction Transaction, P_L5CA_PNCV_1603 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5CA_PNCV_1603();
            returnValue.Result = new L5CA_PNCV_1603();

            var account = new ORM_USR_Account();
            account.Load(Connection, Transaction, securityTicket.AccountID);

            #region Update active catalog revision

            ORM_CMN_PRO_Catalog_Revision rev = new ORM_CMN_PRO_Catalog_Revision();
            rev.Load(Connection, Transaction, Parameter.CMN_PRO_Catalog_RevisionID);
            rev.Valid_From    = Parameter.Valid_From;
            rev.Valid_Through = Parameter.Valid_Through;
            rev.Default_PricelistRelease_RefID        = Parameter.Default_PricelistRelease_RefID;
            rev.PublishedBy_BusinessParticipant_RefID = account.BusinessParticipant_RefID;
            rev.PublishedOn_Date = DateTime.Now;

            rev.Save(Connection, Transaction);

            #endregion

            #region Create new catalog revision

            ORM_CMN_PRO_Catalog_Revision newRev = new ORM_CMN_PRO_Catalog_Revision();
            newRev.CMN_PRO_Catalog_RevisionID = Guid.NewGuid();
            newRev.CMN_PRO_Catalog_RefID      = rev.CMN_PRO_Catalog_RefID;
            newRev.Tenant_RefID                = securityTicket.TenantID;
            newRev.Creation_Timestamp          = DateTime.Now;
            newRev.CatalogRevision_Description = "Revision for Catalog";
            newRev.CatalogRevision_Name        = "New Catalog Revision";
            newRev.IsDeleted      = false;
            newRev.RevisionNumber = rev.RevisionNumber + 1;
            newRev.Save(Connection, Transaction);

            #endregion


            #region Products

            var oldProducts = ORM_CMN_PRO_Catalog_Product.Query.Search(Connection, Transaction, new ORM_CMN_PRO_Catalog_Product.Query()
            {
                CMN_PRO_Catalog_Revision_RefID = rev.CMN_PRO_Catalog_RevisionID,
                IsDeleted = false
            });

            if (oldProducts.Count == 0)
            {
                returnValue.Result.Status_Code    = -1;     // -1 no products in revision
                returnValue.Result.Status_Message = "no products in revision";
                return(returnValue);
            }

            //oldProductID - newProductID
            Dictionary <Guid, Guid> productsMapping = new Dictionary <Guid, Guid>();

            foreach (var item in oldProducts)
            {
                ORM_CMN_SLS_Pricelist_Release plr = new ORM_CMN_SLS_Pricelist_Release();
                plr.Load(Connection, Transaction, Parameter.Default_PricelistRelease_RefID);

                var pricelistPriceQry = new ORM_CMN_SLS_Price.Query()
                {
                    CMN_PRO_Product_RefID  = item.CMN_PRO_Product_RefID,
                    PricelistRelease_RefID = plr.CMN_SLS_Pricelist_ReleaseID,
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID
                };

                var prices = ORM_CMN_SLS_Price.Query.Search(Connection, Transaction, pricelistPriceQry);
                if (prices.Count == 0)
                {
                    ORM_CMN_PRO_Product pr = new ORM_CMN_PRO_Product();
                    pr.Load(Connection, Transaction, item.CMN_PRO_Product_RefID);
                    returnValue.Result.Status_Code    = -2;                         // -2 => pricelist does not have price for product
                    returnValue.Result.Status_Message = pr.Product_Number;
                    return(returnValue);
                }

                var newProduct = new ORM_CMN_PRO_Catalog_Product()
                {
                    CMN_PRO_Catalog_ProductID     = Guid.NewGuid(),
                    CMN_PRO_Product_Variant_RefID = item.CMN_PRO_Product_Variant_RefID,
                    Creation_Timestamp            = DateTime.Now,
                    Tenant_RefID = item.Tenant_RefID,
                    CMN_PRO_Catalog_Revision_RefID = newRev.CMN_PRO_Catalog_RevisionID,
                    CMN_PRO_Product_RefID          = item.CMN_PRO_Product_RefID,
                };

                newProduct.Save(Connection, Transaction);

                productsMapping.Add(item.CMN_PRO_Catalog_ProductID, newProduct.CMN_PRO_Catalog_ProductID);
            }

            #endregion

            #region ProductGroups

            var oldGroups = ORM_CMN_PRO_Catalog_ProductGroup.Query.Search(Connection, Transaction, new ORM_CMN_PRO_Catalog_ProductGroup.Query()
            {
                Catalog_Revision_RefID = rev.CMN_PRO_Catalog_RevisionID,
                IsDeleted = false
            });

            //oldGroupID - newGroupID
            Dictionary <Guid, Guid> groupsMapping = new Dictionary <Guid, Guid>();
            groupsMapping.Add(Guid.Empty, Guid.Empty);

            foreach (var item in oldGroups)
            {
                groupsMapping.Add(item.CMN_PRO_Catalog_ProductGroupID, Guid.NewGuid());
            }

            foreach (var item in oldGroups)
            {
                var newGroup = new ORM_CMN_PRO_Catalog_ProductGroup()
                {
                    CMN_PRO_Catalog_ProductGroupID   = groupsMapping[item.CMN_PRO_Catalog_ProductGroupID],
                    Catalog_Revision_RefID           = newRev.CMN_PRO_Catalog_RevisionID,
                    CatalogProductGroup_Name         = item.CatalogProductGroup_Name,
                    CatalogProductGroup_Parent_RefID = groupsMapping[item.CatalogProductGroup_Parent_RefID],
                    Creation_Timestamp = DateTime.Now,
                    Tenant_RefID       = item.Tenant_RefID
                };

                newGroup.Save(Connection, Transaction);

                var oldProductsInGroup = ORM_CMN_PRO_Catalog_Product_2_ProductGroup.Query.Search(Connection, Transaction, new ORM_CMN_PRO_Catalog_Product_2_ProductGroup.Query()
                {
                    CMN_PRO_Catalog_ProductGroup_RefID = item.CMN_PRO_Catalog_ProductGroupID,
                    IsDeleted = false
                });

                foreach (var product in oldProductsInGroup)
                {
                    var newProduct = new ORM_CMN_PRO_Catalog_Product_2_ProductGroup()
                    {
                        AssignmentID = Guid.NewGuid(),
                        CMN_PRO_Catalog_ProductGroup_RefID = groupsMapping[product.CMN_PRO_Catalog_ProductGroup_RefID],
                        CMN_PRO_Catalog_Product_RefID      = productsMapping[product.CMN_PRO_Catalog_Product_RefID],
                        Creation_Timestamp = DateTime.Now,
                        Tenant_RefID       = item.Tenant_RefID
                    };

                    newProduct.Save(Connection, Transaction);
                }
            }


            #endregion

            returnValue.Result.Status_Code    = 1;
            returnValue.Result.Status_Message = "Success";
            returnValue.Result.ID             = newRev.CMN_PRO_Catalog_RevisionID;
            return(returnValue);

            #endregion UserCode
        }
        protected static FR_L5US_GAOfA_1742 Execute(DbConnection Connection, DbTransaction Transaction, P_L5US_GAOfA_1742 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5US_GAOfA_1742();
            //Put your code here

            var allOfficesForTenant = cls_Get_AllOffices_for_TenantID.Invoke(Connection, Transaction, securityTicket).Result;

            ORM_USR_Account user = new ORM_USR_Account();
            user.Load(Connection, Transaction, Parameter.UserAccountID);

            ORM_CMN_BPT_EMP_Employee.Query employeeQuery = new ORM_CMN_BPT_EMP_Employee.Query();
            employeeQuery.BusinessParticipant_RefID = user.BusinessParticipant_RefID;
            employeeQuery.Tenant_RefID = securityTicket.TenantID;
            var foundEmployee = ORM_CMN_BPT_EMP_Employee.Query.Search(Connection, Transaction, employeeQuery).FirstOrDefault();

            if (foundEmployee == null)
            {
                foundEmployee = new ORM_CMN_BPT_EMP_Employee();
                foundEmployee.BusinessParticipant_RefID = user.BusinessParticipant_RefID;
                foundEmployee.Tenant_RefID = securityTicket.TenantID;
                foundEmployee.Save(Connection, Transaction);
            }

            List <L5US_GAOfA_1742a> listOfOfficesWithAssignments = new List <L5US_GAOfA_1742a>();

            foreach (var office in allOfficesForTenant)
            {
                var assignmentQuery = new ORM_CMN_BPT_EMP_Employee_2_Office.Query();
                assignmentQuery.CMN_BPT_EMP_Employee_RefID = foundEmployee.CMN_BPT_EMP_EmployeeID;
                assignmentQuery.CMN_STR_Office_RefID       = office.CMN_STR_OfficeID;
                assignmentQuery.Tenant_RefID = securityTicket.TenantID;
                assignmentQuery.IsDeleted    = false;
                var foundAssignment = ORM_CMN_BPT_EMP_Employee_2_Office.Query.Search(Connection, Transaction, assignmentQuery);

                L5US_GAOfA_1742a temp = new L5US_GAOfA_1742a();
                if (foundAssignment.Count > 0)
                {
                    temp.AssignmentID = foundAssignment.First().AssignmentID;
                }
                temp.CMN_BPT_EMP_Employee_RefID = foundEmployee.CMN_BPT_EMP_EmployeeID;
                temp.CMN_STR_OfficeID           = office.CMN_STR_OfficeID;
                temp.Office_InternalName        = office.Office_InternalName;
                temp.IsOfficeToAccountDeleted   = foundAssignment.Count == 0;
                temp.Office_Description         = office.Office_Description;
                temp.Office_Name  = office.Office_Name;
                temp.Parent_RefID = office.Parent_RefID;

                temp.USR_AccountID = Parameter.UserAccountID;

                listOfOfficesWithAssignments.Add(temp);
            }

            returnValue.Result = new L5US_GAOfA_1742();
            returnValue.Result.OfficesWithAssignedUser = new List <L5US_GAOfA_1742a>().ToArray();
            returnValue.Result.OfficesWithAssignedUser = listOfOfficesWithAssignments.ToArray();

            return(returnValue);

            #endregion UserCode
        }
Пример #17
0
        protected static FR_L3NO_GNwUiCoiC_1032_Array Execute(DbConnection Connection, DbTransaction Transaction, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L3NO_GNwUiCoiC_1032_Array();
            //Put your code here
            List <L3NO_GNwUiCoiC_1032> notes = new List <L3NO_GNwUiCoiC_1032>();
            //************************************************************************************************//
            #region GETTING NOTES CREATED BY USER

            var ProjectNotesCreatedByCurrentUser = cls_Get_All_ProjectNotes_Created_by_AccountID.Invoke(Connection, Transaction, securityTicket).Result.ToList();

            foreach (var item in ProjectNotesCreatedByCurrentUser)
            {
                L3NO_GNwUiCoiC_1032 note = new L3NO_GNwUiCoiC_1032();
                note.NoteID = item.CMN_NoteID;
                //setting project info
                L3NO_GNwUiCoiC_1032c projectInfo = new L3NO_GNwUiCoiC_1032c();

                projectInfo.ProjectID = item.Project_RefID;
                var project = ORM_TMS_PRO_Project.Query.Search(Connection, Transaction, new ORM_TMS_PRO_Project.Query()
                {
                    Tenant_RefID      = securityTicket.TenantID,
                    TMS_PRO_ProjectID = item.Project_RefID,
                    IsDeleted         = false
                }).SingleOrDefault();
                if (project != null)
                {
                    projectInfo.ProjectName = project.Name;
                    note.ProjectInfo        = projectInfo;
                    note.ProjectNoteID      = item.TMS_PRO_Project_NoteID;
                    note.CurrentVersionID   = item.Current_NoteRevision_RefID;
                    //setting collaborators info
                    List <L3NO_GNwUiCoiC_1032a> collaboratorsInfo = new List <L3NO_GNwUiCoiC_1032a>();

                    var collaboratorsForProjectNoteID = ORM_TMS_PRO_Project_Note_Collaborators.Query.Search(Connection, Transaction, new ORM_TMS_PRO_Project_Note_Collaborators.Query()
                    {
                        Tenant_RefID      = securityTicket.TenantID,
                        ProjectNote_RefID = item.TMS_PRO_Project_NoteID,
                        IsDeleted         = false
                    });

                    foreach (var collaborator in collaboratorsForProjectNoteID)
                    {
                        L3NO_GNwUiCoiC_1032a collInfo = new L3NO_GNwUiCoiC_1032a();
                        collInfo.AccountID      = collaborator.Account_RefID;
                        collInfo.CollaboratorID = collaborator.TMS_PRO_Project_Note_CollaboratorID;

                        P_L2AI_GAPIfAI_1627 userParameter = new P_L2AI_GAPIfAI_1627();
                        userParameter.AccountRefID = collaborator.Account_RefID;
                        var userinfo = cls_Get_Account_PersonalInformation_for_AccountID.Invoke(Connection, Transaction, userParameter, securityTicket).Result;
                        collInfo.FirstAndLastName = userinfo.FirstName + " " + userinfo.LastName;
                        collaboratorsInfo.Add(collInfo);
                    }
                    note.CollaboratorsInfo = collaboratorsInfo.ToArray();
                    //setting tags info
                    List <L3NO_GNwUiCoiC_1032b> tagsInfo      = new List <L3NO_GNwUiCoiC_1032b>();
                    P_L3N_GTfPNID_1415          tagsParameter = new P_L3N_GTfPNID_1415();
                    tagsParameter.ProjectNoteID = item.TMS_PRO_Project_NoteID;
                    var tagsForProjectNoteID = cls_Get_Tags_for_ProjectNoteID.Invoke(Connection, Transaction, tagsParameter, securityTicket).Result.ToList();
                    foreach (var tag in tagsForProjectNoteID)
                    {
                        L3NO_GNwUiCoiC_1032b tagInfo = new L3NO_GNwUiCoiC_1032b();
                        tagInfo.TagID    = tag.TMS_PRO_TagID;
                        tagInfo.TagValue = tag.TagValue;
                        tagsInfo.Add(tagInfo);
                    }
                    note.TagsInfo = tagsInfo.ToArray();
                    //setting current note version
                    var lastnoterevision = ORM_CMN_NoteRevision.Query.Search(Connection, Transaction, new ORM_CMN_NoteRevision.Query()
                    {
                        Tenant_RefID       = securityTicket.TenantID,
                        CMN_NoteRevisionID = item.Current_NoteRevision_RefID,
                        IsDeleted          = false
                    });
                    if (lastnoterevision != null && lastnoterevision.Count != 0)
                    {
                        note.NoteVersion = lastnoterevision.First().Version.ToString();
                    }
                    else
                    {
                        note.NoteVersion = "1";
                    }

                    //setting all note revisions

                    List <L3NO_GNwUiCoiC_1032d> noteRevisionsInfo = new List <L3NO_GNwUiCoiC_1032d>();

                    P_L3N_GNRfNID_1559 revisionsParameter = new P_L3N_GNRfNID_1559();
                    revisionsParameter.NoteID = item.CMN_NoteID;
                    var noteRevisionsForNote = cls_Get_NoteRevisions_for_NoteID.Invoke(Connection, Transaction, revisionsParameter, securityTicket).Result.ToList();
                    foreach (var noteRevision in noteRevisionsForNote)
                    {
                        L3NO_GNwUiCoiC_1032d noteRevisionInfo = new L3NO_GNwUiCoiC_1032d();
                        noteRevisionInfo.NoteRevisionID         = noteRevision.CMN_NoteRevisionID;
                        noteRevisionInfo.NoteRevisionContent    = noteRevision.Content;
                        noteRevisionInfo.NoteRevisionCreatedOn  = noteRevision.Creation_Timestamp;
                        noteRevisionInfo.NoteRevisionModifiedOn = noteRevision.Modification_Timestamp;
                        noteRevisionInfo.NoteRevisionTitle      = noteRevision.Title;
                        noteRevisionInfo.NoteRevisionVersion    = noteRevision.Version;
                        noteRevisionInfo.NoteRevisionCreatorID  = noteRevision.CreatedBy_BusinessParticipant_RefID;

                        var revisionCreator = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query()
                        {
                            //TODO: For future publish,if creator business participant is deleted, do not display his name and offer collaborators option to delete note revision and note
                            Tenant_RefID = securityTicket.TenantID,
                            CMN_BPT_BusinessParticipantID = noteRevision.CreatedBy_BusinessParticipant_RefID
                        }).SingleOrDefault();
                        if (revisionCreator != null)
                        {
                            noteRevisionInfo.NoteRevisionCreatorFirstAndLastName = revisionCreator.DisplayName;
                        }
                        noteRevisionsInfo.Add(noteRevisionInfo);
                    }
                    note.NoteRevisionInfo = noteRevisionsInfo.ToArray();

                    var NoteCreator = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query()
                    {
                        //TODO: For future publish,if creator business participant is deleted, do not display his name and offer collaborators option to delete note
                        CMN_BPT_BusinessParticipantID = item.CreatedBy_BusinessParticipant_RefID,
                        Tenant_RefID = securityTicket.TenantID
                    }).SingleOrDefault();
                    L3NO_GNwUiCoiC_1032e noteCreator = new L3NO_GNwUiCoiC_1032e();
                    ORM_USR_Account      user        = ORM_USR_Account.Query.Search(Connection, Transaction, new ORM_USR_Account.Query()
                    {
                        BusinessParticipant_RefID = item.CreatedBy_BusinessParticipant_RefID,
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID
                    }).SingleOrDefault();
                    if (user != null)
                    {
                        noteCreator.CreatorID = user.USR_AccountID;
                        P_L2AI_GAPIfAI_1627 personalInfoParameter = new P_L2AI_GAPIfAI_1627();
                        personalInfoParameter.AccountRefID = user.USR_AccountID;
                        var personalInfoForUser = cls_Get_Account_PersonalInformation_for_AccountID.Invoke(Connection, Transaction, personalInfoParameter, securityTicket).Result;
                        if (personalInfoForUser != null)
                        {
                            noteCreator.CreatorFirstAndLastName = personalInfoForUser.FirstName + " " + personalInfoForUser.LastName;
                        }
                    }
                    note.NoteCreatorInfo = noteCreator;
                    note.LastEdited      = item.Modification_Timestamp;
                    note.CreatedOn       = item.Creation_Timestamp;
                    notes.Add(note);
                }
            }
            #endregion
            //************************************************************************************************//
            #region GETTING NOTES WHERE USER IS COLLABORATOR

            var ProjectNotesWhereCurrentUserIsCollaborator = cls_Get_All_ProjectNotes_Where_Current_User_is_Collaborator.Invoke(Connection, Transaction, securityTicket).Result.ToList();
            foreach (var item in ProjectNotesWhereCurrentUserIsCollaborator)
            {
                L3NO_GNwUiCoiC_1032 note = new L3NO_GNwUiCoiC_1032();
                note.NoteID = item.CMN_NoteID;
                //setting project info
                L3NO_GNwUiCoiC_1032c projectInfo = new L3NO_GNwUiCoiC_1032c();

                projectInfo.ProjectID = item.Project_RefID;
                ORM_TMS_PRO_Project project = ORM_TMS_PRO_Project.Query.Search(Connection, Transaction, new ORM_TMS_PRO_Project.Query()
                {
                    Tenant_RefID      = securityTicket.TenantID,
                    TMS_PRO_ProjectID = item.Project_RefID,
                    IsDeleted         = false
                }).SingleOrDefault();
                if (project != null)
                {
                    projectInfo.ProjectName = project.Name;
                    note.ProjectInfo        = projectInfo;
                    note.ProjectNoteID      = item.TMS_PRO_Project_NoteID;
                    note.CurrentVersionID   = item.Current_NoteRevision_RefID;
                    //setting collaborators info
                    List <L3NO_GNwUiCoiC_1032a> collaboratorsInfo = new List <L3NO_GNwUiCoiC_1032a>();

                    var collaboratorsForProjectNoteID = ORM_TMS_PRO_Project_Note_Collaborators.Query.Search(Connection, Transaction, new ORM_TMS_PRO_Project_Note_Collaborators.Query()
                    {
                        Tenant_RefID      = securityTicket.TenantID,
                        ProjectNote_RefID = item.TMS_PRO_Project_NoteID,
                        IsDeleted         = false
                    });

                    foreach (var collaborator in collaboratorsForProjectNoteID)
                    {
                        L3NO_GNwUiCoiC_1032a collInfo = new L3NO_GNwUiCoiC_1032a();
                        collInfo.AccountID      = collaborator.Account_RefID;
                        collInfo.CollaboratorID = collaborator.TMS_PRO_Project_Note_CollaboratorID;

                        P_L2AI_GAPIfAI_1627 userParameter = new P_L2AI_GAPIfAI_1627();
                        userParameter.AccountRefID = collaborator.Account_RefID;
                        var userinfo = cls_Get_Account_PersonalInformation_for_AccountID.Invoke(Connection, Transaction, userParameter, securityTicket).Result;
                        collInfo.FirstAndLastName = userinfo.FirstName + " " + userinfo.LastName;
                        collaboratorsInfo.Add(collInfo);
                    }
                    note.CollaboratorsInfo = collaboratorsInfo.ToArray();
                    //setting tags info
                    List <L3NO_GNwUiCoiC_1032b> tagsInfo      = new List <L3NO_GNwUiCoiC_1032b>();
                    P_L3N_GTfPNID_1415          tagsParameter = new P_L3N_GTfPNID_1415();
                    tagsParameter.ProjectNoteID = item.TMS_PRO_Project_NoteID;
                    var tagsForProjectNoteID = cls_Get_Tags_for_ProjectNoteID.Invoke(Connection, Transaction, tagsParameter, securityTicket).Result.ToList();
                    foreach (var tag in tagsForProjectNoteID)
                    {
                        L3NO_GNwUiCoiC_1032b tagInfo = new L3NO_GNwUiCoiC_1032b();
                        tagInfo.TagID    = tag.TMS_PRO_TagID;
                        tagInfo.TagValue = tag.TagValue;
                        tagsInfo.Add(tagInfo);
                    }
                    note.TagsInfo = tagsInfo.ToArray();
                    //setting current note version
                    var lastnoterevision = ORM_CMN_NoteRevision.Query.Search(Connection, Transaction, new ORM_CMN_NoteRevision.Query()
                    {
                        Tenant_RefID       = securityTicket.TenantID,
                        CMN_NoteRevisionID = item.Current_NoteRevision_RefID,
                        IsDeleted          = false
                    });
                    if (lastnoterevision != null && lastnoterevision.Count != 0)
                    {
                        note.NoteVersion = lastnoterevision.First().Version.ToString();
                    }
                    else
                    {
                        note.NoteVersion = "1";
                    }
                    //setting all note revisions
                    List <L3NO_GNwUiCoiC_1032d> noteRevisionsInfo = new List <L3NO_GNwUiCoiC_1032d>();

                    P_L3N_GNRfNID_1559 revisionsParameter = new P_L3N_GNRfNID_1559();
                    revisionsParameter.NoteID = item.CMN_NoteID;
                    var noteRevisionsForNote = cls_Get_NoteRevisions_for_NoteID.Invoke(Connection, Transaction, revisionsParameter, securityTicket).Result.ToList();
                    foreach (var noteRevision in noteRevisionsForNote)
                    {
                        L3NO_GNwUiCoiC_1032d noteRevisionInfo = new L3NO_GNwUiCoiC_1032d();
                        noteRevisionInfo.NoteRevisionID         = noteRevision.CMN_NoteRevisionID;
                        noteRevisionInfo.NoteRevisionContent    = noteRevision.Content;
                        noteRevisionInfo.NoteRevisionCreatedOn  = noteRevision.Creation_Timestamp;
                        noteRevisionInfo.NoteRevisionModifiedOn = noteRevision.Modification_Timestamp;
                        noteRevisionInfo.NoteRevisionTitle      = noteRevision.Title;
                        noteRevisionInfo.NoteRevisionVersion    = noteRevision.Version;
                        noteRevisionInfo.NoteRevisionCreatorID  = noteRevision.CreatedBy_BusinessParticipant_RefID;

                        var revisionCreator = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query()
                        {
                            IsDeleted = false,
                            CMN_BPT_BusinessParticipantID = noteRevision.CreatedBy_BusinessParticipant_RefID
                        }).SingleOrDefault();
                        if (revisionCreator != null)
                        {
                            noteRevisionInfo.NoteRevisionCreatorFirstAndLastName = revisionCreator.DisplayName;
                        }
                        noteRevisionsInfo.Add(noteRevisionInfo);
                    }
                    note.NoteRevisionInfo = noteRevisionsInfo.ToArray();

                    var NoteCreator = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query()
                    {
                        IsDeleted = false,
                        CMN_BPT_BusinessParticipantID = item.CreatedBy_BusinessParticipant_RefID
                    }).SingleOrDefault();
                    L3NO_GNwUiCoiC_1032e noteCreator = new L3NO_GNwUiCoiC_1032e();
                    ORM_USR_Account      user        = ORM_USR_Account.Query.Search(Connection, Transaction, new ORM_USR_Account.Query()
                    {
                        BusinessParticipant_RefID = item.CreatedBy_BusinessParticipant_RefID,
                        IsDeleted    = false,
                        Tenant_RefID = securityTicket.TenantID
                    }).SingleOrDefault();
                    if (user != null)
                    {
                        noteCreator.CreatorID = user.USR_AccountID;
                        P_L2AI_GAPIfAI_1627 personalInfoParameter = new P_L2AI_GAPIfAI_1627();
                        personalInfoParameter.AccountRefID = user.USR_AccountID;
                        var personalInfoForUser = cls_Get_Account_PersonalInformation_for_AccountID.Invoke(Connection, Transaction, personalInfoParameter, securityTicket).Result;
                        if (personalInfoForUser != null)
                        {
                            noteCreator.CreatorFirstAndLastName = personalInfoForUser.FirstName + " " + personalInfoForUser.LastName;
                        }
                    }

                    note.NoteCreatorInfo = noteCreator;
                    note.LastEdited      = item.Modification_Timestamp;
                    note.CreatedOn       = item.Creation_Timestamp;
                    notes.Add(note);
                }
            }

            #endregion
            //************************************************************************************************//
            returnValue.Result = notes.ToArray();

            return(returnValue);

            #endregion UserCode
        }
Пример #18
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5EM_SE_1657 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here

            ORM_CMN_Address address = new ORM_CMN_Address();
            if (Parameter.CMN_AddressID != Guid.Empty)
            {
                var result = address.Load(Connection, Transaction, Parameter.CMN_AddressID);
                if (result.Status != FR_Status.Success || address.CMN_AddressID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            address.City_Name       = Parameter.City_Name;
            address.Street_Name     = Parameter.Street_Name;
            address.Street_Number   = Parameter.Street_Number;
            address.Country_Name    = Parameter.Country_Name;
            address.Province_Name   = Parameter.Province_Name;
            address.Tenant_RefID    = securityTicket.TenantID;
            address.City_PostalCode = Parameter.City_PostalCode;
            address.Save(Connection, Transaction);
            CSV2Core.DlTrace.Trace("success address");
            ORM_CMN_PER_PersonInfo person = new ORM_CMN_PER_PersonInfo();
            if (Parameter.CMN_PER_PersonInfoID != Guid.Empty)
            {
                var result = person.Load(Connection, Transaction, Parameter.CMN_PER_PersonInfoID);
                if (result.Status != FR_Status.Success || person.CMN_PER_PersonInfoID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }

            //person.AccountImage_URL = Parameter.ProfileImage_Document_RefID;
            person.FirstName     = Parameter.FirstName;
            person.LastName      = Parameter.LastName;
            person.PrimaryEmail  = Parameter.PrimaryEmail;
            person.Tenant_RefID  = securityTicket.TenantID;
            person.Title         = Parameter.Title;
            person.Address_RefID = address.CMN_AddressID;
            person.ProfileImage_Document_RefID = Parameter.ImageID;
            person.BirthDate        = Parameter.BirthDate;
            person.NumberOfChildren = Parameter.TaxInfoParameter != null ? Parameter.TaxInfoParameter.NumberOfChildren : 0;
            person.Save(Connection, Transaction);
            CSV2Core.DlTrace.Trace("success persopm");

            var contactQuery = new ORM_CMN_PER_CommunicationContact.Query();
            contactQuery.Tenant_RefID     = securityTicket.TenantID;
            contactQuery.PersonInfo_RefID = person.CMN_PER_PersonInfoID;
            contactQuery.IsDeleted        = false;
            var deleteContacts = ORM_CMN_PER_CommunicationContact.Query.SoftDelete(Connection, Transaction, contactQuery);
            foreach (var parContact in Parameter.Contacts)
            {
                ORM_CMN_PER_CommunicationContact contact = new ORM_CMN_PER_CommunicationContact();
                if (parContact.CMN_PER_CommunicationContactID != Guid.Empty)
                {
                    var result = contact.Load(Connection, Transaction, parContact.CMN_PER_CommunicationContactID);
                    if (result.Status != FR_Status.Success || contact.CMN_PER_CommunicationContactID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                }
                contact.Content          = parContact.Content;
                contact.Contact_Type     = parContact.CMN_PER_CommunicationContact_TypeID;
                contact.Tenant_RefID     = securityTicket.TenantID;
                contact.PersonInfo_RefID = person.CMN_PER_PersonInfoID;
                contact.Save(Connection, Transaction);
                CSV2Core.DlTrace.Trace("success contact");
            }

            ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
            if (Parameter.CMN_BPT_BusinessParticipantID != Guid.Empty)
            {
                var result = bParticipant.Load(Connection, Transaction, Parameter.CMN_BPT_BusinessParticipantID);
                if (result.Status != FR_Status.Success || bParticipant.CMN_BPT_BusinessParticipantID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            bParticipant.DisplayName = Parameter.DisplayName;
            bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID;
            bParticipant.IsNaturalPerson = true;
            bParticipant.Tenant_RefID    = securityTicket.TenantID;
            bParticipant.Save(Connection, Transaction);
            ORM_CMN_BPT_EMP_Employee employee = new ORM_CMN_BPT_EMP_Employee();
            CSV2Core.DlTrace.Trace("success bpart");


            if (Parameter.CMN_BPT_EMP_EmployeeID != Guid.Empty)
            {
                var result = employee.Load(Connection, Transaction, Parameter.CMN_BPT_EMP_EmployeeID);
                if (result.Status != FR_Status.Success || employee.CMN_BPT_EMP_EmployeeID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            employee.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
            employee.Staff_Number     = Parameter.Staff_Number;
            employee.StandardFunction = Parameter.StandardFunction;
            employee.Tenant_RefID     = securityTicket.TenantID;
            employee.Save(Connection, Transaction);
            CSV2Core.DlTrace.Trace("success employee");


            ORM_CMN_BPT_EMP_EmploymentRelationship employmentRelationship = new ORM_CMN_BPT_EMP_EmploymentRelationship();
            if (Parameter.CMN_BPT_EMP_Employee_EmploymentRelationshipID != Guid.Empty)
            {
                var result = employmentRelationship.Load(Connection, Transaction, Parameter.CMN_BPT_EMP_Employee_EmploymentRelationshipID);
                if (result.Status != FR_Status.Success || employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            employmentRelationship.Work_StartDate = Parameter.Work_StartDate;

            bool resignationDateChanged = false;
            if (employmentRelationship.Work_EndDate != Parameter.Work_EndDate)
            {
                resignationDateChanged = true;
            }

            employmentRelationship.Work_EndDate   = Parameter.Work_EndDate;
            employmentRelationship.Tenant_RefID   = securityTicket.TenantID;
            employmentRelationship.Employee_RefID = employee.CMN_BPT_EMP_EmployeeID;
            employmentRelationship.Save(Connection, Transaction);
            CSV2Core.DlTrace.Trace("success employmentRelationship");

            if (Parameter.Work_EndDate.Ticks != 0)
            {
                ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query empRelationShipToWorkingContractQuery = new ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query();
                empRelationShipToWorkingContractQuery.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                empRelationShipToWorkingContractQuery.Tenant_RefID = securityTicket.TenantID;
                empRelationShipToWorkingContractQuery.IsDeleted    = false;
                List <ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract> workingContractAssignments = ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query.Search(Connection, Transaction, empRelationShipToWorkingContractQuery);
                foreach (var workingContractAssignment in workingContractAssignments)
                {
                    ORM_CMN_BPT_EMP_WorkingContract workingContract = new ORM_CMN_BPT_EMP_WorkingContract();
                    if (workingContractAssignment.WorkingContract_RefID != Guid.Empty)
                    {
                        var result = workingContract.Load(Connection, Transaction, workingContractAssignment.WorkingContract_RefID);
                        if (result.Status != FR_Status.Success || workingContract.CMN_BPT_EMP_WorkingContractID == Guid.Empty)
                        {
                            var error = new FR_Guid();
                            error.ErrorMessage = "No Such ID";
                            error.Status       = FR_Status.Error_Internal;
                            return(error);
                        }
                    }
                    if (workingContract.Contract_EndDate.Ticks == 0 || workingContract.Contract_EndDate.Ticks > Parameter.Work_EndDate.Ticks)
                    {
                        workingContract.Contract_EndDate         = Parameter.Work_EndDate;
                        workingContract.IsContractEndDateDefined = true;
                        workingContract.Save(Connection, Transaction);
                    }
                }
            }

            var activeTimeFrame = cls_Get_Active_CalculationTimeFrame.Invoke(Connection, Transaction, securityTicket).Result;

            var timeframes   = cls_Get_CalculationTimeFramesForTenant.Invoke(Connection, Transaction, securityTicket).Result.ToList();
            var resultFrames = timeframes.Where(i => i.CalculationTimeframe_StartDate.Year == employmentRelationship.Work_StartDate.Year).ToList();
            if (resultFrames.Count == 0)
            {
                var newFrame    = new ORM_CMN_CAL_CalculationTimeframe();
                int currentYear = Parameter.Work_StartDate.Year;
                while (currentYear < activeTimeFrame.CalculationTimeframe_StartDate.Year)
                {
                    if (!timeframes.Any(i => i.CalculationTimeframe_StartDate.Year == currentYear))
                    {
                        newFrame.CalculationTimeframe_StartDate        = new DateTime(currentYear, 1, 1);
                        newFrame.CalculationTimeframe_EstimatedEndDate = new DateTime(currentYear, 12, 31);
                        newFrame.Tenant_RefID = securityTicket.TenantID;
                        newFrame.Save(Connection, Transaction);
                        newFrame = new ORM_CMN_CAL_CalculationTimeframe();
                    }
                    currentYear++;

                    ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe relationshipFrame = new ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe();
                    relationshipFrame.CalculationTimeframe_RefID   = newFrame.CMN_CAL_CalculationTimeframeID;
                    relationshipFrame.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                    relationshipFrame.Tenant_RefID = securityTicket.TenantID;
                    relationshipFrame.Save(Connection, Transaction);
                }
            }
            else
            {
                timeframes = timeframes.Where(i => i.CalculationTimeframe_StartDate.Year < activeTimeFrame.CalculationTimeframe_StartDate.Year && i.CalculationTimeframe_StartDate.Year >= employmentRelationship.Work_StartDate.Year).ToList();
                foreach (var timeframe in timeframes)
                {
                    ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe.Query relationshipFrameQuery = new ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe.Query();
                    relationshipFrameQuery.CalculationTimeframe_RefID   = timeframe.CMN_CAL_CalculationTimeframeID;
                    relationshipFrameQuery.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                    relationshipFrameQuery.Tenant_RefID = securityTicket.TenantID;
                    List <ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe> oldContractFrames = ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe.Query.Search(Connection, Transaction, relationshipFrameQuery);
                    if (oldContractFrames.Count == 0)
                    {
                        ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe relationshipFrame = new ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe();
                        relationshipFrame.CalculationTimeframe_RefID   = timeframe.CMN_CAL_CalculationTimeframeID;
                        relationshipFrame.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                        relationshipFrame.Tenant_RefID = securityTicket.TenantID;
                        relationshipFrame.Save(Connection, Transaction);
                    }
                }
            }



            P_L5EM_GAERCTFFE_1405 timeFrameParam = new P_L5EM_GAERCTFFE_1405();
            timeFrameParam.EmployeeID = employee.CMN_BPT_EMP_EmployeeID;
            L5EM_GAERCTFFE_1405 employeeTimeFrame = cls_Get_Active_EmployeeRelationshipTimeFrame_For_EmployeeID.Invoke(Connection, Transaction, timeFrameParam, securityTicket).Result;
            if (employeeTimeFrame == null)
            {
                ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe timeFrame = new ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe();
                timeFrame.CalculationTimeframe_RefID   = activeTimeFrame.CMN_CAL_CalculationTimeframeID;
                timeFrame.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                timeFrame.Tenant_RefID = securityTicket.TenantID;
                timeFrame.Save(Connection, Transaction);
                CSV2Core.DlTrace.Trace("success timeFrame");
            }

            //save employee professions
            P_L5EM_SEP_1447 saveProfessionsPar = new P_L5EM_SEP_1447();
            saveProfessionsPar.Employee_RefID    = employee.CMN_BPT_EMP_EmployeeID;
            saveProfessionsPar.FunctionHistories = Parameter.FunctionHistories;
            cls_Save_EmployeeFunctionHistory.Invoke(Connection, Transaction, saveProfessionsPar, securityTicket);
            CSV2Core.DlTrace.Trace("success employee function history");

            //save workplace histories
            P_L5EM_SWPH_1625 saveWorkplaceHistoryPar = new P_L5EM_SWPH_1625();
            saveWorkplaceHistoryPar.Employee_RefID     = employee.CMN_BPT_EMP_EmployeeID;
            saveWorkplaceHistoryPar.WorkplaceHistories = Parameter.WorkplaceHistories;
            cls_Save_WorkplaceHistories.Invoke(Connection, Transaction, saveWorkplaceHistoryPar, securityTicket);
            CSV2Core.DlTrace.Trace("success workplaceHistories");

            P_L5EM_SUED_1648 saveDocuments = new P_L5EM_SUED_1648();
            saveDocuments.Employee_RefID = employee.CMN_BPT_EMP_EmployeeID;
            saveDocuments.Documents      = Parameter.Documents;
            cls_Save_Uploaded_Employee_Document.Invoke(Connection, Transaction, saveDocuments, securityTicket);
            CSV2Core.DlTrace.Trace("success documents");

            P_L5EM_SEQS_0959 saveSkillsPar = new P_L5EM_SEQS_0959();
            saveSkillsPar.Employee_RefID = employee.CMN_BPT_EMP_EmployeeID;
            saveSkillsPar.Skills         = Parameter.Skills;
            cls_Save_Employee_QualificationSkills.Invoke(Connection, Transaction, saveSkillsPar, securityTicket);
            CSV2Core.DlTrace.Trace("success skills");

            CSV2Core.DlTrace.Trace("AccountID :" + Parameter.USR_AccountID);

            if (Parameter.USR_AccountID != null && Parameter.USR_AccountID != Guid.Empty)
            {
                CSV2Core.DlTrace.Trace("success param");

                ORM_USR_Account account = new ORM_USR_Account();
                if (Parameter.USR_AccountID != Guid.Empty)
                {
                    var result = account.Load(Connection, Transaction, Parameter.USR_AccountID);
                    if (account.USR_AccountID == Guid.Empty)
                    {
                        account.USR_AccountID = Guid.NewGuid();
                        account.AccountType   = 2;
                    }
                    account.Username = Parameter.username;
                    account.DefaultLanguage_RefID     = Parameter.LanguageID;
                    account.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
                    account.Tenant_RefID = securityTicket.TenantID;
                    account.Save(Connection, Transaction);


                    var personToAccountQuery = new ORM_CMN_PER_PersonInfo_2_Account.Query();
                    personToAccountQuery.Tenant_RefID      = securityTicket.TenantID;
                    personToAccountQuery.USR_Account_RefID = account.USR_AccountID;
                    personToAccountQuery.IsDeleted         = false;
                    var personToAccounts = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, personToAccountQuery);
                    if (personToAccounts.Count != 0)
                    {
                        ORM_CMN_PER_PersonInfo_2_Account personToAccount = personToAccounts[0];
                        personToAccount.CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID;
                        personToAccount.USR_Account_RefID        = account.USR_AccountID;
                        personToAccount.Tenant_RefID             = securityTicket.TenantID;
                        personToAccount.Save(Connection, Transaction);
                    }
                    else
                    {
                        ORM_CMN_PER_PersonInfo_2_Account personToAccount = new ORM_CMN_PER_PersonInfo_2_Account();
                        personToAccount.CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID;
                        personToAccount.USR_Account_RefID        = account.USR_AccountID;
                        personToAccount.Tenant_RefID             = securityTicket.TenantID;
                        personToAccount.Save(Connection, Transaction);
                    }
                }



                if (Parameter.Rights != null)
                {
                    foreach (var rightsParam in Parameter.Rights)
                    {
                        if (rightsParam.RightAssinmentID == Guid.Empty && rightsParam.RightID != Guid.Empty)
                        {
                            var right2account = new ORM_USR_Account_2_FunctionLevelRight();
                            right2account.Account_RefID            = Parameter.USR_AccountID;
                            right2account.FunctionLevelRight_RefID = rightsParam.RightID;
                            right2account.Tenant_RefID             = securityTicket.TenantID;
                            right2account.Save(Connection, Transaction);
                            CSV2Core.DlTrace.Trace("success save right: " + right2account.FunctionLevelRight_RefID);
                        }

                        if (rightsParam.RightAssinmentID != Guid.Empty && rightsParam.RightID == Guid.Empty)
                        {
                            var right2account = new ORM_USR_Account_2_FunctionLevelRight();
                            if (rightsParam.RightAssinmentID != Guid.Empty)
                            {
                                var result = right2account.Load(Connection, Transaction, rightsParam.RightAssinmentID);
                                if (result.Status != FR_Status.Success || right2account.AssignmentID == Guid.Empty)
                                {
                                    var error = new FR_Guid();
                                    error.ErrorMessage = "No Such ID";
                                    error.Status       = FR_Status.Error_Internal;
                                    return(error);
                                }
                            }
                            right2account.IsDeleted = true;
                            right2account.Save(Connection, Transaction);
                            CSV2Core.DlTrace.Trace("success save right2Acc: " + right2account.FunctionLevelRight_RefID);
                        }
                    }
                }
            }

            CSV2Core.DlTrace.Trace("emp id wtf " + Parameter.CMN_BPT_EMP_EmployeeID);

            if (Parameter.CMN_BPT_EMP_EmployeeID == Guid.Empty || resignationDateChanged)
            {
                var enterpriseService          = InfrastructureFactory.CreateEnterpriseService();
                KeyPerformanceIndicator action = new KeyPerformanceIndicator();
                action.PerformedByAccountID     = securityTicket.AccountID;
                action.PerformedByApplicationID = Parameter.ApplicationID;
                action.PerformedOn               = DateTime.Now;
                action.PerformedByTenantID       = securityTicket.TenantID;
                action.KeyPerformanceIndicatorID = Guid.Parse("4dda967a-5399-4929-afae-7af64699895b");
                action.Value = cls_Get_Employees_For_Tenant.Invoke(Connection, Transaction, securityTicket).Result.Where(i => i.Work_EndDate.Ticks == 0 || i.Work_EndDate.Ticks > DateTime.Now.Ticks).ToArray().Length;

                var result = enterpriseService.SendMessage(action.ToPayload(), KeyPerformanceIndicator.MESSAGE_TYPE, Parameter.ApplicationID, EMessageRecipient.CUSTOMER_MANAGEMENT_PLATFORM);
                // ServerLog.Instance.Info("Enterprise message sending " + (result.Code == 200 ? "successful" : "failed"));
                CSV2Core.DlTrace.Trace("success send kpi");
            }

            Parameter.TaxInfoParameter.EmployeeID = employee.CMN_BPT_EMP_EmployeeID;
            Parameter.TaxInfoParameter.CMN_BPT_BusinessParticipantID = bParticipant.CMN_BPT_BusinessParticipantID;
            cls_Save_Employee_TaxInformation.Invoke(Connection, Transaction, Parameter.TaxInfoParameter, securityTicket);
            cls_Save_Employee_BankAccount.Invoke(Connection, Transaction, Parameter.BankAccountParameter, securityTicket);
            Parameter.SocialSecurity.CMN_PER_PersonInfoID          = person.CMN_PER_PersonInfoID;
            Parameter.SocialSecurity.CMN_BPT_EMP_EmployeeID        = employee.CMN_BPT_EMP_EmployeeID;
            Parameter.SocialSecurity.CMN_BPT_BusinessParticipantID = bParticipant.CMN_BPT_BusinessParticipantID;
            cls_Save_Employee_SocialSecurity.Invoke(Connection, Transaction, Parameter.SocialSecurity, securityTicket);

            returnValue.Result = employee.CMN_BPT_EMP_EmployeeID;
            return(returnValue);

            #endregion UserCode
        }
Пример #19
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5PS_ST_1157 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();

            #region Get Account By AccountID

            var account = new ORM_USR_Account();
            account.Load(Connection, Transaction, securityTicket.AccountID);

            #endregion

            #region PrescriptionTransaction_InternalNubmer

            var qtransaction = new ORM_HEC_Patient_Prescription_Transaction.Query();
            qtransaction.Tenant_RefID = securityTicket.TenantID;

            var count          = ORM_HEC_Patient_Prescription_Transaction.Query.Search(Connection, Transaction, qtransaction).Count();
            var internalnumber = "0000000" + count;
            internalnumber = internalnumber.Substring(internalnumber.Length - 7, 7);

            #endregion

            var transaction = new ORM_HEC_Patient_Prescription_Transaction();
            transaction.HEC_Patient_Prescription_TransactionID = Guid.NewGuid();
            transaction.PrescriptionTransaction_InternalNubmer = internalnumber;
            transaction.PrescriptionTransaction_IsComplete     = false;
            transaction.PrescriptionTransaction_RequestedDateOfDeliveryFrom       = Parameter.PrescriptionTransaction_RequestedDateOfDeliveryFrom;
            transaction.PrescriptionTransaction_RequestedDateOfDeliveryTo         = Parameter.PrescriptionTransaction_RequestedDateOfDeliveryTo;
            transaction.PrescriptionTransaction_CreatedByBusinessParticpant_RefID = account.BusinessParticipant_RefID;
            transaction.PrescriptionTransaction_Comment                       = Parameter.PrescriptionTransaction_Comment;
            transaction.PrescriptionTransaction_Patient_RefID                 = Parameter.PrescriptionTransaction_Patient_RefID;
            transaction.PerscriptionTransaction_DeliveryAddress_RefID         = Parameter.PrescriptionTransaction_Address_RefID;
            transaction.PrescriptionTransaction_UseParticipationPolicyAddress = false;
            transaction.PrescriptionTransaction_UsePatientAddress             = true;
            transaction.PrescriptionTransaction_UseReceiptAddress             = false;
            transaction.Creation_Timestamp = DateTime.Now;
            transaction.Tenant_RefID       = securityTicket.TenantID;
            transaction.Save(Connection, Transaction);

            if (Parameter.Prescriptions != null)
            {
                var header = new ORM_HEC_Patient_Prescription_Header();
                header.HEC_Patient_Prescription_HeaderID = Guid.NewGuid();
                header.Patient_RefID               = Parameter.PrescriptionTransaction_Patient_RefID;
                header.PrescribedBy_Doctor_RefID   = Guid.Empty;
                header.Prescription_Date           = new DateTime();
                header.Prescription_Comment        = "";
                header.Prescription_InternalNumber = transaction.PrescriptionTransaction_InternalNubmer + "/" + 1;
                header.Perscription_UploadedByBusinessParticipant_RefID = account.BusinessParticipant_RefID;
                header.Creation_Timestamp = DateTime.Now;
                header.Tenant_RefID       = securityTicket.TenantID;
                header.Save(Connection, Transaction);

                var transaction2header = new ORM_HEC_Patient_Prescription_2_PrescriptionTransaction();
                transaction2header.AssignmentID = Guid.NewGuid();
                transaction2header.HEC_Patient_Prescription_Header_RefID      = header.HEC_Patient_Prescription_HeaderID;
                transaction2header.HEC_Patient_Prescription_Transaction_RefID = transaction.HEC_Patient_Prescription_TransactionID;
                transaction2header.Creation_Timestamp = DateTime.Now;
                transaction2header.Tenant_RefID       = securityTicket.TenantID;
                transaction2header.Save(Connection, Transaction);

                var prescriptionDocument = new ORM_HEC_Patient_Prescription_Document();
                prescriptionDocument.HEC_Patient_Prescription_DocumentID = Guid.NewGuid();
                prescriptionDocument.PrescriptionHeader_RefID            = header.HEC_Patient_Prescription_HeaderID;
                prescriptionDocument.Comment            = "";
                prescriptionDocument.Document_RefID     = Guid.NewGuid();
                prescriptionDocument.Creation_Timestamp = DateTime.Now;
                prescriptionDocument.Tenant_RefID       = securityTicket.TenantID;
                prescriptionDocument.Save(Connection, Transaction);

                var document = new ORM_DOC_Document();
                document.DOC_DocumentID     = prescriptionDocument.Document_RefID;
                document.Alias              = Parameter.Prescriptions.File_Name;
                document.PrimaryType        = Parameter.Prescriptions.File_Extension;
                document.Creation_Timestamp = DateTime.Now;
                document.Tenant_RefID       = securityTicket.TenantID;
                document.Save(Connection, Transaction);

                var revision = new ORM_DOC_DocumentRevision();
                revision.DOC_DocumentRevisionID = Guid.NewGuid();
                revision.Document_RefID         = prescriptionDocument.Document_RefID;
                revision.Revision            = 1;
                revision.IsLastRevision      = true;
                revision.UploadedByAccount   = securityTicket.AccountID;
                revision.File_Name           = Parameter.Prescriptions.File_Name;
                revision.File_ServerLocation = Parameter.Prescriptions.File_ServerLocation;
                revision.File_Extension      = Parameter.Prescriptions.File_Extension;
                revision.File_Size_Bytes     = Parameter.Prescriptions.File_Size_Bytes;
                revision.Creation_Timestamp  = DateTime.Now;
                revision.Tenant_RefID        = securityTicket.TenantID;
                revision.Save(Connection, Transaction);
            }
            return(returnValue);

            #endregion UserCode
        }
Пример #20
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L3DT_FDT_1646 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here

            #region Finished Status ID

            var Parameter_StatusFinished = new P_L2DT_GDTSfGPM_1121();
            Parameter_StatusFinished.GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(EDeveloperTaskHistory.Finished);
            var StatusFinished = cls_Get_DeveloperTaskStatus_for_GlobalPropertyMatchingID.Invoke(Connection, Transaction, Parameter_StatusFinished, securityTicket).Result;

            var Parameter_StatusStarted = new P_L2DT_GDTSfGPM_1121();
            Parameter_StatusStarted.GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(EDeveloperTaskHistory.Started);
            var StatusStarted = cls_Get_DeveloperTaskStatus_for_GlobalPropertyMatchingID.Invoke(Connection, Transaction, Parameter_StatusStarted, securityTicket).Result;

            #endregion

            #region Developer Task involvement
            ORM_TMS_PRO_DeveloperTask_Involvement DeveloperTask_Involvemnet = new ORM_TMS_PRO_DeveloperTask_Involvement();
            DeveloperTask_Involvemnet.Load(Connection, Transaction, Parameter.DeveloperTask_InvolvementID);

            DeveloperTask_Involvemnet.IsActive   = false;
            DeveloperTask_Involvemnet.IsArchived = true;
            DeveloperTask_Involvemnet.R_InvestedWorkingTime_min += Parameter.DeveloperTask_InvestedTime;

            DeveloperTask_Involvemnet.Save(Connection, Transaction);
            #endregion

            #region Developer Task

            //ORM_TMS_PRO_DeveloperTask_Involvement.Query InvolvementQuery = new ORM_TMS_PRO_DeveloperTask_Involvement.Query();
            //InvolvementQuery.DeveloperTask_RefID = DeveloperTask_Involvemnet.DeveloperTask_RefID;

            //var InvestedTime = ORM_TMS_PRO_DeveloperTask_Involvement.Query.Search(Connection, Transaction, InvolvementQuery).Sum(i => i.R_InvestedWorkingTime_min);

            ORM_TMS_PRO_DeveloperTask DeveloperTask = new ORM_TMS_PRO_DeveloperTask();
            DeveloperTask.Load(Connection, Transaction, DeveloperTask_Involvemnet.DeveloperTask_RefID);
            DeveloperTask.DeveloperTime_CurrentInvestment_min += Parameter.DeveloperTask_InvestedTime;
            DeveloperTask.Completion_Timestamp = DateTime.Now;
            DeveloperTask.PercentageComplete   = "100";
            DeveloperTask.IsComplete           = true;
            DeveloperTask.Save(Connection, Transaction);

            //Retrieve start task timestamp
            ORM_TMS_PRO_DeveloperTask_StatusHistory.Query DeveloperTask_History_Query = new ORM_TMS_PRO_DeveloperTask_StatusHistory.Query();
            DeveloperTask_History_Query.DeveloperTask_Status_RefID      = StatusStarted.TMS_PRO_DeveloperTask_StatusID;
            DeveloperTask_History_Query.DeveloperTask_RefID             = DeveloperTask.TMS_PRO_DeveloperTaskID;
            DeveloperTask_History_Query.TriggeredBy_ProjectMember_RefID = DeveloperTask_Involvemnet.ProjectMember_RefID;
            List <ORM_TMS_PRO_DeveloperTask_StatusHistory> statusHistoryResult = ORM_TMS_PRO_DeveloperTask_StatusHistory.Query.Search(Connection, Transaction, DeveloperTask_History_Query);


            //Status History
            ORM_TMS_PRO_DeveloperTask_StatusHistory DeveloperTask_StatusHistory = new ORM_TMS_PRO_DeveloperTask_StatusHistory();
            DeveloperTask_StatusHistory.DeveloperTask_RefID             = DeveloperTask.TMS_PRO_DeveloperTaskID;
            DeveloperTask_StatusHistory.DeveloperTask_Status_RefID      = StatusFinished.TMS_PRO_DeveloperTask_StatusID;
            DeveloperTask_StatusHistory.TriggeredBy_ProjectMember_RefID = DeveloperTask_Involvemnet.ProjectMember_RefID;
            DeveloperTask_StatusHistory.Comment = Parameter.DeveloperTask_Comment != ""? "Comment: " + Parameter.DeveloperTask_Comment + "</br>" + "Invested time : "
                                                  + DeveloperTask_Involvemnet.R_InvestedWorkingTime_min + " minutes":
                                                  "Invested time: " + DeveloperTask_Involvemnet.R_InvestedWorkingTime_min + " minutes";
            DeveloperTask_StatusHistory.Tenant_RefID = securityTicket.TenantID;
            DeveloperTask_StatusHistory.Save(Connection, Transaction);

            #endregion

            #region Charging Level
            ORM_TMP_PRO_ProjectMember_Type_AvailableChargingLevel DefaultChargingLevel = null;
            ORM_TMS_PRO_ProjectMember GrabbedByMember = new ORM_TMS_PRO_ProjectMember();
            GrabbedByMember.Load(Connection, Transaction, DeveloperTask.GrabbedByMember_RefID);

            if (GrabbedByMember != null)
            {
                ORM_TMP_PRO_ProjectMember_Type_AvailableChargingLevel.Query ChargingLevelQuery = new ORM_TMP_PRO_ProjectMember_Type_AvailableChargingLevel.Query();
                ChargingLevelQuery.ProjectMember_Type_RefID = GrabbedByMember.ProjectMember_Type_RefID;
                ChargingLevelQuery.IsDeleted = false;

                List <ORM_TMP_PRO_ProjectMember_Type_AvailableChargingLevel> AvailbaleChargingLevels =
                    ORM_TMP_PRO_ProjectMember_Type_AvailableChargingLevel.Query.Search(Connection, Transaction, ChargingLevelQuery);

                if (AvailbaleChargingLevels.Exists(acl => acl.IsDefault))
                {
                    DefaultChargingLevel = AvailbaleChargingLevels.Where(acl => acl.IsDefault).FirstOrDefault();
                }
                else if (AvailbaleChargingLevels.Count > 0)
                {
                    DefaultChargingLevel = AvailbaleChargingLevels.FirstOrDefault();
                }
            }

            #endregion

            #region Invested WorkTimes

            //User Account
            ORM_USR_Account UserAccount = new ORM_USR_Account();
            UserAccount.Load(Connection, Transaction, securityTicket.AccountID);


            ORM_CMN_BPT_InvestedWorkTime InvestedWorkTimes = new ORM_CMN_BPT_InvestedWorkTime();
            InvestedWorkTimes.BusinessParticipant_RefID   = UserAccount.BusinessParticipant_RefID;
            InvestedWorkTimes.WorkTime_Start              = statusHistoryResult.OrderBy(c => c.Creation_Timestamp).LastOrDefault().Creation_Timestamp;
            InvestedWorkTimes.WorkTime_Amount_min         = Parameter.DeveloperTask_InvestedTime;
            InvestedWorkTimes.WorkTime_InternalIdentifier = cls_Get_New_InvestedWorkTime_Identifier.Invoke(Connection, Transaction, securityTicket).Result.IWT_Identifier;
            InvestedWorkTimes.WorkTime_Source             = "DanuTask - [D" + DeveloperTask.IdentificationNumber + "] " + DeveloperTask.Name;
            InvestedWorkTimes.WorkTime_Comment.AddEntry(Parameter.LanguageID, Parameter.DeveloperTask_Comment);
            InvestedWorkTimes.ChargingLevel_RefID = DefaultChargingLevel != null ? DefaultChargingLevel.ChargingLevel_RefID : Guid.Empty;
            InvestedWorkTimes.Tenant_RefID        = securityTicket.TenantID;
            InvestedWorkTimes.Save(Connection, Transaction);
            #endregion

            #region Developer Task Involvements Invested time
            ORM_TMS_PRO_DeveloperTask_Involvements_InvestedWorkTime DeveloperTaskInvolvements_InvestedTime = new ORM_TMS_PRO_DeveloperTask_Involvements_InvestedWorkTime();
            DeveloperTaskInvolvements_InvestedTime.CMN_BPT_InvestedWorkTime_RefID          = InvestedWorkTimes.CMN_BPT_InvestedWorkTimeID;
            DeveloperTaskInvolvements_InvestedTime.TMS_PRO_DeveloperTask_Involvement_RefID = DeveloperTask_Involvemnet.TMS_PRO_DeveloperTask_InvolvementID;
            DeveloperTaskInvolvements_InvestedTime.Tenant_RefID = securityTicket.TenantID;
            DeveloperTaskInvolvements_InvestedTime.Save(Connection, Transaction);
            #endregion

            return(returnValue);

            #endregion UserCode
        }
Пример #21
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L6DR_DDBID_1653 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here


            P_L6DR_DDBID_1653 param = new P_L6DR_DDBID_1653();
            param.CMN_BPT_BusinessParticipantID = Parameter.CMN_BPT_BusinessParticipantID;

            var drivers = cls_Retrieve_Driver_Info_and_VerCode.Invoke(Connection, Transaction, securityTicket).Result;

            var driver = drivers.FirstOrDefault(x => x.CMN_BPT_BusinessParticipantID == param.CMN_BPT_BusinessParticipantID);

            if (driver != null)
            {
                ORM_CMN_PER_PersonInfo person = new ORM_CMN_PER_PersonInfo();
                if (driver.CMN_PER_PersonInfoID != Guid.Empty)
                {
                    var result = person.Load(Connection, Transaction, driver.CMN_PER_PersonInfoID);
                    if (result.Status != FR_Status.Success || person.CMN_PER_PersonInfoID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    person.IsDeleted = true;
                    person.Save(Connection, Transaction);
                }

                ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
                if (driver.CMN_BPT_BusinessParticipantID != Guid.Empty)
                {
                    var result = bParticipant.Load(Connection, Transaction, driver.CMN_BPT_BusinessParticipantID);
                    if (result.Status != FR_Status.Success || bParticipant.CMN_BPT_BusinessParticipantID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    bParticipant.IsDeleted = true;
                    bParticipant.Save(Connection, Transaction);
                }

                if (driver.Contacts != null)
                {
                    foreach (var parContact in driver.Contacts)
                    {
                        ORM_CMN_PER_CommunicationContact contact = new ORM_CMN_PER_CommunicationContact();
                        if (parContact.CMN_PER_CommunicationContact_TypeID != Guid.Empty)
                        {
                            var result = contact.Load(Connection, Transaction, parContact.CMN_PER_CommunicationContact_TypeID);
                            if (result.Status != FR_Status.Success || contact.CMN_PER_CommunicationContactID == Guid.Empty)
                            {
                                var error = new FR_Guid();
                                error.ErrorMessage = "No Such ID";
                                error.Status       = FR_Status.Error_Internal;
                                return(error);
                            }
                            contact.IsDeleted = true;
                            contact.Save(Connection, Transaction);
                        }
                    }
                }

                ORM_CMN_Address adress = new ORM_CMN_Address();
                if (driver.CMN_AddressID != Guid.Empty)
                {
                    var result = adress.Load(Connection, Transaction, driver.CMN_AddressID);
                    if (result.Status != FR_Status.Success || adress.CMN_AddressID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    adress.IsDeleted = true;
                    adress.Save(Connection, Transaction);
                }

                ORM_CMN_BPT_Supplier supplier = new ORM_CMN_BPT_Supplier();
                if (driver.CMN_BPT_SupplierID != Guid.Empty)
                {
                    var result = supplier.Load(Connection, Transaction, driver.CMN_BPT_SupplierID);
                    if (result.Status != FR_Status.Success || supplier.CMN_BPT_SupplierID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    supplier.IsDeleted = true;
                    supplier.Save(Connection, Transaction);
                }

                ORM_CMN_BPT_BusinessParticipant asossBParticipant = new ORM_CMN_BPT_BusinessParticipant();
                if (driver.AssociatedBusinessParticipant_RefID != Guid.Empty)
                {
                    var result = asossBParticipant.Load(Connection, Transaction, driver.AssociatedBusinessParticipant_RefID);
                    if (result.Status != FR_Status.Success || asossBParticipant.CMN_BPT_BusinessParticipantID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    asossBParticipant.IsDeleted = true;
                    asossBParticipant.Save(Connection, Transaction);
                }


                ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant BusinessParticipant_AssociatedBusinessParticipant = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant();
                if (driver.AssociatedBusinessParticipant_RefID != Guid.Empty)
                {
                    var result = BusinessParticipant_AssociatedBusinessParticipant.Load(Connection, Transaction, driver.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID);
                    if (result.Status != FR_Status.Success || BusinessParticipant_AssociatedBusinessParticipant.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    BusinessParticipant_AssociatedBusinessParticipant.IsDeleted = true;
                    BusinessParticipant_AssociatedBusinessParticipant.Save(Connection, Transaction);
                }

                ORM_USR_Account account = new ORM_USR_Account();
                if (driver.USR_AccountID != Guid.Empty)
                {
                    var result = account.Load(Connection, Transaction, driver.USR_AccountID);
                    if (result.Status != FR_Status.Success || account.USR_AccountID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    account.IsDeleted = true;
                    account.Save(Connection, Transaction);
                }

                ORM_USR_Device_AccountCode_StatusHistory Device_AccountCode_StatusHistory = new ORM_USR_Device_AccountCode_StatusHistory();
                if (driver.USR_Device_AccountCode_UsageHistoryID != Guid.Empty)
                {
                    var result = Device_AccountCode_StatusHistory.Load(Connection, Transaction, driver.USR_Device_AccountCode_UsageHistoryID);
                    if (result.Status != FR_Status.Success || Device_AccountCode_StatusHistory.USR_Device_AccountCode_StatusHistoryID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    Device_AccountCode_StatusHistory.IsDeleted = true;
                    Device_AccountCode_StatusHistory.Save(Connection, Transaction);
                }

                ORM_USR_Device_AccountCode accountCode = new ORM_USR_Device_AccountCode();
                if (driver.USR_Device_AccountCodeID != Guid.Empty)
                {
                    var result = accountCode.Load(Connection, Transaction, driver.USR_Device_AccountCodeID);
                    if (result.Status != FR_Status.Success || accountCode.USR_Device_AccountCodeID == Guid.Empty)
                    {
                        var error = new FR_Guid();
                        error.ErrorMessage = "No Such ID";
                        error.Status       = FR_Status.Error_Internal;
                        return(error);
                    }
                    accountCode.IsDeleted = true;
                    accountCode.Save(Connection, Transaction);
                }

                var Device_AccountCode_UsageHistoryQuery = new ORM_USR_Device_AccountCode_UsageHistory.Query();
                Device_AccountCode_UsageHistoryQuery.Device_AccountCode_RefID = accountCode.USR_Device_AccountCodeID;
                Device_AccountCode_UsageHistoryQuery.IsDeleted    = false;
                Device_AccountCode_UsageHistoryQuery.Tenant_RefID = securityTicket.TenantID;

                var historyArray = ORM_USR_Device_AccountCode_UsageHistory.Query.Search(Connection, Transaction, Device_AccountCode_UsageHistoryQuery);
                if (historyArray != null && historyArray.Count > 0)
                {
                    foreach (var historyItem in historyArray)
                    {
                        historyItem.IsDeleted = true;
                        historyItem.Save(Connection, Transaction);
                    }
                }
            }



            return(returnValue);

            #endregion UserCode
        }
Пример #22
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L6DR_SD_1537 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here
            if (Parameter.CMN_BPT_BusinessParticipantID == Guid.Empty)
            {
                #region Create Mode

                #region BusinessParticipant


                ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
                bParticipant.CMN_BPT_BusinessParticipantID            = Guid.NewGuid();
                bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = Guid.NewGuid();
                bParticipant.IsNaturalPerson    = true;
                bParticipant.Tenant_RefID       = securityTicket.TenantID;
                bParticipant.Creation_Timestamp = DateTime.Now;
                bParticipant.Save(Connection, Transaction);

                #endregion

                #region Account

                ORM_USR_Account account = new ORM_USR_Account();

                account.Username    = Parameter.FirstName + "_" + Parameter.LastName;
                account.AccountType = 3;
                account.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
                account.Tenant_RefID       = securityTicket.TenantID;
                account.Creation_Timestamp = DateTime.Now;
                account.Save(Connection, Transaction);

                P_L2DC_GUDCfT_1505 codeParam = new P_L2DC_GUDCfT_1505();
                codeParam.codeLength = 8;
                var checkCodeValue = cls_GetUniqueDeviceCodeForTenant.Invoke(Connection, Transaction, codeParam, securityTicket).Result;

                ORM_USR_Device_AccountCode accountCode = new ORM_USR_Device_AccountCode();
                accountCode.Account_RefID                   = account.USR_AccountID;
                accountCode.AccountCode_Value               = checkCodeValue.CodeValue;
                accountCode.AccountCode_ValidFrom           = DateTime.Now;
                accountCode.AccountCode_CurrentStatus_RefID = Guid.NewGuid();
                accountCode.IsAccountCode_Expirable         = false;
                accountCode.Tenant_RefID       = securityTicket.TenantID;
                accountCode.Creation_Timestamp = DateTime.Now;
                accountCode.Save(Connection, Transaction);

                ORM_USR_Device_AccountCode_StatusHistory Device_AccountCode_StatusHistory = new ORM_USR_Device_AccountCode_StatusHistory();
                Device_AccountCode_StatusHistory.USR_Device_AccountCode_StatusHistoryID = accountCode.AccountCode_CurrentStatus_RefID;
                Device_AccountCode_StatusHistory.IsAccountCode_Active     = true;
                Device_AccountCode_StatusHistory.Device_AccountCode_RefID = accountCode.USR_Device_AccountCodeID;
                Device_AccountCode_StatusHistory.Tenant_RefID             = securityTicket.TenantID;
                Device_AccountCode_StatusHistory.Creation_Timestamp       = DateTime.Now;
                Device_AccountCode_StatusHistory.Save(Connection, Transaction);


                ORM_USR_Device_AccountCode_UsageHistory USR_Device_AccountCode_UsageHistory = new ORM_USR_Device_AccountCode_UsageHistory();
                USR_Device_AccountCode_UsageHistory.USR_Device_AccountCode_UsageHistoryID = Guid.NewGuid();
                USR_Device_AccountCode_UsageHistory.Tenant_RefID             = securityTicket.TenantID;
                USR_Device_AccountCode_UsageHistory.Device_AccountCode_RefID = accountCode.USR_Device_AccountCodeID;
                USR_Device_AccountCode_UsageHistory.Creation_Timestamp       = DateTime.Now;
                USR_Device_AccountCode_UsageHistory.Save(Connection, Transaction);


                #endregion

                #region PersonInfo and Adresses

                ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo();
                personInfo.CMN_PER_PersonInfoID = bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID;
                personInfo.Salutation_General   = Parameter.Salutation_General;
                personInfo.FirstName            = Parameter.FirstName;
                personInfo.LastName             = Parameter.LastName;
                personInfo.PrimaryEmail         = Parameter.PrimaryMail;
                personInfo.Address_RefID        = Guid.NewGuid();
                personInfo.Tenant_RefID         = securityTicket.TenantID;
                personInfo.Save(Connection, Transaction);

                ORM_CMN_PER_PersonInfo_2_Address personAdress = new ORM_CMN_PER_PersonInfo_2_Address();
                personAdress.AssignmentID             = Guid.NewGuid();
                personAdress.CMN_PER_PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                personAdress.CMN_Address_RefID        = personInfo.Address_RefID;
                personAdress.IsPrimary    = true;
                personAdress.Tenant_RefID = securityTicket.TenantID;
                personAdress.Save(Connection, Transaction);

                ORM_CMN_Address adress = new ORM_CMN_Address();
                adress.CMN_AddressID   = personInfo.Address_RefID;
                adress.City_Name       = Parameter.City_Name;
                adress.Province_Name   = Parameter.Province_Name;
                adress.Street_Name     = Parameter.Street_Name;
                adress.Street_Number   = Parameter.Street_Number;
                adress.City_PostalCode = Parameter.City_PostalCode;
                adress.Tenant_RefID    = securityTicket.TenantID;
                adress.Save(Connection, Transaction);

                #endregion

                #region Contacts

                foreach (var parContact in Parameter.Contacts)
                {
                    ORM_CMN_PER_CommunicationContact contact = new ORM_CMN_PER_CommunicationContact();
                    contact.Content          = parContact.Content;
                    contact.Contact_Type     = parContact.CMN_PER_CommunicationContact_TypeID;
                    contact.Tenant_RefID     = securityTicket.TenantID;
                    contact.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                    contact.Save(Connection, Transaction);
                }

                #endregion

                #region Driver To Employer

                ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant bpt_asBP = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant();
                bpt_asBP.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID = Guid.NewGuid();
                bpt_asBP.BusinessParticipant_RefID          = bParticipant.CMN_BPT_BusinessParticipantID;
                bpt_asBP.AssociatedParticipant_FunctionName = "Driver";
                bpt_asBP.Tenant_RefID = securityTicket.TenantID;
                bpt_asBP.AssociatedBusinessParticipant_RefID = Parameter.CMN_BPT_BusinessParticipantID_Of_Employer;
                bpt_asBP.Save(Connection, Transaction);

                #endregion

                #endregion
            }
            else
            {
                ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
                bParticipant.Load(Connection, Transaction, Parameter.CMN_BPT_BusinessParticipantID);

                var personInfo = new ORM_CMN_PER_PersonInfo();
                personInfo.Load(Connection, Transaction, bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID);
                personInfo.Salutation_General = Parameter.Salutation_General;
                personInfo.FirstName          = Parameter.FirstName;
                personInfo.LastName           = Parameter.LastName;
                personInfo.PrimaryEmail       = Parameter.PrimaryMail;
                personInfo.Save(Connection, Transaction);

                ORM_CMN_Address adress = new ORM_CMN_Address();
                adress.Load(Connection, Transaction, personInfo.Address_RefID);
                adress.City_Name     = Parameter.City_Name;
                adress.Province_Name = Parameter.Province_Name;
                adress.Street_Name   = Parameter.Street_Name;
                adress.Street_Number = Parameter.Street_Number;
                adress.Save(Connection, Transaction);

                foreach (var parContact in Parameter.Contacts)
                {
                    var query = new ORM_CMN_PER_CommunicationContact.Query();
                    query.Contact_Type     = parContact.CMN_PER_CommunicationContact_TypeID;
                    query.IsDeleted        = false;
                    query.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;

                    var contact = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, query).First();
                    contact.Content      = parContact.Content;
                    contact.Contact_Type = parContact.CMN_PER_CommunicationContact_TypeID;
                    contact.Save(Connection, Transaction);
                }

                var associationQuery = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query();
                associationQuery.BusinessParticipant_RefID = Parameter.CMN_BPT_BusinessParticipantID;
                associationQuery.IsDeleted = false;

                var bpt_asBP = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, associationQuery).First();
                bpt_asBP.AssociatedBusinessParticipant_RefID = Parameter.CMN_BPT_BusinessParticipantID_Of_Employer;
                bpt_asBP.Save(Connection, Transaction);
            }
            return(returnValue);

            #endregion UserCode
        }
        protected static FR_L5EM_GEFT_0959_Array Execute(DbConnection Connection, DbTransaction Transaction, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5EM_GEFT_0959_Array();
            List <L5EM_GEFT_0959>          employeeResultList = new List <L5EM_GEFT_0959>();
            ORM_CMN_BPT_EMP_Employee.Query employeeQuery      = new ORM_CMN_BPT_EMP_Employee.Query();
            employeeQuery.IsDeleted    = false;
            employeeQuery.Tenant_RefID = securityTicket.TenantID;
            List <ORM_CMN_BPT_EMP_Employee> employeeList = ORM_CMN_BPT_EMP_Employee.Query.Search(Connection, Transaction, employeeQuery);

            foreach (var employeeItem in employeeList)
            {
                L5EM_GEFT_0959           result   = new L5EM_GEFT_0959();
                ORM_CMN_BPT_EMP_Employee employee = new ORM_CMN_BPT_EMP_Employee();
                employee.Load(Connection, Transaction, employeeItem.CMN_BPT_EMP_EmployeeID);
                result.CMN_BPT_EMP_EmployeeID = employee.CMN_BPT_EMP_EmployeeID;
                result.Staff_Number           = employee.Staff_Number;
                result.StandardFunction       = employee.StandardFunction;

                ORM_USR_Account.Query accountQuery = new ORM_USR_Account.Query();
                accountQuery.BusinessParticipant_RefID = employee.BusinessParticipant_RefID;
                accountQuery.Tenant_RefID = securityTicket.TenantID;
                accountQuery.IsDeleted    = false;
                ORM_USR_Account account = ORM_USR_Account.Query.Search(Connection, Transaction, accountQuery).FirstOrDefault();
                if (account != null)
                {
                    result.USR_AccountID = account.USR_AccountID;
                }

                ORM_CMN_BPT_BusinessParticipant businessParticipant = new ORM_CMN_BPT_BusinessParticipant();
                businessParticipant.Load(Connection, Transaction, employee.BusinessParticipant_RefID);

                result.CMN_BPT_BusinessParticipantID = businessParticipant.CMN_BPT_BusinessParticipantID;
                result.DisplayName = businessParticipant.DisplayName;

                ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo();
                personInfo.Load(Connection, Transaction, businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID);
                result.CMN_PER_PersonInfoID = personInfo.CMN_PER_PersonInfoID;
                result.FirstName            = personInfo.FirstName;
                result.LastName             = personInfo.LastName;
                result.PrimaryEmail         = personInfo.PrimaryEmail;
                result.Title = personInfo.Title;
                result.ProfileImage_Document_RefID = personInfo.ProfileImage_Document_RefID;
                result.BirthDate = personInfo.BirthDate;

                ORM_CMN_BPT_EMP_EmploymentRelationship.Query workingContractQuery = new ORM_CMN_BPT_EMP_EmploymentRelationship.Query();
                workingContractQuery.Employee_RefID = employee.CMN_BPT_EMP_EmployeeID;
                workingContractQuery.IsDeleted      = false;
                workingContractQuery.Tenant_RefID   = securityTicket.TenantID;
                ORM_CMN_BPT_EMP_EmploymentRelationship employmentRelationship = ORM_CMN_BPT_EMP_EmploymentRelationship.Query.Search(Connection, Transaction, workingContractQuery).FirstOrDefault();

                result.CMN_BPT_EMP_EmploymentRelationshipID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                result.Work_StartDate = employmentRelationship.Work_StartDate;
                result.Work_EndDate   = employmentRelationship.Work_EndDate;

                //Address
                if (personInfo.Address_RefID != Guid.Empty)
                {
                    ORM_CMN_Address address = new ORM_CMN_Address();
                    address.Load(Connection, Transaction, personInfo.Address_RefID);
                    result.CMN_AddressID = address.CMN_AddressID;
                    result.Street_Name   = address.Street_Name;
                    result.Street_Number = address.Street_Number;
                    result.City_AdministrativeDistrict = address.City_AdministrativeDistrict;
                    result.City_Region     = address.City_Region;
                    result.City_Name       = address.City_Name;
                    result.City_PostalCode = address.City_PostalCode;
                    result.Province_Name   = address.Province_Name;
                    result.Country_Name    = address.Country_Name;
                    result.Country_ISOCode = address.Country_ISOCode;
                }

                //Contacts
                ORM_CMN_PER_CommunicationContact.Query comunicationContactQuery = new ORM_CMN_PER_CommunicationContact.Query();
                comunicationContactQuery.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID;
                comunicationContactQuery.Tenant_RefID     = securityTicket.TenantID;
                comunicationContactQuery.IsDeleted        = false;
                List <ORM_CMN_PER_CommunicationContact> comunicationContacts       = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, comunicationContactQuery);
                List <L5EM_GEFT_0959_Contacts>          resultComunicationContacts = new List <L5EM_GEFT_0959_Contacts>();
                foreach (var comunicationContact in comunicationContacts)
                {
                    ORM_CMN_PER_CommunicationContact_Type contactType = new ORM_CMN_PER_CommunicationContact_Type();
                    contactType.Load(Connection, Transaction, comunicationContact.CMN_PER_CommunicationContactID);
                    L5EM_GEFT_0959_Contacts resultComunicationContact = new L5EM_GEFT_0959_Contacts();
                    resultComunicationContact.CMN_PER_CommunicationContact_TypeID = contactType.CMN_PER_CommunicationContact_TypeID;
                    resultComunicationContact.CMN_PER_CommunicationContactID      = comunicationContact.CMN_PER_CommunicationContactID;
                    resultComunicationContact.Content = comunicationContact.Content;
                    resultComunicationContact.Type    = contactType.Type;
                    resultComunicationContacts.Add(resultComunicationContact);
                }
                result.Contacts = resultComunicationContacts.ToArray();


                //Employee workplace history
                ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment.Query employeeWorkplaceAssignmentsQuery = new ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment.Query();
                employeeWorkplaceAssignmentsQuery.CMN_BPT_EMP_Employee_RefID = employee.CMN_BPT_EMP_EmployeeID;
                employeeWorkplaceAssignmentsQuery.Tenant_RefID = securityTicket.TenantID;
                employeeWorkplaceAssignmentsQuery.IsDeleted    = false;
                List <ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment> employeeWorkplaceAssignemntsList = ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment.Query.Search(Connection, Transaction, employeeWorkplaceAssignmentsQuery);
                List <L5EM_GEFT_0959_EmployeeWorkplaceHistory>      employeeWorkplaceAssignments     = new List <L5EM_GEFT_0959_EmployeeWorkplaceHistory>();

                foreach (var workplaceAssignemns in employeeWorkplaceAssignemntsList)
                {
                    L5EM_GEFT_0959_EmployeeWorkplaceHistory item = new L5EM_GEFT_0959_EmployeeWorkplaceHistory();
                    item.BoundTo_Workplace_RefID = workplaceAssignemns.BoundTo_Workplace_RefID;
                    item.CMN_BPT_EMP_Employee_PlanGroup_RefID       = workplaceAssignemns.CMN_BPT_EMP_Employee_PlanGroup_RefID;
                    item.CMN_BPT_EMP_Employee_WorkplaceAssignmentID = workplaceAssignemns.CMN_BPT_EMP_Employee_WorkplaceAssignment;
                    item.Default_BreakTime_Template_RefID           = workplaceAssignemns.Default_BreakTime_Template_RefID;
                    item.IsBreakTimeCalculated_Actual   = workplaceAssignemns.IsBreakTimeCalculated_Actual;
                    item.IsBreakTimeCalculated_Planning = workplaceAssignemns.IsBreakTimeCalculated_Planning;
                    item.SequenceNumber = workplaceAssignemns.SequenceNumber;
                    item.WorkplaceAssignment_StartDate = workplaceAssignemns.WorkplaceAssignment_StartDate;

                    employeeWorkplaceAssignments.Add(item);
                }

                result.EmployeeWorkplaceHistory = employeeWorkplaceAssignments.ToArray();


                //Contracts

                ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query contractTermQuery = new ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query();
                contractTermQuery.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID;
                contractTermQuery.IsDeleted    = false;
                contractTermQuery.Tenant_RefID = securityTicket.TenantID;
                List <ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract> contracts = ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query.Search(Connection, Transaction, contractTermQuery);
                List <L5EM_GEFT_0959_WorkingContracts> resultContracts = new List <L5EM_GEFT_0959_WorkingContracts>();
                foreach (var contractToRelationship in contracts)
                {
                    L5EM_GEFT_0959_WorkingContracts resultContract = new L5EM_GEFT_0959_WorkingContracts();

                    ORM_CMN_BPT_EMP_WorkingContract workingContract = new ORM_CMN_BPT_EMP_WorkingContract();
                    workingContract.Load(Connection, Transaction, contractToRelationship.WorkingContract_RefID);
                    if (!workingContract.IsDeleted)
                    {
                        resultContract.CMN_BPT_EMP_WorkingContractID = workingContract.CMN_BPT_EMP_WorkingContractID;
                        resultContract.EmploymentRelationshipToWorkingContractAssignmentID = contractToRelationship.AssignmentID;
                        resultContract.IsWorkingContract_Active     = contractToRelationship.IsContract_Active;
                        resultContract.Contract_StartDate           = workingContract.Contract_StartDate;
                        resultContract.Contract_EndDate             = workingContract.Contract_EndDate;
                        resultContract.IsContractEndDateDefined     = workingContract.IsContractEndDateDefined;
                        resultContract.IsWorkTimeCalculated_InDays  = workingContract.IsWorkTimeCalculated_InDays;
                        resultContract.IsWorkTimeCalculated_InHours = workingContract.IsWorkTimeCalculated_InHours;
                        resultContract.R_WorkTime_DaysPerWeek       = workingContract.R_WorkTime_DaysPerWeek;
                        resultContract.R_WorkTime_HoursPerWeek      = workingContract.R_WorkTime_HoursPerWeek;

                        //Office hours
                        ORM_CMN_BPT_EMP_WorkingContract_2_WorkingDay.Query workingContractTermToWorkingDayQuery = new ORM_CMN_BPT_EMP_WorkingContract_2_WorkingDay.Query();
                        workingContractTermToWorkingDayQuery.CMN_BPT_EMP_WorkingContract_RefID = workingContract.CMN_BPT_EMP_WorkingContractID;
                        workingContractTermToWorkingDayQuery.Tenant_RefID = securityTicket.TenantID;
                        workingContractTermToWorkingDayQuery.IsDeleted    = false;
                        List <ORM_CMN_BPT_EMP_WorkingContract_2_WorkingDay> workingDayAssigments    = ORM_CMN_BPT_EMP_WorkingContract_2_WorkingDay.Query.Search(Connection, Transaction, workingContractTermToWorkingDayQuery);
                        List <L5EM_GEFT_0959_WeeklyOfficeHours>             resultWeeklyOfficeHours = new List <L5EM_GEFT_0959_WeeklyOfficeHours>();
                        foreach (var workingDayAssigment in workingDayAssigments)
                        {
                            ORM_CMN_CAL_WeeklyOfficeHours_Interval interval = new ORM_CMN_CAL_WeeklyOfficeHours_Interval();
                            interval.Load(Connection, Transaction, workingDayAssigment.CMN_CAL_WeeklyOfficeHours_Interval_RefID);

                            L5EM_GEFT_0959_WeeklyOfficeHours resultOfficeHour = new L5EM_GEFT_0959_WeeklyOfficeHours();
                            resultOfficeHour.CMN_CAL_WeeklyOfficeHours_IntervalID = interval.CMN_CAL_WeeklyOfficeHours_IntervalID;
                            resultOfficeHour.IsFriday           = interval.IsFriday;
                            resultOfficeHour.IsMonday           = interval.IsMonday;
                            resultOfficeHour.IsSaturday         = interval.IsSaturday;
                            resultOfficeHour.IsSunday           = interval.IsSunday;
                            resultOfficeHour.IsThursday         = interval.IsThursday;
                            resultOfficeHour.IsTuesday          = interval.IsTuesday;
                            resultOfficeHour.IsWednesday        = interval.IsWednesday;
                            resultOfficeHour.IsWholeDay         = interval.IsWholeDay;
                            resultOfficeHour.TimeFrom_InMinutes = interval.TimeFrom_InMinutes;
                            resultOfficeHour.TimeTo_InMinutes   = interval.TimeTo_InMinutes;
                            resultWeeklyOfficeHours.Add(resultOfficeHour);
                        }
                        resultContract.WeeklyOfficeHours = resultWeeklyOfficeHours.ToArray();


                        //Allowed absence reasons
                        ORM_CMN_BPT_EMP_WorkingContract_AllowedAbsenceReason.Query AllowedAbsenceReasonQuery = new ORM_CMN_BPT_EMP_WorkingContract_AllowedAbsenceReason.Query();
                        AllowedAbsenceReasonQuery.WorkingContract_RefID = resultContract.CMN_BPT_EMP_WorkingContractID;
                        AllowedAbsenceReasonQuery.Tenant_RefID          = securityTicket.TenantID;
                        AllowedAbsenceReasonQuery.IsDeleted             = false;
                        List <ORM_CMN_BPT_EMP_WorkingContract_AllowedAbsenceReason> allowedAbsenceReasons       = ORM_CMN_BPT_EMP_WorkingContract_AllowedAbsenceReason.Query.Search(Connection, Transaction, AllowedAbsenceReasonQuery);
                        List <L5EM_GEFT_0959_WorkingContractToLeaveRequest>         resultAllowedAbsenceReasons = new List <L5EM_GEFT_0959_WorkingContractToLeaveRequest>();
                        foreach (var allowedAbsenceReason in allowedAbsenceReasons)
                        {
                            ORM_CMN_BPT_STA_AbsenceReason absenceReason = new ORM_CMN_BPT_STA_AbsenceReason();
                            absenceReason.Load(Connection, Transaction, allowedAbsenceReason.STA_AbsenceReason_RefID);

                            L5EM_GEFT_0959_WorkingContractToLeaveRequest resultReasonresultReason = new L5EM_GEFT_0959_WorkingContractToLeaveRequest();
                            resultReasonresultReason.CMN_BPT_EMP_Employee_WorkingContract_AllowedAbsenceReasonID = allowedAbsenceReason.CMN_BPT_EMP_WorkingContract_AllowedAbsenceReasonID;
                            resultReasonresultReason.STA_AbsenceReason_RefID          = absenceReason.CMN_BPT_STA_AbsenceReasonID;
                            resultReasonresultReason.IsAbsenceCalculated_InDays       = allowedAbsenceReason.IsAbsenceCalculated_InDays;
                            resultReasonresultReason.IsAbsenceCalculated_InHours      = allowedAbsenceReason.IsAbsenceCalculated_InHours;
                            resultReasonresultReason.ContractAllowedAbsence_per_Month = allowedAbsenceReason.ContractAllowedAbsence_per_Month;
                            resultAllowedAbsenceReasons.Add(resultReasonresultReason);
                        }
                        resultContract.WorkingContractToLeaveRequest = resultAllowedAbsenceReasons.ToArray();

                        resultContracts.Add(resultContract);
                    }
                }
                result.WorkingContracts = resultContracts.ToArray();
                employeeResultList.Add(result);
            }
            returnValue.Result = employeeResultList.ToArray();
            //Put your code here
            return(returnValue);

            #endregion UserCode
        }
Пример #24
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5CA_SCER_0931 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            ORM_CMN_BPT_CTM_CatalogProductExtensionRequests request = new ORM_CMN_BPT_CTM_CatalogProductExtensionRequests();
            request.Load(Connection, Transaction, Parameter.RequestID);

            if (Parameter.SendAnswer)
            {
                ORM_USR_Account account = new ORM_USR_Account();
                account.Load(Connection, Transaction, securityTicket.AccountID);

                request.IfAnswerSent_By_BusinessParticipant_RefID = account.BusinessParticipant_RefID;
                request.IfAnswerSent_Date = DateTime.Now;
            }
            request.IsAnswerSent   = Parameter.SendAnswer;
            request.Request_Answer = Parameter.RequestAnswer;
            request.Save(Connection, Transaction);

            #region Add products
            ORM_CMN_BPT_CTM_CatalogProductExtensionRequest_Product product = null;

            if (Parameter.Products != null)
            {
                foreach (P_L5CA_SCER_0931a item in Parameter.Products)
                {
                    ORM_CMN_PRO_Product.Query prodQuery = new ORM_CMN_PRO_Product.Query()
                    {
                        CMN_PRO_ProductID = item.ProductID,
                        IsDeleted         = false,
                        Tenant_RefID      = securityTicket.TenantID
                    };
                    var prod = ORM_CMN_PRO_Product.Query.Search(Connection, Transaction, prodQuery).Single();
                    if (String.IsNullOrEmpty(prod.ProductITL))
                    {
                        prod.ProductITL = prod.CMN_PRO_ProductID.ToString();
                        prod.Save(Connection, Transaction);
                    }

                    if (item.IsDeleted)
                    {
                        ORM_CMN_BPT_CTM_CatalogProductExtensionRequest_Product.Query query = new ORM_CMN_BPT_CTM_CatalogProductExtensionRequest_Product.Query();
                        query.CatalogProductExtensionRequest_RefID = request.CMN_BPT_CTM_CatalogProductExtensionRequestID;
                        query.CMN_BPT_CTM_CatalogProductExtensionRequest_ProductID = item.Request_ProductID;
                        //query.Tenant_RefID = securityTicket.TenantID;
                        //ORM_CMN_BPT_CTM_CatalogProductExtensionRequest_Product.Query.SoftDelete(Connection, Transaction, query);
                        var itemToDelete = ORM_CMN_BPT_CTM_CatalogProductExtensionRequest_Product.Query.Search(Connection, Transaction, query).SingleOrDefault();
                        if (itemToDelete != default(ORM_CMN_BPT_CTM_CatalogProductExtensionRequest_Product))
                        {
                            itemToDelete.IsDeleted = true;
                            itemToDelete.Save(Connection, Transaction);
                        }
                        continue;
                    }

                    product = new ORM_CMN_BPT_CTM_CatalogProductExtensionRequest_Product();
                    product.CMN_BPT_CTM_CatalogProductExtensionRequest_ProductID = Guid.NewGuid();
                    product.CatalogProductExtensionRequest_RefID = request.CMN_BPT_CTM_CatalogProductExtensionRequestID;
                    product.CMN_PRO_Product_RefID = prod.CMN_PRO_ProductID;
                    product.Creation_Timestamp    = DateTime.Now;
                    product.Tenant_RefID          = securityTicket.TenantID;
                    product.Comment = "";
                    product.Save(Connection, Transaction);
                }
            }
            #endregion

            #region Save products in Catalog Products for Catalog Revision

            if (Parameter.Products != null)
            {
                // Find catalog revision
                var catalogRevision = ORM_CMN_PRO_Catalog_Revision.Query.Search(Connection, Transaction,
                                                                                new ORM_CMN_PRO_Catalog_Revision.Query
                {
                    PublishedBy_BusinessParticipant_RefID = Guid.Empty,
                    CMN_PRO_Catalog_RefID = request.RequestedFor_Catalog_RefID,
                    Tenant_RefID          = securityTicket.TenantID,
                    IsDeleted             = false
                }).OrderByDescending(x => x.PublishedOn_Date).FirstOrDefault();

                if (catalogRevision != null)
                {
                    foreach (P_L5CA_SCER_0931a item in Parameter.Products)
                    {
                        // Find product
                        var p = ORM_CMN_PRO_Product.Query.Search(Connection, Transaction,
                                                                 new ORM_CMN_PRO_Product.Query()
                        {
                            CMN_PRO_ProductID = item.ProductID,
                            IsDeleted         = false,
                            Tenant_RefID      = securityTicket.TenantID
                        }).Single();

                        // Find catalog product for product
                        var catalogProduct = ORM_CMN_PRO_Catalog_Product.Query.Search(Connection, Transaction,
                                                                                      new ORM_CMN_PRO_Catalog_Product.Query
                        {
                            CMN_PRO_Catalog_Revision_RefID = catalogRevision.CMN_PRO_Catalog_RevisionID,
                            CMN_PRO_Product_RefID          = p.CMN_PRO_ProductID,
                            Tenant_RefID = p.Tenant_RefID,
                            IsDeleted    = false
                        }).SingleOrDefault();


                        // If product not exist then add product to catalog products
                        if (catalogProduct == null)
                        {
                            // Find product variant for product
                            ORM_CMN_PRO_Product_Variant productVariant = null;
                            if (p.HasProductVariants)
                            {
                                productVariant = ORM_CMN_PRO_Product_Variant.Query.Search(Connection, Transaction,
                                                                                          new ORM_CMN_PRO_Product_Variant.Query
                                {
                                    CMN_PRO_Product_RefID    = p.CMN_PRO_ProductID,
                                    Tenant_RefID             = p.Tenant_RefID,
                                    IsStandardProductVariant = true,
                                    IsDeleted = false
                                }).OrderByDescending(x => x.Creation_Timestamp).FirstOrDefault();
                            }

                            // Create catalog product for product
                            catalogProduct = new ORM_CMN_PRO_Catalog_Product();
                            catalogProduct.CMN_PRO_Catalog_Revision_RefID = catalogRevision.CMN_PRO_Catalog_RevisionID;
                            catalogProduct.CMN_PRO_Product_RefID          = p.CMN_PRO_ProductID;
                            catalogProduct.CMN_PRO_Product_Variant_RefID  = p.HasProductVariants ? productVariant.CMN_PRO_Product_VariantID : Guid.Empty;
                            catalogProduct.Tenant_RefID = securityTicket.TenantID;
                            catalogProduct.Save(Connection, Transaction);
                        }
                        else
                        {
                            if (item.IsDeleted)
                            {
                                catalogProduct.IsDeleted = true;
                                catalogProduct.Save(Connection, Transaction);
                            }
                        }
                    }
                }
            }

            #endregion

            returnValue.Result = request.CMN_BPT_CTM_CatalogProductExtensionRequestID;

            return(returnValue);

            #endregion UserCode
        }
Пример #25
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5CO_CBH_1606 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            ORM_BIL_BillHeader billHeader = null;
            ORM_BIL_BillHeader_2_BillStatus billHeader2BillStatus  = null;
            ORM_CMN_UniversalContactDetail  universalContactDetail = null;

            var BillParam = Parameter.Bill_Parameter.BillHeaderData;

            #region Preloading data

            ORM_USR_Account account = new ORM_USR_Account();
            account.Load(Connection, Transaction, securityTicket.AccountID);
            var customer = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction,
                                                                 new ORM_CMN_BPT_CTM_Customer.Query()
            {
                CMN_BPT_CTM_CustomerID = BillParam.BillingReceiverCustomer.CMN_BPT_CTM_CustomerID
            }).SingleOrDefault();

            List <L3ACAAD_GCAfT_1612> customerAddresses = cls_Get_CustomerAddresses_for_CustomerID.Invoke(Connection, Transaction, new P_L3ACAAD_GCAfCID_1612 {
                CustomerID = BillParam.BillingReceiverCustomer.CMN_BPT_CTM_CustomerID
            }, securityTicket).Result.ToList();
            L3ACAAD_GCAfT_1612 customerAddress = customerAddresses.Where(x => x.AddressID == BillParam.BillingAddressID).SingleOrDefault();

            var incrNumberParam = new P_L2NR_GaIINfUA_1454()
            {
                GlobalStaticMatchingID = EnumUtils.GetEnumDescription(ENumberRangeUsageAreaType.BillNumber)
            };
            var billNumber = cls_Get_and_Increase_IncreasingNumber_for_UsageArea.Invoke(Connection, Transaction, incrNumberParam, securityTicket).Result.Current_IncreasingNumber;

            #endregion

            #region Universal Contact Detail

            universalContactDetail = new ORM_CMN_UniversalContactDetail()
            {
                CMN_UniversalContactDetailID = Guid.NewGuid(),
                Country_639_1_ISOCode        = customerAddress.Country_639_1_ISOCode,
                Country_Name      = customerAddress.Country_Name,
                Street_Name       = customerAddress.Street_Name,
                Street_Number     = customerAddress.Street_Number,
                Town              = customerAddress.Town,
                ZIP               = customerAddress.ZIP,
                Tenant_RefID      = account.Tenant_RefID,
                CompanyName_Line1 = BillParam.BillingReceiverCustomer.DisplayName,
                First_Name        = BillParam.BillingReceiverCustomer.FirstName,
                Last_Name         = BillParam.BillingReceiverCustomer.LastName,
                IsCompany         = BillParam.BillingReceiverCustomer.IsCompany
            };
            universalContactDetail.Save(Connection, Transaction);
            #endregion

            #region Bill Header

            billHeader = new ORM_BIL_BillHeader
            {
                BIL_BillHeaderID = Guid.NewGuid(),
                BillNumber       = billNumber,
                CreatedBy_BusinessParticipant_RefID     = account.BusinessParticipant_RefID,
                BillRecipient_BuisnessParticipant_RefID = customer.Ext_BusinessParticipant_RefID,
                TotalValue_BeforeTax     = 0,
                TotalValue_IncludingTax  = 0,
                BillingAddress_UCD_RefID = universalContactDetail.CMN_UniversalContactDetailID,
                DateOnBill     = BillParam.BillingDate,
                BillComment    = BillParam.Comment,
                Currency_RefID = cls_Get_DefaultCurrency_for_Tenant.Invoke(Connection, Transaction, securityTicket).Result.CMN_CurrencyID,
                BillHeader_PaymentCondition_RefID = Parameter.Bill_Parameter.BillHeaderData.PaymentTargetID,
                Tenant_RefID = securityTicket.TenantID
            };

            billHeader.Save(Connection, Transaction);

            #endregion

            #region Method of Payment

            var methodOfPayment = new CL1_BIL.ORM_BIL_BillHeader_MethodOfPayment
            {
                BIL_BillHeader_MethodOfPaymentID = Guid.NewGuid(),
                ACC_PAY_Type_RefID         = Parameter.Bill_Parameter.BillHeaderData.PaymentTypeID,
                BIL_BillHeader_RefID       = billHeader.BIL_BillHeaderID,
                IsPreferredMethodOfPayment = true,
                SequenceNumber             = 0,
                Tenant_RefID = securityTicket.TenantID
            };
            methodOfPayment.Save(Connection, Transaction);

            #endregion

            #region Bill Status - Created

            var statusCreated = ORM_BIL_BillStatus.Query.Search(Connection, Transaction,
                                                                new ORM_BIL_BillStatus.Query()
            {
                GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(EBillStatus.Created),
                Tenant_RefID             = account.Tenant_RefID,
                IsDeleted = false
            }).Single();

            billHeader2BillStatus = new ORM_BIL_BillHeader_2_BillStatus
            {
                AssignmentID         = Guid.NewGuid(),
                BIL_BillHeader_RefID = billHeader.BIL_BillHeaderID,
                BIL_BillStatus_RefID = statusCreated.BIL_BillStatusID,
                Tenant_RefID         = account.Tenant_RefID,
                IsCurrentStatus      = true
            };
            billHeader2BillStatus.Save(Connection, Transaction);

            #endregion

            returnValue.Result = billHeader.BIL_BillHeaderID;
            return(returnValue);

            #endregion UserCode
        }
Пример #26
0
        protected static FR_L5EM_GEFU_445 Execute(DbConnection Connection, DbTransaction Transaction, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var           returnValue = new FR_L5EM_GEFU_445();
            L5EM_GEFU_445 result      = new L5EM_GEFU_445();


            ORM_USR_Account account = new ORM_USR_Account();
            account.Load(Connection, Transaction, securityTicket.AccountID);
            if (account.USR_AccountID == Guid.Empty)
            {
                return(null);
            }

            ORM_CMN_BPT_EMP_Employee.Query employeeQuery = new ORM_CMN_BPT_EMP_Employee.Query();
            employeeQuery.IsDeleted    = false;
            employeeQuery.Tenant_RefID = securityTicket.TenantID;
            employeeQuery.BusinessParticipant_RefID = account.BusinessParticipant_RefID;
            List <ORM_CMN_BPT_EMP_Employee> employeeList = ORM_CMN_BPT_EMP_Employee.Query.Search(Connection, Transaction, employeeQuery);
            if (employeeList.Count != 0)
            {
                ORM_CMN_BPT_EMP_Employee employee = employeeList[0];
                result.CMN_BPT_EMP_EmployeeID = employee.CMN_BPT_EMP_EmployeeID;
                result.Staff_Number           = employee.Staff_Number;
                result.StandardFunction       = employee.StandardFunction;


                ORM_CMN_BPT_BusinessParticipant businessParticipant = new ORM_CMN_BPT_BusinessParticipant();
                businessParticipant.Load(Connection, Transaction, employee.BusinessParticipant_RefID);

                ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment.Query employeeWorkplaceAssignmentsQuery = new ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment.Query();
                employeeWorkplaceAssignmentsQuery.CMN_BPT_EMP_Employee_RefID = employee.CMN_BPT_EMP_EmployeeID;
                employeeWorkplaceAssignmentsQuery.Tenant_RefID = securityTicket.TenantID;
                employeeWorkplaceAssignmentsQuery.IsDeleted    = false;
                List <ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment> employeeWorkplaceAssignemntsList = ORM_CMN_BPT_EMP_Employee_WorkplaceAssignment.Query.Search(Connection, Transaction, employeeWorkplaceAssignmentsQuery);
                List <L5EM_GEFU_445_EmployeeWorkplaceHistory>       employeeWorkplaceAssignments     = new List <L5EM_GEFU_445_EmployeeWorkplaceHistory>();

                foreach (var workplaceAssignemns in employeeWorkplaceAssignemntsList)
                {
                    L5EM_GEFU_445_EmployeeWorkplaceHistory item = new L5EM_GEFU_445_EmployeeWorkplaceHistory();
                    item.BoundTo_Workplace_RefID = workplaceAssignemns.BoundTo_Workplace_RefID;
                    item.CMN_BPT_EMP_Employee_PlanGroup_RefID       = workplaceAssignemns.CMN_BPT_EMP_Employee_PlanGroup_RefID;
                    item.CMN_BPT_EMP_Employee_WorkplaceAssignmentID = workplaceAssignemns.CMN_BPT_EMP_Employee_WorkplaceAssignment;
                    item.Default_BreakTime_Template_RefID           = workplaceAssignemns.Default_BreakTime_Template_RefID;
                    item.IsBreakTimeCalculated_Actual   = workplaceAssignemns.IsBreakTimeCalculated_Actual;
                    item.IsBreakTimeCalculated_Planning = workplaceAssignemns.IsBreakTimeCalculated_Planning;
                    item.SequenceNumber = workplaceAssignemns.SequenceNumber;
                    item.WorkplaceAssignment_StartDate = workplaceAssignemns.WorkplaceAssignment_StartDate;

                    employeeWorkplaceAssignments.Add(item);
                }

                result.EmployeeWorkplaceHistory = employeeWorkplaceAssignments.ToArray();
            }
            returnValue.Result = result;
            //Put your code here
            return(returnValue);

            #endregion UserCode
        }
Пример #27
0
        protected static FR_L5CA_PNCV_1520 Execute(DbConnection Connection, DbTransaction Transaction, P_L5CA_PNCV_1520 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_L5CA_PNCV_1520();
            returnValue.Result = new L5CA_PNCV_1520();

            //Put your code here
            var account = new ORM_USR_Account();
            account.Load(Connection, Transaction, securityTicket.AccountID);

            #region Update active catalog revision

            ORM_CMN_PRO_Catalog_Revision rev = new ORM_CMN_PRO_Catalog_Revision();
            rev.Load(Connection, Transaction, Parameter.CMN_PRO_Catalog_RevisionID);
            rev.Valid_From    = Parameter.Valid_From;
            rev.Valid_Through = Parameter.Valid_Through;
            rev.Default_PricelistRelease_RefID        = Parameter.Default_PricelistRelease_RefID;
            rev.PublishedBy_BusinessParticipant_RefID = account.BusinessParticipant_RefID;
            rev.PublishedOn_Date = DateTime.Now;

            rev.Save(Connection, Transaction);

            #endregion

            #region Update catalog public/private status
            if (rev.RevisionNumber == 1)
            {
                ORM_CMN_PRO_Catalog catalog = new ORM_CMN_PRO_Catalog();
                catalog.Load(Connection, Transaction, rev.CMN_PRO_Catalog_RefID);

                catalog.IsPublicCatalog = Parameter.IsPublic;

                catalog.Save(Connection, Transaction);
            }
            #endregion

            #region Create new catalog revision

            ORM_CMN_PRO_Catalog_Revision newRev = new ORM_CMN_PRO_Catalog_Revision();
            newRev.CMN_PRO_Catalog_RevisionID = Guid.NewGuid();
            newRev.CMN_PRO_Catalog_RefID      = rev.CMN_PRO_Catalog_RefID;
            newRev.Tenant_RefID                = securityTicket.TenantID;
            newRev.Creation_Timestamp          = DateTime.Now;
            newRev.CatalogRevision_Description = "Revision for Catalog";
            newRev.CatalogRevision_Name        = "New Catalog Revision";
            newRev.IsDeleted      = false;
            newRev.RevisionNumber = rev.RevisionNumber + 1;
            newRev.Save(Connection, Transaction);

            #endregion

            #region Products

            var oldProducts = ORM_CMN_PRO_Catalog_Product.Query.Search(Connection, Transaction, new ORM_CMN_PRO_Catalog_Product.Query()
            {
                CMN_PRO_Catalog_Revision_RefID = rev.CMN_PRO_Catalog_RevisionID,
                IsDeleted    = false,
                Tenant_RefID = securityTicket.TenantID
            });

            if (oldProducts.Count == 0)
            {
                returnValue.Result.Status_Code    = -1;     // -1 no products in revision
                returnValue.Result.Status_Message = "no products in revision";
                return(returnValue);
            }

            //oldProductID - newProductID
            Dictionary <Guid, Guid> productsMapping = new Dictionary <Guid, Guid>();

            var productsWithoutPrices = ProductWithoutPrices(Connection, Transaction, Parameter, securityTicket, oldProducts);
            if (productsWithoutPrices.Count > 0)
            {
                returnValue.Result.Status_Code    = -2;                         // -2 => pricelist does not have price for product
                returnValue.Result.Status_Message = JsonConvert.SerializeObject(productsWithoutPrices);
                return(returnValue);
            }

            foreach (var item in oldProducts)
            {
                var newProduct = new ORM_CMN_PRO_Catalog_Product()
                {
                    CMN_PRO_Catalog_ProductID     = Guid.NewGuid(),
                    CMN_PRO_Product_Variant_RefID = item.CMN_PRO_Product_Variant_RefID,
                    Creation_Timestamp            = DateTime.Now,
                    Tenant_RefID = item.Tenant_RefID,
                    CMN_PRO_Catalog_Revision_RefID = newRev.CMN_PRO_Catalog_RevisionID,
                    CMN_PRO_Product_RefID          = item.CMN_PRO_Product_RefID,
                };

                newProduct.Save(Connection, Transaction);

                productsMapping.Add(item.CMN_PRO_Catalog_ProductID, newProduct.CMN_PRO_Catalog_ProductID);
            }

            #endregion

            #region ProductGroups

            var oldGroups = ORM_CMN_PRO_Catalog_ProductGroup.Query.Search(Connection, Transaction, new ORM_CMN_PRO_Catalog_ProductGroup.Query()
            {
                Catalog_Revision_RefID = rev.CMN_PRO_Catalog_RevisionID,
                IsDeleted = false
            });

            //oldGroupID - newGroupID
            Dictionary <Guid, Guid> groupsMapping = new Dictionary <Guid, Guid>();
            groupsMapping.Add(Guid.Empty, Guid.Empty);

            foreach (var item in oldGroups)
            {
                groupsMapping.Add(item.CMN_PRO_Catalog_ProductGroupID, Guid.NewGuid());
            }

            foreach (var item in oldGroups)
            {
                var newGroup = new ORM_CMN_PRO_Catalog_ProductGroup()
                {
                    CMN_PRO_Catalog_ProductGroupID   = groupsMapping[item.CMN_PRO_Catalog_ProductGroupID],
                    Catalog_Revision_RefID           = newRev.CMN_PRO_Catalog_RevisionID,
                    CatalogProductGroup_Name         = item.CatalogProductGroup_Name,
                    CatalogProductGroup_Parent_RefID = groupsMapping[item.CatalogProductGroup_Parent_RefID],
                    Creation_Timestamp = DateTime.Now,
                    Tenant_RefID       = item.Tenant_RefID
                };

                newGroup.Save(Connection, Transaction);

                var oldProductsInGroup = ORM_CMN_PRO_Catalog_Product_2_ProductGroup.Query.Search(Connection, Transaction, new ORM_CMN_PRO_Catalog_Product_2_ProductGroup.Query()
                {
                    CMN_PRO_Catalog_ProductGroup_RefID = item.CMN_PRO_Catalog_ProductGroupID,
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID
                });

                foreach (var product in oldProductsInGroup)
                {
                    if (groupsMapping.ContainsKey(product.CMN_PRO_Catalog_ProductGroup_RefID) && productsMapping.ContainsKey(product.CMN_PRO_Catalog_Product_RefID))
                    {
                        var newProduct = new ORM_CMN_PRO_Catalog_Product_2_ProductGroup()
                        {
                            AssignmentID = Guid.NewGuid(),
                            CMN_PRO_Catalog_ProductGroup_RefID = groupsMapping[product.CMN_PRO_Catalog_ProductGroup_RefID],
                            CMN_PRO_Catalog_Product_RefID      = productsMapping[product.CMN_PRO_Catalog_Product_RefID],
                            Creation_Timestamp = DateTime.Now,
                            Tenant_RefID       = item.Tenant_RefID
                        };

                        newProduct.Save(Connection, Transaction);
                    }
                }
            }


            #endregion

            returnValue.Result.Status_Code    = 1;
            returnValue.Result.Status_Message = "Success";
            returnValue.Result.ID             = newRev.CMN_PRO_Catalog_RevisionID;
            return(returnValue);

            #endregion UserCode
        }
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5CA_ACER_1055 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            ORM_CMN_BPT_CTM_CatalogProductExtensionRequests request = new ORM_CMN_BPT_CTM_CatalogProductExtensionRequests();
            var fetched = request.Load(Connection, Transaction, Parameter.RequestID);
            if (fetched.Status != FR_Status.Success || request.CMN_BPT_CTM_CatalogProductExtensionRequestID == Parameter.RequestID)
            {
                var error = new FR_Guid();
                error.ErrorMessage = "No Such ID";
                error.Status       = FR_Status.Error_Internal;
                return(error);
            }

            ORM_USR_Account account = new ORM_USR_Account();
            account.Load(Connection, Transaction, securityTicket.AccountID);

            request.IsAnswerSent = true;
            request.IfAnswerSent_By_BusinessParticipant_RefID = account.BusinessParticipant_RefID;
            request.IfAnswerSent_Date = DateTime.Now;
            request.Request_Answer    = Parameter.RequestAnswer;
            request.Save(Connection, Transaction);

            ArticleRequestAnswerCreation answer = new ArticleRequestAnswerCreation();
            answer.IntendedFor_TenantID = DBCrossTenantReader.Instance.GetPracticeTenantID();
            answer.CreatedBy_TenantID   = securityTicket.TenantID;
            answer.ArticleRequestITL    = Guid.Parse(request.CatalogProductExtensionRequestITL);

            #region Add products
            ORM_CMN_BPT_CTM_CatalogProductExtensionRequest_Product product = null;

            if (Parameter.Products != null)
            {
                foreach (P_L5CA_ACER_1055a item in Parameter.Products)
                {
                    product = new ORM_CMN_BPT_CTM_CatalogProductExtensionRequest_Product();
                    product.CMN_BPT_CTM_CatalogProductExtensionRequest_ProductID = Guid.NewGuid();
                    product.CMN_PRO_Product_RefID = item.ProductID;
                    product.Creation_Timestamp    = DateTime.Now;
                    product.Tenant_RefID          = securityTicket.TenantID;
                    product.CatalogProductExtensionRequest_RefID = request.CMN_BPT_CTM_CatalogProductExtensionRequestID;
                    product.Comment = "";
                    product.Save(Connection, Transaction);

                    var cmnProProduct = ORM_CMN_PRO_Product.Query.Search(Connection, Transaction,
                                                                         new ORM_CMN_PRO_Product.Query()
                    {
                        CMN_PRO_ProductID = item.ProductID,
                        Tenant_RefID      = securityTicket.TenantID,
                        IsDeleted         = false
                    }).Single();

                    Product prod = new Product();
                    prod.Product_ITL = cmnProProduct.ProductITL;
                    answer.Products.Add(prod);
                }
            }
            #endregion

            returnValue.Result = request.CMN_BPT_CTM_CatalogProductExtensionRequestID;

            return(returnValue);

            #endregion UserCode
        }
Пример #29
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5EM_SFE_1524 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();



            ORM_CMN_Address address = new ORM_CMN_Address();
            if (Parameter.CMN_AddressID != Guid.Empty)
            {
                var result = address.Load(Connection, Transaction, Parameter.CMN_AddressID);
                if (result.Status != FR_Status.Success || address.CMN_AddressID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            address.City_Name     = Parameter.City_Name;
            address.Street_Name   = Parameter.Street_Name;
            address.Street_Number = Parameter.Street_Number;
            address.Country_Name  = Parameter.Country_Name;
            address.Province_Name = Parameter.Province_Name;
            address.Tenant_RefID  = Parameter.TenantID;
            address.Save(Connection, Transaction);

            ORM_CMN_PER_PersonInfo person = new ORM_CMN_PER_PersonInfo();
            if (Parameter.CMN_PER_PersonInfoID != Guid.Empty)
            {
                var result = person.Load(Connection, Transaction, Parameter.CMN_PER_PersonInfoID);
                if (result.Status != FR_Status.Success || person.CMN_PER_PersonInfoID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }

            //person.AccountImage_URL = Parameter.ProfileImage_Document_RefID;
            person.FirstName     = Parameter.FirstName;
            person.LastName      = Parameter.LastName;
            person.PrimaryEmail  = Parameter.PrimaryEmail;
            person.Tenant_RefID  = Parameter.TenantID;
            person.Title         = Parameter.Title;
            person.Address_RefID = address.CMN_AddressID;
            person.BirthDate     = Parameter.BirthDate;
            person.Save(Connection, Transaction);

            ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant();
            if (Parameter.CMN_BPT_BusinessParticipantID != Guid.Empty)
            {
                var result = bParticipant.Load(Connection, Transaction, Parameter.CMN_BPT_BusinessParticipantID);
                if (result.Status != FR_Status.Success || bParticipant.CMN_BPT_BusinessParticipantID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            bParticipant.DisplayName = Parameter.DisplayName;
            bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID;
            bParticipant.IsNaturalPerson = true;
            bParticipant.Tenant_RefID    = Parameter.TenantID;
            bParticipant.Save(Connection, Transaction);
            ORM_CMN_BPT_EMP_Employee employee = new ORM_CMN_BPT_EMP_Employee();


            CSV2Core.DlTrace.Trace("Parameter.CMN_BPT_EMP_EmployeeID " + Parameter.CMN_BPT_EMP_EmployeeID);
            if (Parameter.CMN_BPT_EMP_EmployeeID != Guid.Empty)
            {
                var result = employee.Load(Connection, Transaction, Parameter.CMN_BPT_EMP_EmployeeID);
                if (result.Status != FR_Status.Success || employee.CMN_BPT_EMP_EmployeeID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }

            employee.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
            employee.Staff_Number     = Parameter.Staff_Number;
            employee.StandardFunction = Parameter.StandardFunction;
            employee.Tenant_RefID     = Parameter.TenantID;

            employee.Save(Connection, Transaction);
            CSV2Core.DlTrace.Trace("after save Parameter.CMN_BPT_EMP_EmployeeID " + Parameter.CMN_BPT_EMP_EmployeeID);
            CSV2Core.DlTrace.Trace("employee.Status_IsAlreadySaved " + employee.Status_IsAlreadySaved);

            ORM_CMN_BPT_EMP_EmploymentRelationship employeeRelationship = new ORM_CMN_BPT_EMP_EmploymentRelationship();
            if (Parameter.CMN_BPT_EMP_Employee_WorkingContractID != Guid.Empty)
            {
                var result = employeeRelationship.Load(Connection, Transaction, Parameter.CMN_BPT_EMP_Employee_WorkingContractID);
                if (result.Status != FR_Status.Success || employeeRelationship.CMN_BPT_EMP_EmploymentRelationshipID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }
            employeeRelationship.Work_StartDate = Parameter.Work_StartDate;
            employeeRelationship.Work_EndDate   = Parameter.Work_EndDate;
            employeeRelationship.Tenant_RefID   = Parameter.TenantID;
            employeeRelationship.Employee_RefID = employee.CMN_BPT_EMP_EmployeeID;
            employeeRelationship.Save(Connection, Transaction);



            if (Parameter.USR_AccountID != null && Parameter.USR_AccountID != Guid.Empty)
            {
                ORM_USR_Account account = new ORM_USR_Account();
                account.Load(Connection, Transaction, Parameter.USR_AccountID);
                account.USR_AccountID             = Parameter.USR_AccountID;
                account.Username                  = Parameter.username;
                account.DefaultLanguage_RefID     = Parameter.LanguageID;
                account.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
                account.Tenant_RefID              = Parameter.TenantID;
                account.Save(Connection, Transaction);

                var personToAccountQuery = new ORM_CMN_PER_PersonInfo_2_Account.Query();
                personToAccountQuery.Tenant_RefID      = securityTicket.TenantID;
                personToAccountQuery.USR_Account_RefID = account.USR_AccountID;
                personToAccountQuery.IsDeleted         = false;
                var personToAccounts = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, personToAccountQuery);
                if (personToAccounts.Count != 0)
                {
                    ORM_CMN_PER_PersonInfo_2_Account personToAccount = personToAccounts[0];
                    personToAccount.CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID;
                    personToAccount.USR_Account_RefID        = account.USR_AccountID;
                    personToAccount.Tenant_RefID             = securityTicket.TenantID;
                    personToAccount.Save(Connection, Transaction);
                }
                else
                {
                    ORM_CMN_PER_PersonInfo_2_Account personToAccount = new ORM_CMN_PER_PersonInfo_2_Account();
                    personToAccount.CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID;
                    personToAccount.USR_Account_RefID        = account.USR_AccountID;
                    personToAccount.Tenant_RefID             = securityTicket.TenantID;
                    personToAccount.Save(Connection, Transaction);
                }

                if (Parameter.Rights != null)
                {
                    foreach (var rightParam in Parameter.Rights)
                    {
                        var right = new ORM_USR_Account_FunctionLevelRight();
                        if (rightParam.RightID != Guid.Empty)
                        {
                            var result = right.Load(Connection, Transaction, rightParam.RightID);
                            if (result.Status != FR_Status.Success || right.USR_Account_FunctionLevelRightID == Guid.Empty)
                            {
                                right.USR_Account_FunctionLevelRightID = rightParam.RightID;
                                right.Tenant_RefID = Parameter.TenantID;
                                right.RightName    = rightParam.RightName;
                                right.FunctionLevelRights_Group_RefID = Guid.Empty;
                                right.Save(Connection, Transaction);
                            }
                        }

                        var right2account = new ORM_USR_Account_2_FunctionLevelRight();
                        right2account.Account_RefID            = account.USR_AccountID;
                        right2account.FunctionLevelRight_RefID = rightParam.RightID;
                        right2account.Tenant_RefID             = Parameter.TenantID;
                        right2account.Save(Connection, Transaction);
                    }
                }
            }

            returnValue.Result = employee.CMN_BPT_EMP_EmployeeID;
            return(returnValue);

            #endregion UserCode
        }
Пример #30
0
        protected static FR_L5RS_CSaRSH_0244 Execute(DbConnection Connection, DbTransaction Transaction, P_L5RS_CSaRSH_0244 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5RS_CSaRSH_0244();

            returnValue.Result = new L5RS_CSaRSH_0244();

            #region New ShipmentHeader
            var newShipmentHeaderId = Guid.NewGuid();

            #region Get Tenant Curency ID
            var defaultCurrency = cls_Get_DefaultCurrency_for_Tenant.Invoke(Connection, Transaction, securityTicket).Result;
            #endregion

            #region Create Shipment Status History
            #region Get 'Returned' Shipment status
            var returnedStatusId = ORM_LOG_SHP_Shipment_Status.Query.Search(
                Connection,
                Transaction,
                new ORM_LOG_SHP_Shipment_Status.Query()
            {
                GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(EShipmentStatus.Returned),
                Tenant_RefID             = securityTicket.TenantID
            }).FirstOrDefault().LOG_SHP_Shipment_StatusID;
            #endregion

            #region Fetch Status History 'performed by' User Account
            var performedByAccount = new ORM_USR_Account();
            performedByAccount.Load(Connection, Transaction, securityTicket.AccountID);
            #endregion

            #region Get ShipmentHeader Number
            var shipmentHeaderNumber = cls_Get_and_Increase_IncreasingNumber_for_UsageArea.Invoke(
                Connection,
                Transaction,
                new P_L2NR_GaIINfUA_1454()
            {
                GlobalStaticMatchingID = EnumUtils.GetEnumDescription(ENumberRangeUsageAreaType.SupplierReturnShipmentNumber)
            },
                securityTicket).Result.Current_IncreasingNumber;
            #endregion

            var newShipmentStatusHistory = new ORM_LOG_SHP_Shipment_StatusHistory();
            newShipmentStatusHistory.Creation_Timestamp                    = DateTime.Now;
            newShipmentStatusHistory.IsDeleted                             = false;
            newShipmentStatusHistory.LOG_SHP_Shipment_Header_RefID         = newShipmentHeaderId;
            newShipmentStatusHistory.LOG_SHP_Shipment_Status_RefID         = returnedStatusId;
            newShipmentStatusHistory.LOG_SHP_Shipment_StatusHistoryID      = Guid.NewGuid();
            newShipmentStatusHistory.PerformedBy_BusinessParticipant_RefID =
                performedByAccount == null
                ? Guid.Empty
                : performedByAccount.BusinessParticipant_RefID;
            newShipmentStatusHistory.Tenant_RefID = securityTicket.TenantID;
            #endregion

            #region Create Shipment Header Object
            var newShipmentHeader = new ORM_LOG_SHP_Shipment_Header();
            newShipmentHeader.Creation_Timestamp                 = DateTime.Now;
            newShipmentHeader.LOG_SHP_Shipment_HeaderID          = newShipmentHeaderId;
            newShipmentHeader.RecipientBusinessParticipant_RefID = Parameter.SupplierID;
            newShipmentHeader.ShipmentHeader_Currency_RefID      = defaultCurrency.CMN_CurrencyID;
            newShipmentHeader.ShipmentHeader_Number              = shipmentHeaderNumber;
            newShipmentHeader.ShipmentHeader_ValueWithoutTax     = 0;
            newShipmentHeader.ShipmentPriority   = 0;
            newShipmentHeader.ShipmentType_RefID = newShipmentStatusHistory.LOG_SHP_Shipment_StatusHistoryID;
            newShipmentHeader.Tenant_RefID       = securityTicket.TenantID;
            #endregion
            #endregion

            #region New ReturnShipment Header
            var newReturnShipmentHeaderId = Guid.NewGuid();
            var newReturnShipmentHeader   = new ORM_LOG_SHP_ReturnShipment_Header();
            newReturnShipmentHeader.Creation_Timestamp              = DateTime.Now;
            newReturnShipmentHeader.Ext_Shipment_Header_RefID       = newShipmentHeaderId;
            newReturnShipmentHeader.LOG_SHP_ReturnShipment_HeaderID = newReturnShipmentHeaderId;
            newReturnShipmentHeader.Tenant_RefID = securityTicket.TenantID;
            #endregion

            #region Save
            var resultHistory        = newShipmentStatusHistory.Save(Connection, Transaction);
            var resultHeader         = newShipmentHeader.Save(Connection, Transaction);
            var resultShipmentHeader = newReturnShipmentHeader.Save(Connection, Transaction);
            if (resultHistory.Status != FR_Status.Success || resultHeader.Status != FR_Status.Success || resultShipmentHeader.Status != FR_Status.Success)
            {
                returnValue.Status = FR_Status.Error_Internal;
                returnValue.Result = null;
            }
            else
            {
                returnValue.Status = FR_Status.Success;
                returnValue.Result.ShipmentHeaderID       = newShipmentHeaderId;
                returnValue.Result.ShipmentHeaderNumber   = newShipmentHeader.ShipmentHeader_Number;
                returnValue.Result.ReturnShipmentHeaderID = newReturnShipmentHeaderId;
            }
            #endregion

            return(returnValue);

            #endregion UserCode
        }