Beispiel #1
0
        public static async Task <dynamic> AddChannel(string id, int typeId, string address, string comment)
        {
            CommunicationServiceProxy csvc = new CommunicationServiceProxy();
            Communication             c    = new Communication();

            c.ID            = Guid.NewGuid().ToString();
            c.TypeID        = typeId;
            c.UserID        = id;
            c.ApplicationID = ApplicationContext.App.ID;
            c.AddressInfo   = address;
            c.Comment       = comment;
            var result = await csvc.AddOrUpdateEntitiesAsync(Cntx, new CommunicationSet(), new Communication[] { c });

            if ((result.ChangedEntities[0].OpStatus & (int)EntityOpStatus.Added) > 0)
            {
                c = result.ChangedEntities[0].UpdatedItem;
                c.CommunicationTypeRef = await csvc.MaterializeCommunicationTypeRefAsync(Cntx, c);

                var dc = new { id = c.ID, label = c.DistinctString, addr = c.AddressInfo, comment = c.Comment, typeId = c.CommunicationTypeRef.TypeName };
                return(new { ok = true, msg = "", data = dc });
            }
            else
            {
                return new { ok = false, msg = ResourceUtils.GetString("954122aa46fdc842a03ed8b89acdd125", "Add failed!") }
            };
        }
 public static async Task<UserDetailsVM> GetUserDetails(string id, bool direct = false)
 {
     UserDetailServiceProxy udsvc = new UserDetailServiceProxy();
     var cntx = Cntx;
     cntx.DirectDataAccess = direct;
     var details = await udsvc.LoadEntityByKeyAsync(cntx, ApplicationContext.App.ID, id);
     UserDetailsVM m = null;
     if (details != null)
     {
         if (!details.IsDescriptionLoaded)
         {
             details.Description = udsvc.LoadEntityDescription(cntx, ApplicationContext.App.ID, id);
             details.IsDescriptionLoaded = true;
         }
         m = new UserDetailsVM { Details = details };
         m.IsPhotoAvailable = !string.IsNullOrEmpty(details.PhotoMime);
     }
     else
     {
         m = new UserDetailsVM();
         m.IsPhotoAvailable = false;
     }
     UserDetailSet uds = new UserDetailSet();
     m.Genders = uds.GenderValues;
     QueryExpresion qexpr = new QueryExpresion();
     qexpr.OrderTks = new List<QToken>(new QToken[] { 
         new QToken { TkName = "ID" },
         new QToken { TkName = "asc" }
     });
     CommunicationTypeServiceProxy ctsvc = new CommunicationTypeServiceProxy();
     var lct = await ctsvc.QueryDatabaseAsync(Cntx, new CommunicationTypeSet(), qexpr);
     m.ChannelTypes = lct.ToArray();
     CommunicationServiceProxy csvc = new CommunicationServiceProxy();
     //qexpr = new QueryExpresion();
     //qexpr.OrderTks = new List<QToken>(new QToken[] { 
     //    new QToken { TkName = "TypeID" },
     //    new QToken { TkName = "asc" }
     //});
     //qexpr.FilterTks = new List<QToken>(new QToken[] { 
     //    new QToken { TkName = "UserID" },
     //    new QToken { TkName = "==" },
     //    new QToken { TkName = "\"" + id + "\"" },
     //    new QToken { TkName = "&&" },
     //    new QToken { TkName = "ApplicationID" },
     //    new QToken { TkName = "==" },
     //    new QToken { TkName = "\"" + ApplicationContext.App.ID + "\"" }
     //});
     //var lc = await csvc.QueryDatabaseAsync(Cntx, new CommunicationSet(), qexpr);
     var fkeys = new CommunicationSetConstraints
     {
         ApplicationIDWrap = new ForeignKeyData<string> { KeyValue = ApplicationContext.App.ID },
         TypeIDWrap = null, // no restriction on types
         UserIDWrap = new ForeignKeyData<string> { KeyValue = id }
     };
     var lc = await csvc.ConstraintQueryAsync(Cntx, new CommunicationSet(), fkeys, null);
     foreach (var c in lc)
     {
         c.Comment = await csvc.LoadEntityCommentAsync(Cntx, c.ID);
         c.IsCommentLoaded = true;
         c.CommunicationTypeRef = await csvc.MaterializeCommunicationTypeRefAsync(Cntx, c);
         m.Channels.Add(new { id = c.ID, label = c.DistinctString, addr = c.AddressInfo, comment = c.Comment, typeId = c.CommunicationTypeRef.TypeName });
     }
     return m;
 }
