Exemplo n.º 1
0
        /// <summary>
        /// Convert an db organisation to a DTO
        /// </summary>
        /// <param name="scope">The scope in which the organisation is converted (only metadata from that scope will be included)</param>
        /// <param name="dborg">the database representation of the organisation</param>
        /// <returns>DTO representation of an organisation</returns>
        public static Auth.DTO.Organisation ConvertToDTO(string scope, Organisation dborg)
        {
            if (dborg != null)
            {
                Auth.DTO.Organisation organisation = new Auth.DTO.Organisation();
                organisation.Id   = dborg.Id;
                organisation.Name = dborg.Name;
                organisation.ParentOrganisation = dborg.ParentOrganisation == null ? Guid.Empty : dborg.ParentOrganisation.Id;

                // we call DataContext.Instance.Contracts instead of the relation, to avoid NULL error
                organisation.Contracts = DataContext.Instance.Contracts.Where(p => p.Organisation.Id == dborg.Id).Select(p => new Auth.DTO.Contract()
                {
                    Base64File      = p.Base64File,
                    ContractNo      = p.ContractNo,
                    Description     = p.Description,
                    Interval        = p.Interval,
                    IsActive        = p.IsActive,
                    NextInvoicedate = p.NextInvoicedate,
                    OngoingPayment  = p.OngoingPayment,
                    Payout          = p.Payout,
                    Title           = p.Title
                }).ToArray();
                organisation.Invoices = DataContext.Instance.Invoices.Where(p => p.Organisation.Id == dborg.Id).Select(p => new Auth.DTO.Invoice()
                {
                    Amout       = p.Amout,
                    Base64File  = p.Base64File,
                    Details     = p.Details,
                    DueDate     = p.DueDate,
                    Invoicedate = p.Invoicedate,
                    Invoiceno   = p.InvoiceNo,
                    Status      = p.Status,
                    Titel       = p.Titel
                }).ToArray();
                organisation.Metadata = DataContext.Instance.OrganisationMetadatas.Where(p => p.Organisation.Id == dborg.Id && p.Scope == scope).Select(p => new Common.DTO.MetaData()
                {
                    Key   = p.Key,
                    Scope = p.Scope,
                    Value = p.Value
                }).ToArray();

                organisation.Cluster = Cluster.ConvertToDTO(dborg.Cluster);

                return(organisation);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create default organisation (Monosoft)
        /// </summary>
        /// <param name="organisation">DTO of organisation</param>
        internal static void CreateDefault(Auth.DTO.Organisation organisation)
        {
            var dborg = DataContext.Instance.Organisations.Where(x => x.Id == organisation.Id).FirstOrDefault();

            if (dborg == null)
            {
                var dbcluster = DataContext.Instance.Clusters.Where(x => x.ClusterId == organisation.Cluster.ClusterId).FirstOrDefault();

                dborg = new Organisation()
                {
                    Id      = organisation.Id,
                    Name    = organisation.Name,
                    Cluster = dbcluster
                };
                DataContext.Instance.Organisations.Add(dborg);
                DataContext.Instance.SaveChanges();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Convert an db organisation to a DTO without detailed information
        /// </summary>
        /// <param name="scope">The scope in which the organisation is converted (only metadata from that scope will be included)</param>
        /// <param name="dborg">the database representation of the organisation</param>
        /// <returns>DTO representation of an organisation</returns>
        public static Auth.DTO.Organisation ConvertToDTOWoDetails(string scope, Organisation dborg)
        {
            if (dborg != null)
            {
                Auth.DTO.Organisation organisation = new Auth.DTO.Organisation();
                organisation.Id       = dborg.Id;
                organisation.Name     = dborg.Name;
                organisation.Metadata = DataContext.Instance.OrganisationMetadatas.Where(p => p.Organisation.Id == dborg.Id && p.Scope == scope).Select(p => new Common.DTO.MetaData()
                {
                    Key   = p.Key,
                    Scope = p.Scope,
                    Value = p.Value
                }).ToArray();

                organisation.Cluster = null;

                return(organisation);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// The message handler logic for organisation messages
        /// </summary>
        /// <param name="topicparts">topic parts</param>
        /// <param name="wrapper">wrapper object</param>
        /// <returns>resulting object or null</returns>
        public static ReturnMessageWrapper HandleMessage(string[] topicparts, Common.DTO.MessageWrapper wrapper)
        {
            CallContext cc = new CallContext(
                wrapper.OrgContext,
                new Common.DTO.Token()
            {
                Tokenid = wrapper.UserContextToken, Scope = GlobalValues.Scope
            },
                wrapper.IssuedDate);
            var operation = topicparts[1];

            Monosoft.Auth.DTO.Organisation organisation = new Auth.DTO.Organisation();

            if (cc.IsKeyAccountManager)
            {
                if (wrapper.MessageData != null)
                {
                    Auth.DTO.Organisation result = null;
                    switch (operation)
                    {
                    case "create":     // TESTET OK: 30-09-2018
                        organisation = Common.DTO.MessageWrapperHelper <Monosoft.Auth.DTO.Organisation> .GetData(wrapper);

                        result = Organisation.ConvertToDTO(cc.Scope, Organisation.Create(organisation, cc.Scope));
                        Common.MessageQueue.EventClient.Instance.RaiseEvent(GlobalValues.RouteOrganisationCreated, new Common.DTO.EventDTO(result, wrapper.Clientid, wrapper.Messageid));
                        return(ReturnMessageWrapper.CreateResult(true, wrapper, new System.Collections.Generic.List <LocalizedString>()
                        {
                            new LocalizedString()
                            {
                                Lang = "en", Text = "OK"
                            }
                        }, result));

                    case "update":     // TESTET OK: 30-09-2018
                        organisation = Common.DTO.MessageWrapperHelper <Monosoft.Auth.DTO.Organisation> .GetData(wrapper);

                        result = Organisation.ConvertToDTO(cc.Scope, Organisation.Update(organisation, cc.Scope));
                        Common.MessageQueue.EventClient.Instance.RaiseEvent(GlobalValues.RouteOrganisationUpdated, new Common.DTO.EventDTO(result, wrapper.Clientid, wrapper.Messageid));
                        return(ReturnMessageWrapper.CreateResult(true, wrapper, new System.Collections.Generic.List <LocalizedString>()
                        {
                            new LocalizedString()
                            {
                                Lang = "en", Text = "OK"
                            }
                        }, result));

                    case "delete":     // TESTET OK: 30-09-2018
                        var deleteid = Common.DTO.MessageWrapperHelper <Monosoft.Common.DTO.GuidIdDTO> .GetData(wrapper);

                        Common.DTO.Success isDeleted = new Common.DTO.Success();
                        isDeleted.Succeeded = Organisation.Delete(deleteid.Id);
                        Common.MessageQueue.EventClient.Instance.RaiseEvent(GlobalValues.RouteOrganisationDeleted, new Common.DTO.EventDTO(isDeleted, wrapper.Clientid, wrapper.Messageid));
                        return(ReturnMessageWrapper.CreateResult(true, wrapper, new System.Collections.Generic.List <LocalizedString>()
                        {
                            new LocalizedString()
                            {
                                Lang = "en", Text = "OK"
                            }
                        }, isDeleted));

                    default:     /*log error event*/
                        // Common.MessageQueue.Diagnostics.Instance.LogEvent("Unknow topic for Organisation.", operation + " is unknown", Common.DTO.Severity.Information, wrapper.OrgContext);
                        break;
                    }
                }
            }

            if (wrapper.MessageData != null)
            { // operations without any security conserns
                switch (operation)
                {
                case "create":
                case "update":
                case "delete":
                    Common.MessageQueue.Diagnostics.Instance.LogEvent("Missing credentials.", "Missing credentials for " + operation + " is unknown", Common.DTO.Severity.Information, wrapper.OrgContext);
                    return(ReturnMessageWrapper.CreateResult(true, wrapper, new System.Collections.Generic.List <LocalizedString>()
                    {
                        new LocalizedString()
                        {
                            Lang = "en", Text = "missing credentials"
                        }
                    }, null));

                case "getbyids":
                    var getbyid = Common.DTO.MessageWrapperHelper <Monosoft.Common.DTO.GuidIdsDTO> .GetData(wrapper);

                    var orgsList = Organisation.GetByIds(getbyid.Ids).Select(p => Organisation.ConvertToDTOWoDetails(cc.Scope, p)).ToList();
                    var results  = Organisation.ConvertToDTO(cc.Scope, orgsList);
                    Common.MessageQueue.EventClient.Instance.RaiseEvent(GlobalValues.RouteOrganisationRead, new Common.DTO.EventDTO(results, wrapper.Clientid, wrapper.Messageid));
                    return(ReturnMessageWrapper.CreateResult(true, wrapper, new System.Collections.Generic.List <LocalizedString>()
                    {
                        new LocalizedString()
                        {
                            Lang = "en", Text = "OK"
                        }
                    }, results));

                default:     /*log error event*/
                    Common.MessageQueue.Diagnostics.Instance.LogEvent("Unknow topic for Organisation.", operation + " is unknown", Common.DTO.Severity.Information, wrapper.OrgContext);
                    return(ReturnMessageWrapper.CreateResult(true, wrapper, new System.Collections.Generic.List <LocalizedString>()
                    {
                        new LocalizedString()
                        {
                            Lang = "en", Text = operation + " is unknown"
                        }
                    }, null));
                }
            }

            Common.MessageQueue.Diagnostics.Instance.LogEvent("Missing MessageData.", "MessageData is null", Common.DTO.Severity.Information, wrapper.OrgContext);
            return(ReturnMessageWrapper.CreateResult(true, wrapper, new System.Collections.Generic.List <LocalizedString>()
            {
                new LocalizedString()
                {
                    Lang = "en", Text = "MessageData is null"
                }
            }, null));
        }