Beispiel #1
0
        public void CreateUpdates(string message, string PostCategory, int id)
        {
            string myname = Membership.GetUser().UserName;
            UserProfile userprofile = db.UserProfiles.SingleOrDefault(p => p.UserProfileId == id);
            //UserProfile myprofile = db.UserProfiles.SingleOrDefault(p => p.UserName == myname);
            CategoryPost post = new CategoryPost
            {
                Type = 0,
                PostMessage = message,
                TimeStamp = DateTime.Now,
                Category = PostCategory,
                Postedby = id
            };

            //userprofile.Updates.Add(record); //add own update record
            userprofile.CategoryPosts.Add(post);
        }
Beispiel #2
0
        public ActionResult AddEvent(Event model, string[] InvitesId)
        {
            if (model.EventName == null)
                {
                    model.EventName = "default";
                }
                if (model.EventDate == DateTime.MinValue)
                {
                    model.EventDate = DateTime.Now;
                }
                if (model.EventTime == DateTime.MinValue)
                {
                    model.EventTime = DateTime.Now;
                }
                if (model.EventDesc == null)
                {
                    model.EventDesc = "default";
                }

                /*
                //Adding Tags
                //To keep track of tags being added
                List<Tag> AddedTags = new List<Tag>();

                //Adding the Tag
                if (model.EventDesc!= null)
                {
                    string EventDescTags = model.EventDesc.ToString();
                    //If written new tag
                    string[] Tags = EventDescTags.Split(' ');
                    foreach (string tagname in Tags)
                    {
                        string Trimtagname = tagname.Trim();
                        Tag Item = followPeersDB.Tags.FirstOrDefault(p => p.TagName.ToLower() == Trimtagname.ToLower());
                        if (Item != null)
                        {
                            if (AddedTags.Contains(Item) != true && !(Item.Events.Any(p => p.EventId == model.EventId)))
                            {
                                Item.TagLinkedItems += 1;
                                model.Tags.Add(Item);
                                Item.Events.Add(model);
                                AddedTags.Add(Item);
                            }
                        }
                        else //If (Item == null)
                        {
                            //Create a New Tag
                            Tag NewItem = new Tag();
                            NewItem.TagName = Trimtagname;
                            NewItem.TagLinkedItems = 1;
                            followPeersDB.Tags.Add(NewItem);
                            model.Tags.Add(NewItem);
                            NewItem.Events.Add(model);
                            AddedTags.Add(NewItem);
                        }
                    }
                }
                //-----------End of Adding Tags*/

                string name = Membership.GetUser().UserName;
                UserProfile user = db.UserProfiles.SingleOrDefault(p => p.UserName == name);

                //Adding event for User (Creator of Event) and Adding User to Event
                user.Events.Add(model);
                model.Invitees.Add(user);

                //Adding event for All invitees and all invitees to event
                if (InvitesId != null)
                {
                    foreach (var InviteeId in InvitesId)
                    {
                        if (InviteeId != null && InviteeId != "")
                        {
                            int id = Convert.ToInt32(InviteeId);
                            UserProfile invitee = db.UserProfiles.SingleOrDefault(p => p.UserProfileId == id);

                            try
                            {
                                if (user.UserProfileId != id)
                                {
                                    invitee.Events.Add(model);
                                    model.Invitees.Add(invitee);

                                    //For Notifications
                                    string makeMessage = user.FirstName + " invited you to an event : '" + model.EventName+"'";
                                    int eventnumber = followPeersDB.Events.Count() + 1;
                                    Notification newnoti = new Notification
                                    {
                                        message = makeMessage,
                                        link = "/Event/EventDetail/" + eventnumber,
                                        New = true,
                                    };

                                    invitee.Notifications.Add(newnoti);
                                }

                            }
                            catch
                            {
                            }
                        }
                    }
                }

                //Add event to database
                db.Events.Add(model);

                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();

                //Calculating Event Id to Create Notification
                int EventId = followPeersDB.Events.Count();

                //If Event was created, we find it and create a notification
                CategoryPost post = new CategoryPost
                {
                    TimeStamp = DateTime.Now,
                    PostMessage = "Created a new Event titled " + model.EventName,
                    Type = 3,
                    Postedby = user.UserProfileId,
                    Category = model.EventDesc,
                    Link = "/Event/EventDetail/" + EventId,
                };
                user.CategoryPosts.Add(post);

                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();

                return RedirectToAction("Index");
        }
