public Category ToCategory()
 {
     Category item = new Category();
     item.Name = this.Name;
     item.CategoryID = this.CategoryID;
     return item;
 }
 public void Delete(Category category)
 {
     if (!category.Meetings.Any())
     {
         db.Categories.DeleteObject(category);
     }
 }
        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);
        }
示例#4
0
 /// <summary>
 /// Creates new Category
 /// </summary>
 /// <param name="user">Owner of the Category</param>
 /// <param name="categoryName">Name of the category.</param>
 /// <param name="categoryDescription">The category description.</param>
 public static void Create(User user, string categoryName, string categoryDescription)
 {
     Category c = new Category();
     c.Name = categoryName;
     c.Description = categoryDescription;
     c.User = user;
     db.AddToCategories(c);
     db.SaveChanges();
 }
        public ActionResult Create(Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categories.AddObject(category);
                db.SaveChanges();
                return PartialView("GridData", new Category[] { category });
            }

            ViewBag.UserID = new SelectList(db.Users, "ID", "UserName", category.UserID);
            return PartialView("Edit", category);
        }
 public CategoryViewModel(Category category)
 {
     if (category != null)
     {
         this.CategoryID = category.CategoryID;
         this.Name = category.Name;
     }
     else
     {
         this.CategoryID = 0;
         this.Name = string.Empty;
     }
 }
        public ActionResult Edit(Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Attach(category);
                db.ObjectStateManager.ChangeObjectState(category, EntityState.Modified);
                db.SaveChanges();
                return PartialView("GridData", new Category[] { category });
            }

            ViewBag.UserID = new SelectList(db.Users, "ID", "UserName", category.UserID);
            return PartialView(category);
        }
        public void InsertOrUpdate(Category category, string username)
        {
            category.UserID = db.Users.SingleOrDefault(u => u.UserName == username).UserId;

            if (category.CategoryID == default(int))
            {
                db.Categories.AddObject(category);
            }
            else
            {
                db.Categories.Attach(category);
                db.ObjectStateManager.ChangeObjectState(category, EntityState.Modified);
            }
        }
示例#9
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();
        }
 /// <summary>
 /// Create a new Category object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="userID">Initial value of the UserID property.</param>
 public static Category CreateCategory(global::System.Int32 id, global::System.String name, global::System.Int32 userID)
 {
     Category category = new Category();
     category.ID = id;
     category.Name = name;
     category.UserID = userID;
     return category;
 }
示例#11
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();
        }
示例#12
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Categories EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCategories(Category category)
 {
     base.AddObject("Categories", category);
 }
        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 Category object.
 /// </summary>
 /// <param name="categoryID">Initial value of the CategoryID property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="userID">Initial value of the UserID property.</param>
 public static Category CreateCategory(global::System.Int32 categoryID, global::System.String name, global::System.Guid userID)
 {
     Category category = new Category();
     category.CategoryID = categoryID;
     category.Name = name;
     category.UserID = userID;
     return category;
 }
示例#15
0
 /// <summary>
 /// Updates the specified category.
 /// </summary>
 /// <param name="category">The category.</param>
 /// <param name="categoryName">Name of the category.</param>
 /// <param name="categoryDescription">The category description.</param>
 public static void Update(Category category, string categoryName, string categoryDescription)
 {
     category.Name = categoryName;
     category.Description = categoryDescription;
     db.SaveChanges();
 }
示例#16
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();
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Categories EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCategories(Category category)
 {
     base.AddObject("Categories", category);
 }