Пример #1
0
        public void AddInvitation(Notification notification)
        {
            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                //check if user send invitation to himself
                ApplicationUser user = db.Users.Find(notification.SenderID);
                if (string.Compare(user.UserName, notification.ReceiverID) == 0)
                {
                    Clients.Caller.error("Can not send invitation to yourself");
                    return;
                }

                notification.SendDateTime = DateTime.Now;
                string UserName = notification.ReceiverID;
                var receiver = db.Users.FirstOrDefault(x => x.UserName == notification.ReceiverID);
                if (receiver == null)
                {
                    //ERROR
                    Clients.Caller.error("Username does not exist");
                    return;
                }
                notification.ReceiverID = receiver.Id;

                db.Notification.Add(notification);
                db.SaveChanges();
                Clients.Group(UserName).newInvitation();
                Clients.Caller.acknowledge();
            }
        }
Пример #2
0
        public void AddNotification(Notification notification)
        {
            notification.SendDateTime = DateTime.Now;
            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                string UserName = notification.ReceiverID;
                var receiver = db.Users.FirstOrDefault(x => x.UserName == notification.ReceiverID);
                if (receiver == null)
                {
                    //ERROR
                    Clients.Caller.error("Username does not exist");
                    return;
                }
                notification.ReceiverID = receiver.Id;

                db.Notification.Add(notification);
                db.SaveChanges();
                Clients.Group(UserName).newNotification();
                Clients.Caller.acknowledge();
            }
        }