Ejemplo n.º 1
0
        public static object addMessageInGroup(int groupId, string body = "")
        {
            UsersContext db   = new UsersContext();
            UserProfile  user = db.UserProfiles.Find(System.Web.Security.Membership.GetUser().ProviderUserKey);

            var group = db.Groups.Find(groupId);
            var g     = new Message {
                writer = user, body = Message.linkyPictureInBox(body), timeAdded = DateTime.Now, messageGroup = group
            };
            object myMessage = new { };

            if (group.members.Contains(user) || group.Admin == user)
            {
                db.Messages.Add(g);
                db.SaveChanges();
                myMessage = new { MessageId = g.MessageId, body = g.body, timeAdded = g.timeAdded.ToString("g"), writer = new { UserId = g.writer.UserId, UserName = g.writer.UserName, profilePic = g.writer.profilepic }, usersLiked = g.usersLiked, usersShared = g.usersShared, Comments = g.Comments };
            }

            //var context = GlobalHost.ConnectionManager.GetHubContext("Notifiy"); //GetHubContext<Notifiy>();
            //context.Clients.All().addMessage(myMessage);

            return(myMessage);
        }
Ejemplo n.º 2
0
        public static string uploadPic(HttpPostedFileBase photo, bool Isprofile = false, string name = "", string body = "")
        {
            UsersContext db   = new UsersContext();
            var          user = db.UserProfiles.Find(Membership.GetUser().ProviderUserKey);
            //1mega in bytes
            int    maxsize    = 1048576;
            var    TempFolder = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "_TEMP");
            Random r          = new Random();
            string savepath   = TempFolder + DateTime.Now.GetHashCode() + r.Next() + photo.FileName;

            if (photo != null && photo.ContentLength < maxsize && photo.ContentType.Contains("image/"))
            {
                photo.SaveAs(savepath);
                ;
                var message = new Message {
                    writer = user, body = body, timeAdded = DateTime.Now, MessagePicture = new List <Picture>()
                };
                message.MessagePicture.Add(new Picture {
                    name = name, pictureUrl = savepath, owner = user
                });
                db.Messages.Add(message);
                if (Isprofile == true)
                {
                    user.profilepic = savepath;
                }
                db.SaveChanges();
            }
            else
            {
                return("empty file or heavy one");
            }



            return(savepath);
        }