Beispiel #3
0
        public void CreateUpdates(Course model, string category)
        {
            string name = Membership.GetUser().UserName;
            myprofile = db.UserProfiles.SingleOrDefault(p => p.UserName == name);
            string CreateMessage = "New Course Created titled '" + model.CourseName + "'";
            int coursenumber = db.Courses.Count() + 1;
            if (category != null)
            {
                if(category.Contains(';'))
                {
                    string[] Tagnames = category.Split(';');
                    CategoryPost post = new CategoryPost
                    {

                        TimeStamp = DateTime.Now,
                        PostMessage = CreateMessage,
                        Link = "/Course/Details/" + coursenumber,
                        Type = 4,
                        Postedby = myprofile.UserProfileId,
                        Category = Tagnames[0],
                    };

                    myprofile.CategoryPosts.Add(post);
                }
            }

            //For own updates
            Update record = new Update
            {
                Time = DateTime.Now,
                message = CreateMessage,
                link = "/Course/Details/" + coursenumber,
                New = true,
                Own = true,
                type = 6,
                owner = myprofile.UserProfileId
            };

            myprofile.Updates.Add(record); //add own update record

            db.Entry(myprofile).State = EntityState.Modified;
            db.SaveChanges();
        }
        //
        // POST: /PatentModel/Create
        public void CreateUpdates(string message, string link, int type, int id, string category)
        {
            string myname = Membership.GetUser().UserName;
            UserProfile userprofile = db.UserProfiles.SingleOrDefault(p => p.UserProfileId == id);
            UserProfile myprofile = db.UserProfiles.SingleOrDefault(p => p.UserName == myname);
            Update record = new Update
            {
                Time = DateTime.Now,
                message = message,
                link = link,
                New = true,
                Own = true,
                type = type,
                owner = myprofile.UserProfileId
            };

            userprofile.Updates.Add(record); //add own update record

            if (category != null)
            {
                CategoryPost post = new CategoryPost
                    {
                        TimeStamp = DateTime.Now,
                        PostMessage = message,
                        Link = link,
                        Type = 5,
                        Postedby = myprofile.UserProfileId,
                        Category = category,
                    };

                userprofile.CategoryPosts.Add(post);
            }

            string name = userprofile.UserName;
            IQueryable<string> custQuery = from cust in db.Relationships where cust.personBName == name select cust.personAName;

            foreach (string personAname in custQuery)
            {
                Update record2 = new Update
                {
                    Time = DateTime.Now,
                    message = message,
                    link = link,
                    New = true,
                    Own = false,
                    type = type,
                    owner = userprofile.UserProfileId
                };

                UserProfile tempuserprofile = db.UserProfiles.SingleOrDefault(p => p.UserName == personAname);

                tempuserprofile.Updates.Add(record2);
            } //add a new update record for the followers
        }
Beispiel #5
0
        public void CreateUpdates(Group model, string category)
        {
            if (category != null)
            {
                string GroupOwner = Membership.GetUser().UserName;
                myprofile = followPeersDB.UserProfiles.SingleOrDefault(p => p.UserName == GroupOwner);
                CategoryPost post = new CategoryPost
                {
                    TimeStamp = DateTime.Now,
                    PostMessage = "New Group Has Recently Been Created titled" + model.Name,
                    Link = "/Groups/Details/"+model.GroupId,
                    Type = 2,
                    Postedby = myprofile.UserProfileId,
                    Category = category,
                };

                myprofile.CategoryPosts.Add(post);
            }
        }