public ActionResult AddEvent(Event model)
        {
            if (ModelState.IsValid)
            {
                if (model.EventName == null)
                {
                    model.EventName = "default";
                }
                if (model.EventDateTime == DateTime.MinValue)
                {
                    model.EventDateTime = DateTime.Now;
                }
                if (model.EventDesc == null)
                {
                    model.EventDesc = "default";
                }

                string name = Membership.GetUser().UserName;
                UserProfile user = db.UserProfiles.SingleOrDefault(p => p.UserName == name);
                //model.UserProfile = user;
                //user.Publication.Add(publicationmodel);

                try
                {
                    model.EventId = db.Events.Count() + 1;
                }
                catch
                {//If Events has no items yet ie count() returns an error
                    model.EventId = 1;
                }
                //Add the model to the table
                db.Events.Add(model);

                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            else
            {  //Something went wrong in creating the event
                return RedirectToAction("AddEvent");
            }
        }
Exemple #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");
        }
Exemple #3
0
        public ActionResult EventEdit(Event model)
        {
            /*Event select = followPeersDB.Events.FirstOrDefault(p => p.EventId == model.EventId);
            /*if (model.EventTime == DateTime.MinValue)
            {
                //Assign Event its old time value in this case
                model.EventTime = select.EventTime;
            }
            select.EventName = model.EventName;
            select.EventDate = model.EventDate;
            select.EventTime = model.EventTime;
            select.EventDesc = model.EventDesc;

            db.Entry(select).State = EntityState.Modified;
            db.SaveChanges();
            return RedirectToAction("EventDetail", new { id = model.EventId });*/

            if (ModelState.IsValid)
            {
                Event select = followPeersDB.Events.FirstOrDefault(p => p.EventId == model.EventId);
                select.EventName = model.EventName;
                select.EventDate = model.EventDate;
                select.EventTime = model.EventTime;
                select.EventDesc = model.EventDesc;

                db.Entry(select).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("EventDetail", new { id = model.EventId });
            }
            return RedirectToAction("EventDetail", new { id = model.EventId });
        }