public void Sync()
        {
            var assoc = new UserAssociation[1];

            assoc[0] = new UserAssociation()
            {
                UserInteropID        = this.InteropID,
                CostCenterInteropIDs = this.CostCenters.Select(c => c.CostCenterInteropID).ToArray(),
                Addresses            = this.Addresses.Select(a => new AddressAssignment()
                {
                    AddressInteropID = a.AddressInteropID,
                    UseForBilling    = a.UseForBilling,
                    UseForShipping   = a.UseForShipping
                }).ToArray(),
                GroupInteropIDs = this.Groups.Where(g => !g.Remove).Select(g => g.GroupInteropID).ToArray(),
                OrderFields     = this.OrderFields.Select(o => new OrderFieldAssignment()
                {
                    Name             = o.Name,
                    OptionInteropIDs = new string[] { o.OptionInteropID }
                }).ToArray()
            };

            var error = _user.SyncAssociations(assoc, this.SharedSecret);

            if (error.Equals(null))
            {
                throw new Exception(error[0].InteropID + " failed: " + error[0].ErrorMessage);
            }
        }
Beispiel #2
0
        private static void MigrateUserAssociation(MemberAssociation item)
        {
            var db1    = new SourceDbContext();
            var db2    = new HostDbContext();
            var member = db1.Members.FirstOrDefault(m => m.MemberId == item.MemberId);

            if (member != null)
            {
                var user = db2.User.FirstOrDefault(x => x.Phone == member.Phone.ToString());
                var unit = db2.Units.FirstOrDefault(x => x.UnitId == item.UnitId);
                if (user != null && unit != null)
                {
                    var isAssociated = db2.UserAssociation.FirstOrDefault(x => x.UnitId == unit.Id && x.IdUser == user.Id);
                    if (isAssociated == null)
                    {
                        var ua = new UserAssociation
                        {
                            IdUser = user.Id,
                            UnitId = unit.Id
                        };
                        db2.UserAssociation.Add(ua);
                        db2.SaveChanges();
                    }
                }
            }
            db1.Dispose();
            db2.Dispose();
        }
