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);
        }
Ejemplo n.º 2
0
 public ContactViewModel(Contact contact)
 {
     this.ContactID = contact.ContactID;
     this.FirstName = contact.FirstName;
     this.LastName = contact.LastName;
     this.Email = contact.Email;
     this.DateOfBirth = contact.DateOfBirth;
     this.Phone = contact.Phone;
     this.Address = contact.Address;
     this.Comment = contact.Comment;
 }
Ejemplo n.º 3
0
        public ActionResult Create(Contact contact)
        {
            if (ModelState.IsValid)
            {
                db.Contacts.AddObject(contact);
                db.SaveChanges();
                return PartialView("GridData", new Contact[] { contact });
            }

            ViewBag.UserID = new SelectList(db.Users, "ID", "UserName", contact.UserID);
            return PartialView("Edit", contact);
        }
Ejemplo n.º 4
0
        public ActionResult Edit(Contact contact)
        {
            if (ModelState.IsValid)
            {
                db.Contacts.Attach(contact);
                db.ObjectStateManager.ChangeObjectState(contact, EntityState.Modified);
                db.SaveChanges();
                return PartialView("GridData", new Contact[] { contact });
            }

            ViewBag.UserID = new SelectList(db.Users, "ID", "UserName", contact.UserID);
            return PartialView(contact);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates the specified Contact.
        /// </summary>
        /// <param name="user">The owner of the Contacts</param>
        /// <param name="firstName">The first name.</param>
        /// <param name="lastName">The last name.</param>
        /// <param name="email">The email.</param>
        /// <param name="note">The note.</param>
        /// <param name="phone">The phone.</param>
        /// <param name="address">The address.</param>
        public static void Create(User user, string firstName, string lastName, string email, string note, string phone, string address)
        {
            Contact c = new Contact()
            {
                FirstName = firstName,
                LastName = lastName,
                Email = email,
                Note = note,
                Phone = phone,
                Address = address,
                User = user
            };

            db.Contacts.AddObject(c);
            db.SaveChanges();
        }
        public void InsertOrUpdate(Contact contact, string username)
        {
            var user = db.Users.SingleOrDefault(u => u.UserName == username);
            contact.UserID = user.UserId;

            if (contact.ContactID == default(int))
            {
                if (contact.DateOfBirth != null)
                {
                    ContactBirthdayMeeting(contact, username, user);
                }
                db.Contacts.AddObject(contact);
            }
            else
            {
                db.Contacts.Attach(contact);
                db.ObjectStateManager.ChangeObjectState(contact, EntityState.Modified);
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Create a new Contact object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 /// <param name="firstName">Initial value of the FirstName property.</param>
 /// <param name="userID">Initial value of the UserID property.</param>
 public static Contact CreateContact(global::System.Int32 id, global::System.String firstName, global::System.Int32 userID)
 {
     Contact contact = new Contact();
     contact.ID = id;
     contact.FirstName = firstName;
     contact.UserID = userID;
     return contact;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Contacts EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToContacts(Contact contact)
 {
     base.AddObject("Contacts", contact);
 }
 /// <summary>
 /// Create a new Contact object.
 /// </summary>
 /// <param name="contactID">Initial value of the ContactID property.</param>
 /// <param name="firstName">Initial value of the FirstName property.</param>
 public static Contact CreateContact(global::System.Int32 contactID, global::System.String firstName)
 {
     Contact contact = new Contact();
     contact.ContactID = contactID;
     contact.FirstName = firstName;
     return contact;
 }
Ejemplo n.º 10
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();
 }
Ejemplo n.º 11
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();
 }
Ejemplo n.º 12
0
 public void Delete(Contact contact)
 {
     db.Contacts.DeleteObject(contact);
 }
Ejemplo n.º 13
0
        public Contact ToContact()
        {
            Contact contact = new Contact();
            contact.ContactID = this.ContactID;
            contact.FirstName = this.FirstName;
            contact.LastName = this.LastName;
            contact.Email = this.Email;
            contact.DateOfBirth = this.DateOfBirth;
            contact.Phone = this.Phone;
            contact.Address = this.Address;
            contact.Comment = this.Comment;

            return contact;
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Updates the specified Contact.
 /// </summary>
 /// <param name="contact">The contact.</param>
 /// <param name="firstName">The first name.</param>
 /// <param name="lastName">The last name.</param>
 /// <param name="email">The email.</param>
 /// <param name="note">The note.</param>
 /// <param name="phone">The phone.</param>
 /// <param name="address">The address.</param>
 public static void Update(Contact contact, string firstName, string lastName, string email, string note, string phone, string address)
 {
     contact.FirstName = firstName;
     contact.LastName = lastName;
     contact.Email = email;
     contact.Note = note;
     contact.Phone = phone;
     contact.Address = address;
     db.SaveChanges();
 }