private void ContactBirthdayMeeting(Contact contact, string username, User user)
        {
            int currentYear = DateTime.Now.Year;
            int currentMonth = DateTime.Now.Month;

            DateTime? birthday = contact.DateOfBirth;

            if (currentMonth > birthday.Value.Month)
            {
                currentYear++;
            }

            DateTime meetingTime = new DateTime(
                currentYear,
                birthday.Value.Month,
                birthday.Value.Day - 1,
                14, 0, 0);

            if (!db.Categories.Any(x => x.Name == "Birthday" && x.UserID == user.UserId))
            {
                Category category = new Category();
                category.Name = "Birthday";
                category.UserID = db.Users.SingleOrDefault(u => u.UserName == username).UserId;
                db.Categories.AddObject(category);
                db.SaveChanges();
            }

            Meeting meeting = new Meeting();
            meeting.UserID = user.UserId;
            meeting.CategoryID = db.Categories.SingleOrDefault(c => c.Name == "Birthday" && c.UserID == user.UserId).CategoryID;
            meeting.Time = meetingTime;
            meeting.Description = "Congratulate " + contact.FirstName + "!";
            meeting.Contacts.Add(contact);
            db.Meetings.AddObject(meeting);
        }
        public void InsertOrUpdate(Meeting meeting, List<int> contacts, string username)
        {
            meeting.UserID = db.Users.SingleOrDefault(u => u.UserName == username).UserId;

            if (meeting.MeetingID == default(int))
            {
                if (contacts != null)
                {
                    foreach (var contact in contacts)
                    {
                        Contact c = db.Contacts.SingleOrDefault(x => x.ContactID == contact);
                        meeting.Contacts.Add(c);
                    }
                }
                db.Meetings.AddObject(meeting);
            }
            else
            {
                Meeting m = db.Meetings.Include("Contacts").Single(x => x.MeetingID == meeting.MeetingID);
                m.Time = meeting.Time;
                m.Description = meeting.Description;
                m.Place = meeting.Place;
                m.CategoryID = meeting.CategoryID;
                m.Contacts.Clear();

                if (contacts != null)
                {
                    foreach (var contactId in contacts)
                    {
                        Contact contact = db.Contacts.SingleOrDefault(c => c.ContactID == contactId);
                        m.Contacts.Add(contact);
                    }
                }
            }
        }
Exemple #3
0
 /// <summary>
 /// Adds additional contacts to the Meeting
 /// </summary>
 /// <param name="meeting">The meeting.</param>
 /// <param name="contacts">The contacts.</param>
 public static void AddContacts(Meeting meeting, IEnumerable<Contact> contacts)
 {
     foreach (Contact c in contacts)
     {
         meeting.Contacts.Add(c);
     }
     db.SaveChanges();
 }
        public MeetingViewModel(Meeting meeting)
        {
            List<ContactViewModel> contactsCollection = new List<ContactViewModel>();
            foreach (var item in meeting.Contacts)
            {
                contactsCollection.Add(new ContactViewModel(item));
            }

            this.MeetingID = meeting.MeetingID;
            this.Time = meeting.Time;
            this.Description = meeting.Description;
            this.Place = meeting.Place;
            this.Category = new CategoryViewModel(meeting.Category);
            this.ContactModels = contactsCollection;
        }