Beispiel #3
0
        public async Task <IActionResult> ChooseAss(string assoc_name)
        {
            int    userId        = Int32.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier).Value);
            string rememberMeStr = HttpContext.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.UserData).Value;
            bool   rememberMe;

            if (rememberMeStr == "True")
            {
                rememberMe = true;
            }
            else
            {
                rememberMe = false;
            }
            Library.Data.Models.User user = await _repo.findById(userId);

            await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);

            List <UserAssociation> associations = await _assoc.getAllUserAss(userId);

            UserAssociation currentUserAssociation = new UserAssociation();
            int             i = 0;

            foreach (UserAssociation uA in associations)
            {
                string name = await _assoc.getAssociationNameById(uA.Id);

                if (name == assoc_name)
                {
                    currentUserAssociation = associations[i];
                    break;
                }
                i++;
            }
            int    role = (int)currentUserAssociation.IdRole;
            string rol  = "Operator";

            if (role == 1)
            {
                rol = "SysAdmin";
            }
            else if (role == 2)
            {
                rol = "AssocAdmin";
            }
            else if (role == 3)
            {
                rol = "Operator";
            }
            List <Claim> claims = new List <Claim>
            {
                new Claim(ClaimTypes.Name, user.Email),
                new Claim(ClaimTypes.Role, rol),
                new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()),
                new Claim(ClaimTypes.UserData, currentUserAssociation.IdAssociation.ToString())
            };
            var identity  = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
            var principal = new ClaimsPrincipal(identity);
            var props     = new AuthenticationProperties
            {
                ExpiresUtc   = DateTimeOffset.UtcNow.AddMinutes(300),
                IsPersistent = rememberMe
            };

            await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal, props);

            if (role == 1)
            {
                return(RedirectToAction("Index", "SysAdmin"));
            }
            else if (role == 2)
            {
                return(RedirectToAction("Index", "AsocAdmin"));
            }
            else if (role == 3)
            {
                return(RedirectToAction("Index", "Operator"));
            }

            return(RedirectToAction("ErrorLoggingIn"));
        }
        public static async Task <ConnectionStatus> UserConnected(string noticeHubId, string hubId, string peerId, string userId, string connectId, string languages)
        {
            var mbsvc = new UserAppMemberServiceProxy();
            var cntx  = Cntx;

            cntx.AcceptLanguages = languages;
            var memb = await mbsvc.LoadEntityGraphRecursAsync(cntx, AppId, userId, null, null);

            if (memb != null)
            {
                memb.StartAutoUpdating = true;
                memb.LastActivityDate  = DateTime.UtcNow;
                memb.AcceptLanguages   = languages;
                List <MemberCallback> callbacks;
                if (memb.ChangedMemberCallbacks == null)
                {
                    callbacks = new List <MemberCallback>();
                }
                else
                {
                    callbacks = new List <MemberCallback>(memb.ChangedMemberCallbacks);
                }
                var cbk = (from d in callbacks where d.HubID == hubId && d.ChannelID == peerId select d).SingleOrDefault();
                if (cbk == null)
                {
                    cbk = new MemberCallback
                    {
                        ApplicationID  = AppId,
                        UserID         = userId,
                        HubID          = hubId,
                        ChannelID      = peerId,
                        ConnectionID   = connectId,
                        IsDisconnected = false,
                        LastActiveDate = DateTime.UtcNow
                    };
                }
                else
                {
                    // it is very important to turn this on, otherwise the property will not be marked as modified.
                    // and the service will not save the change!
                    cbk.StartAutoUpdating = true;
                    cbk.ConnectionID      = connectId;
                    cbk.IsDisconnected    = false;
                    cbk.LastActiveDate    = DateTime.UtcNow;
                }
                memb.ChangedMemberCallbacks = new MemberCallback[] { cbk };
                await mbsvc.AddOrUpdateEntitiesAsync(cntx, new UserAppMemberSet(), new UserAppMember[] { memb });

                UserServiceProxy usvc = new UserServiceProxy();
                var u = await usvc.LoadEntityByKeyAsync(cntx, userId);

                memb.UserRef = u;

                var peerMb = await mbsvc.LoadEntityByKeyAsync(cntx, AppId, peerId);

                ConnectionStatus status = new ConnectionStatus();
                status.me = cbk;
                MemberCallbackServiceProxy mbcsvc = new MemberCallbackServiceProxy();
                var peerCb = await mbcsvc.LoadEntityByKeyAsync(cntx, userId, hubId, AppId, peerId);

                if (peerCb == null || peerCb.ConnectionID == null || peerCb.IsDisconnected)
                {
                    MemberNotificationTypeServiceProxy ntsvc = new MemberNotificationTypeServiceProxy();
                    var ntype = await ntsvc.LoadEntityByKeyAsync(cntx, 3);

                    var notifier = await mbcsvc.LoadEntityByKeyAsync(cntx, "System", noticeHubId, AppId, peerId);

                    if (notifier != null && notifier.ConnectionID != null && !notifier.IsDisconnected)
                    {
                        status.peerNotifier = notifier;
                        status.status       = PeerStatus.Notifiable;
                    }
                    MemberNotification n = new MemberNotification
                    {
                        ID            = Guid.NewGuid().ToString(),
                        Title         = string.Format(ResourceUtils.GetString("20dc5913998d0e9ed01360475e46a0f9", "{0} invites you to chat, is waiting ...", peerMb.AcceptLanguages), u.Username),
                        CreatedDate   = DateTime.UtcNow,
                        PriorityLevel = 0,
                        ReadCount     = 0,
                        ApplicationID = AppId,
                        TypeID        = 3,
                        UserID        = peerId
                    };
                    n.NoticeMsg          = "{ \"peerId\": \"" + userId + "\", \"peer\": \"" + u.Username + "\", \"connectId\": \"" + connectId + "\", \"msg\": \"" + n.Title + "\", \"isCancel\": false }";
                    n.IsNoticeDataLoaded = true;
                    MemberNotificationServiceProxy nsvc = new MemberNotificationServiceProxy();
                    var r = await nsvc.AddOrUpdateEntitiesAsync(cntx, new MemberNotificationSet(), new MemberNotification[] { n });

                    status.noticeType  = ntype.TypeName;
                    status.noticeMsg   = "{ \"peerId\": \"" + userId + "\", \"peer\": \"" + u.Username + "\", \"connectId\": \"" + connectId + "\", \"msg\": \"" + n.Title + "\", \"isCancel\": false }";
                    status.noticeRecId = r.ChangedEntities[0].UpdatedItem.ID;
                }
                else
                {
                    UserAssociationServiceProxy uasvc = new UserAssociationServiceProxy();
                    UserAssociation             utop  = await uasvc.LoadEntityByKeyAsync(cntx, userId, peerId, ApplicationContext.ChatAssocTypeId);

                    DateTime dt = DateTime.UtcNow;
                    if (utop == null)
                    {
                        utop = new UserAssociation
                        {
                            TypeID        = ApplicationContext.ChatAssocTypeId,
                            FromUserID    = userId,
                            ToUserID      = peerId,
                            CreateDate    = dt,
                            AssocCount    = 1,
                            LastAssoc     = dt,
                            InteractCount = 0,
                            Votes         = 0
                        };
                    }
                    else
                    {
                        utop.AssocCount++;
                    }
                    UserAssociation ptou = await uasvc.LoadEntityByKeyAsync(cntx, peerId, userId, ApplicationContext.ChatAssocTypeId);

                    if (ptou == null)
                    {
                        ptou = new UserAssociation
                        {
                            TypeID        = ApplicationContext.ChatAssocTypeId,
                            FromUserID    = peerId,
                            ToUserID      = userId,
                            CreateDate    = dt,
                            AssocCount    = 1,
                            LastAssoc     = dt,
                            InteractCount = 0,
                            Votes         = 0
                        };
                    }
                    else
                    {
                        ptou.AssocCount++;
                    }
                    await uasvc.AddOrUpdateEntitiesAsync(cntx, new UserAssociationSet(), new UserAssociation[] { utop, ptou });

                    status.status = PeerStatus.Connected;
                }
                if (peerCb != null)
                {
                    peerCb.UserAppMemberRef = peerMb;
                }
                status.peer = peerCb;
                return(status);
            }
            return(null);
        }
