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 static void MeetingsForUser(User user, int numberMeetings)
        {
            IEnumerable<Contact> contacts = ContactDAL.GetAllByUser(user);

            if (user.Contacts.Count > 3)
            {
                contacts = user.Contacts.Where(x => x.ID % 3 == 0);
            }
            else if (user.Contacts.Count > 0)
            {
                contacts.First();
            }
            else
            {
                //Console.WriteLine("The selected User don't have enough
            }

            for (int i = 0; i < numberMeetings; i++)
            {
                DateTime date = Faker.DateTimeFaker.DateTime();
                string location = Faker.LocationFaker.City() + ", " + Faker.LocationFaker.Street();
                string description = Faker.CompanyFaker.BS();
                Category category = user.Categories.ToArray()[Faker.NumberFaker.Number(0, user.Categories.ToArray().Count() - 1)];

                MeetingDAL.Create(user, category, contacts, date, description, location);
            }
        }
Beispiel #3
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();
 }
 /// <summary>
 /// Generate number of categories for the selected user
 /// </summary>
 /// <param name="user">The user.</param>
 /// <param name="numberCategories">The number categories.</param>
 public static void CategoriesForUser(User user, int numberCategories)
 {
     for (int i = 0; i < numberCategories; i++)
     {
         string[] categories = { "Business", "Personal", "Co-workers", "Official Lunch", "Training" };
         string categoryName = categories[i % 5];
         string categoryDescription = Faker.CompanyFaker.BS();
         WebCalendar.DAL.CategoryDAL.Create(user, categoryName, categoryDescription);
     }
 }
        public ActionResult Create(User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.AddObject(user);
                db.SaveChanges();
                return PartialView("GridData", new User[] { user });
            }

            return PartialView("Edit", user);
        }
        public ActionResult Edit(User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Attach(user);
                db.ObjectStateManager.ChangeObjectState(user, EntityState.Modified);
                db.SaveChanges();
                return PartialView("GridData", new User[] { user });
            }

            return PartialView(user);
        }
        public static void ContactsForUser(User user, int numberContacts)
        {
            for (int i = 0; i < numberContacts; i++)
            {
                string firstName = Faker.NameFaker.FirstName();
                string lastName = Faker.NameFaker.LastName();
                string email = Faker.StringFaker.Alpha(3) + Faker.InternetFaker.Email();
                string note = Faker.CompanyFaker.BS();
                string phone = Faker.PhoneFaker.Phone();
                string address = Faker.LocationFaker.City() + ", " + Faker.LocationFaker.Street();

                ContactDAL.Create(user, firstName, lastName, email, note, phone, address);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Creates new User
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="password">The password.</param>
        /// <param name="email">The email.</param>
        /// <param name="firstName">The first name.</param>
        /// <param name="lastName">The last name.</param>
        /// <returns>The newly created User</returns>
        public static User Create(string username, string password, string email, string firstName, string lastName)
        {
            User u = new User();
            u.UserName = username;
            u.Email = email;
            u.FirstName = firstName;
            u.LastName = lastName;
            u.PasswordSalt = CreateSalt();
            u.Password = CreatePasswordHash(password, u.PasswordSalt);

            db.AddToUsers(u);
            db.SaveChanges();

            return u;
        }
Beispiel #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();
        }
Beispiel #10
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();
        }
Beispiel #11
0
        //private static string CreateSalt()
        //{
        //    RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
        //    byte[] buff = new byte[32];
        //    rng.GetBytes(buff);
        //    return Convert.ToBase64String(buff);
        //}
        //private static string CreatePasswordHash(string password, string salt)
        //{
        //    string saltAndPwd = "mixing" + password + "with some" + salt;
        //    System.Security.Cryptography.SHA1 hash = System.Security.Cryptography.SHA1.Create();
        //    System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
        //    byte[] combined = encoder.GetBytes(saltAndPwd);
        //    hash.ComputeHash(combined);
        //    string hashCode = Convert.ToBase64String(hash.Hash);
        //    return hashCode;
        //}
        public MembershipUser CreateUser(string username, string password, string email)
        {
            User u = new User();

            u.UserName = username;
            u.Email = email;
            u.PasswordSalt = UserDAL.CreateSalt();
            u.Password = UserDAL.CreatePasswordHash(password, u.PasswordSalt);
            db.AddToUsers(u);
            db.SaveChanges();

            return CreateMembershipUser(u.UserName);
        }
 /// <summary>
 /// Create a new User object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 /// <param name="userName">Initial value of the UserName property.</param>
 /// <param name="password">Initial value of the Password property.</param>
 /// <param name="passwordSalt">Initial value of the PasswordSalt property.</param>
 /// <param name="email">Initial value of the Email property.</param>
 public static User CreateUser(global::System.Int32 id, global::System.String userName, global::System.String password, global::System.String passwordSalt, global::System.String email)
 {
     User user = new User();
     user.ID = id;
     user.UserName = userName;
     user.Password = password;
     user.PasswordSalt = passwordSalt;
     user.Email = email;
     return user;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Users EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToUsers(User user)
 {
     base.AddObject("Users", user);
 }
 /// <summary>
 /// Create a new User object.
 /// </summary>
 /// <param name="applicationId">Initial value of the ApplicationId property.</param>
 /// <param name="userId">Initial value of the UserId property.</param>
 /// <param name="userName">Initial value of the UserName property.</param>
 /// <param name="isAnonymous">Initial value of the IsAnonymous property.</param>
 /// <param name="lastActivityDate">Initial value of the LastActivityDate property.</param>
 public static User CreateUser(global::System.Guid applicationId, global::System.Guid userId, global::System.String userName, global::System.Boolean isAnonymous, global::System.DateTime lastActivityDate)
 {
     User user = new User();
     user.ApplicationId = applicationId;
     user.UserId = userId;
     user.UserName = userName;
     user.IsAnonymous = isAnonymous;
     user.LastActivityDate = lastActivityDate;
     return user;
 }
Beispiel #15
0
 /// <summary>
 /// Gets all Contacts by user.
 /// </summary>
 /// <param name="user">The user</param>
 /// <returns>Collection of Users</returns>
 public static IEnumerable<Contact> GetAllByUser(User user)
 {
     var e = db.Contacts.Where(x => x.User == user);
     return e;
 }