Exemple #5
0
        /// <summary>
        /// Creates the specified Meeting
        /// </summary>
        /// <param name="user">The owner of this meeting</param>
        /// <param name="category">The category.</param>
        /// <param name="contacts">The contacts.</param>
        /// <param name="date">The date.</param>
        /// <param name="description">The description.</param>
        /// <param name="location">The location.</param>
        public static void Create(User user, Category category, IEnumerable<Contact> contacts, DateTime date, string description, string location)
        {
            Meeting m = new Meeting();
            m.User = user;
            m.Date = date;
            m.Description = description;
            m.Location = location;
            m.Category = category;

            foreach (Contact c in contacts)
            {
                m.Contacts.Add(c);
            }

            db.SaveChanges();
        }
 public void Delete(Meeting meeting)
 {
     Meeting m = db.Meetings.Include("Contacts").Single(x => x.MeetingID == meeting.MeetingID);
     db.Meetings.DeleteObject(m);
 }
        public Meeting ToMeeting()
        {
            Meeting meeting = new Meeting();

            CategoryViewModel categoryModel = new CategoryViewModel();
            categoryModel = this.Category;
            Category category = new Category();
            if (this.Category == null)
            {
                meeting.CategoryID = null;
            }
            else
            {
                category = categoryModel.ToCategory();
                meeting.CategoryID = category.CategoryID;
            }

            meeting.MeetingID = this.MeetingID;
            meeting.Time = this.Time;
            meeting.Description = this.Description;
            meeting.Place = this.Place;

            return meeting;
        }
 /// <summary>
 /// Create a new Meeting object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 /// <param name="date">Initial value of the Date property.</param>
 /// <param name="description">Initial value of the Description property.</param>
 /// <param name="userID">Initial value of the UserID property.</param>
 /// <param name="categoryID">Initial value of the CategoryID property.</param>
 public static Meeting CreateMeeting(global::System.Int32 id, global::System.DateTime date, global::System.String description, global::System.Int32 userID, global::System.Int32 categoryID)
 {
     Meeting meeting = new Meeting();
     meeting.ID = id;
     meeting.Date = date;
     meeting.Description = description;
     meeting.UserID = userID;
     meeting.CategoryID = categoryID;
     return meeting;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Meetings EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToMeetings(Meeting meeting)
 {
     base.AddObject("Meetings", meeting);
 }
 /// <summary>
 /// Create a new Meeting object.
 /// </summary>
 /// <param name="meetingID">Initial value of the MeetingID property.</param>
 /// <param name="time">Initial value of the Time property.</param>
 /// <param name="description">Initial value of the Description property.</param>
 public static Meeting CreateMeeting(global::System.Int32 meetingID, global::System.DateTime time, global::System.String description)
 {
     Meeting meeting = new Meeting();
     meeting.MeetingID = meetingID;
     meeting.Time = time;
     meeting.Description = description;
     return meeting;
 }
Exemple #11
0
 /// <summary>
 /// Removes all contacts from the Meeting
 /// </summary>
 /// <param name="meeting">The meeting.</param>
 public static void ClearContacts(Meeting meeting)
 {
     meeting.Contacts.Clear();
     db.SaveChanges();
 }
Exemple #12
0
        /// <summary>
        /// Changes the category of a Meeting
        /// </summary>
        /// <param name="meeting">The meeting.</param>
        /// <param name="category">The category.</param>
        public static void ChangeCategory(Meeting meeting, Category category)
        {
            meeting.Category = category;

            db.SaveChanges();
        }
Exemple #13
0
 /// <summary>
 /// Updates the specified meeting.
 /// </summary>
 /// <param name="meeting">The meeting.</param>
 /// <param name="category">The category.</param>
 /// <param name="date">The date.</param>
 /// <param name="description">The description.</param>
 /// <param name="location">The location.</param>
 public static void Update(Meeting meeting, Category category, DateTime date, string description, string location)
 {
     meeting.Category = category;
     meeting.Date = date;
     meeting.Description = description;
     meeting.Location = location;
     db.SaveChanges();
 }
Exemple #14
0
 /// <summary>
 /// Removes contact from the meeting
 /// </summary>
 /// <param name="meeting">The meeting.</param>
 /// <param name="contact">The contact.</param>
 public static void RemoveContact(Meeting meeting, Contact contact)
 {
     meeting.Contacts.Remove(contact);
     db.SaveChanges();
 }
Exemple #15
0
 /// <summary>
 /// Adds additional contact to the meeting
 /// </summary>
 /// <param name="meeting">The meeting.</param>
 /// <param name="contact">The contact.</param>
 public static void AddContact(Meeting meeting, Contact contact)
 {
     meeting.Contacts.Add(contact);
     db.SaveChanges();
 }