Beispiel #5
0
        public static async Task LeaveUserMessage(string chatHubId, string userId, string peerId, string replyId, string message)
        {
            var cntx = Cntx;
            UserServiceProxy usvc = new UserServiceProxy();
            var u = await usvc.LoadEntityByKeyAsync(cntx, userId);

            var peer = await usvc.LoadEntityByKeyAsync(cntx, peerId);

            ShortMessageServiceProxy msvc = new ShortMessageServiceProxy();
            PeerShotMessage          m    = new PeerShotMessage();
            var          now = DateTime.UtcNow;
            ShortMessage msg = new ShortMessage
            {
                ID            = Guid.NewGuid().ToString(),
                ApplicationID = AppId,
                TypeID        = ApplicationContext.ChatShortMsgTypeId,
                GroupID       = null,
                FromID        = userId,
                ToID          = peerId,
                ReplyToID     = string.IsNullOrEmpty(replyId) ? null : replyId,
                CreatedDate   = now,
                LastModified  = now,
                MsgText       = message,
                IsNotReceived = true
            };
            await msvc.AddOrUpdateEntitiesAsync(cntx, new ShortMessageSet(), new ShortMessage[] { msg });

            UserAssociationServiceProxy uasvc = new UserAssociationServiceProxy();
            DateTime dt = DateTime.UtcNow;
            List <UserAssociation> lass = new List <UserAssociation>();
            UserAssociation        utop = await uasvc.LoadEntityByKeyAsync(cntx, userId, peerId, ApplicationContext.ChatAssocTypeId);

            if (utop == null)
            {
                utop = new UserAssociation
                {
                    TypeID        = ApplicationContext.ChatAssocTypeId,
                    FromUserID    = userId,
                    ToUserID      = peerId,
                    CreateDate    = dt,
                    AssocCount    = 0,
                    LastAssoc     = dt,
                    InteractCount = 1,
                    Votes         = 0
                };
            }
            else
            {
                utop.InteractCount++;
            }
            lass.Add(utop);
            if (!string.IsNullOrEmpty(replyId))
            {
                UserAssociation ptou = await uasvc.LoadEntityByKeyAsync(cntx, peerId, userId, ApplicationContext.ChatAssocTypeId);

                if (ptou == null)
                {
                    ptou = new UserAssociation
                    {
                        TypeID        = ApplicationContext.ChatAssocTypeId,
                        FromUserID    = peerId,
                        ToUserID      = userId,
                        CreateDate    = dt,
                        AssocCount    = 0,
                        LastAssoc     = dt,
                        InteractCount = 0,
                        Votes         = 0
                    };
                }
                else
                {
                    ptou.InteractCount++;
                }
                lass.Add(ptou);
            }
            await uasvc.AddOrUpdateEntitiesAsync(cntx, new UserAssociationSet(), lass.ToArray());
        }
Beispiel #6
0
        public static async Task TogglePeerStatus(int statusType, string userId, string peerId)
        {
            var cntx = Cntx;
            UserAssociationServiceProxy uasvc = new UserAssociationServiceProxy();
            UserAssociation             ptou  = await uasvc.LoadEntityByKeyAsync(cntx, peerId, userId, ApplicationContext.ChatAssocTypeId);

            if (ptou != null)
            {
                bool changed = true;
                switch (statusType)
                {
                case 1:
                    ptou.NotifyButBlock = ptou.NotifyButBlock == null ? true : !ptou.NotifyButBlock.Value;
                    if (ptou.NotifyButBlock == true)
                    {
                        if (ptou.DoNotNotify == true)
                        {
                            ptou.DoNotNotify = false;
                        }
                        if (ptou.NoMessages == true)
                        {
                            ptou.NoMessages = false;
                        }
                    }
                    break;

                case 2:
                    ptou.DoNotNotify = ptou.DoNotNotify == null ? true : !ptou.DoNotNotify.Value;
                    if (ptou.DoNotNotify == true)
                    {
                        if (ptou.NotifyButBlock == true)
                        {
                            ptou.NotifyButBlock = false;
                        }
                        if (ptou.NoMessages == true)
                        {
                            ptou.NoMessages = false;
                        }
                    }
                    break;

                case 3:
                    ptou.NoMessages = ptou.NoMessages == null ? true : !ptou.NoMessages.Value;
                    if (ptou.NoMessages == true)
                    {
                        if (ptou.NotifyButBlock == true)
                        {
                            ptou.NotifyButBlock = false;
                        }
                        if (ptou.DoNotNotify == true)
                        {
                            ptou.DoNotNotify = false;
                        }
                    }
                    break;

                default:
                    changed = false;
                    break;
                }
                if (changed)
                {
                    await uasvc.AddOrUpdateEntitiesAsync(cntx, new UserAssociationSet(), new UserAssociation[] { ptou });
                }
            }
        }