Beispiel #3
0
        public static async Task <UserDetailsVM> GetUserDetails(string id, bool direct = false)
        {
            UserDetailServiceProxy udsvc = new UserDetailServiceProxy();
            var cntx = Cntx;

            cntx.DirectDataAccess = direct;

            var details = await udsvc.LoadEntityByKeyAsync(cntx, GuidMix(ApplicationContext.App.ID, id));

            UserDetailsVM m = null;

            if (details != null)
            {
                if (!details.IsDescriptionLoaded)
                {
                    details.Description         = udsvc.LoadEntityDescription(cntx, GuidMix(ApplicationContext.App.ID, id));
                    details.IsDescriptionLoaded = true;
                }
                m = new UserDetailsVM {
                    Details = details
                };
                m.IsPhotoAvailable = !string.IsNullOrEmpty(details.PhotoMime);
            }
            else
            {
                m = new UserDetailsVM();
                m.IsPhotoAvailable = false;
            }
            UserDetailSet uds = new UserDetailSet();

            m.Genders = uds.GenderValues;
            QueryExpresion qexpr = new QueryExpresion();

            qexpr.OrderTks = new List <QToken>(new QToken[] {
                new QToken {
                    TkName = "ID"
                },
                new QToken {
                    TkName = "asc"
                }
            });
            CommunicationTypeServiceProxy ctsvc = new CommunicationTypeServiceProxy();
            var lct = await ctsvc.QueryDatabaseAsync(Cntx, new CommunicationTypeSet(), qexpr);

            m.ChannelTypes = lct.ToArray();
            CommunicationServiceProxy csvc = new CommunicationServiceProxy();
            var fkeys = new CommunicationSetConstraints
            {
                ApplicationIDWrap = new ForeignKeyData <string> {
                    KeyValue = ApplicationContext.App.ID
                },
                TypeIDWrap = null, // no restriction on types
                UserIDWrap = new ForeignKeyData <string> {
                    KeyValue = id
                }
            };
            var lc = await csvc.ConstraintQueryAsync(Cntx, new CommunicationSet(), fkeys, null);

            foreach (var c in lc)
            {
                c.Comment = await csvc.LoadEntityCommentAsync(Cntx, c.ID);

                c.IsCommentLoaded      = true;
                c.CommunicationTypeRef = await csvc.MaterializeCommunicationTypeRefAsync(Cntx, c);

                m.Channels.Add(new { id = c.ID, label = c.DistinctString, addr = c.AddressInfo, comment = c.Comment, typeId = c.CommunicationTypeRef.TypeName });
            }
            return(m);
        }
 public static async Task<dynamic> AddChannel(string id, int typeId, string address, string comment)
 {
     CommunicationServiceProxy csvc = new CommunicationServiceProxy();
     Communication c = new Communication();
     c.ID = Guid.NewGuid().ToString();
     c.TypeID = typeId;
     c.UserID = id;
     c.ApplicationID = ApplicationContext.App.ID;
     c.AddressInfo = address;
     c.Comment = comment;
     var result = await csvc.AddOrUpdateEntitiesAsync(Cntx, new CommunicationSet(), new Communication[] { c });
     if ((result.ChangedEntities[0].OpStatus & (int)EntityOpStatus.Added) > 0)
     {
         c = result.ChangedEntities[0].UpdatedItem;
         c.CommunicationTypeRef = await csvc.MaterializeCommunicationTypeRefAsync(Cntx, c);
         var dc = new { id = c.ID, label = c.DistinctString, addr = c.AddressInfo, comment = c.Comment, typeId = c.CommunicationTypeRef.TypeName };
         return new { ok = true, msg = "", data = dc };
     }
     else
         return new { ok = false, msg = ResourceUtils.GetString("954122aa46fdc842a03ed8b89acdd125", "Add failed!") };
 }