Esempio n. 1
0
        public static object GetNoteGridList(int personId)
        {
            var context = new MusicManEntities();

            return(context.Notes.Where(x => x.PersonID == personId).OrderBy(x => x.Date)
                   .Select(x => new { x.NoteID, x.Date, x.Note1, x.IsSent }).ToList());
        }
Esempio n. 2
0
        /// <summary>Saves, or creates if new this instance of person.</summary>
        private void Save()
        {
            using (var db = new MusicManEntities())
            {
                var person = PersonKey > 0 ? db.People.FirstOrDefault(x => x.PersonID == PersonKey) : new Person();

                if (person == null)
                {
                    return;
                }
                person.FirstName  = txtFirstName.Text;
                person.LastName   = txtLastName.Text;
                person.Email      = txtEmail.Text;
                person.Phone      = txtPhone.Text;
                person.InvoiceDay = (int?)numInvoiceDay.Value;
                person.IsActive   = chkActive.Checked;
                person.IsVenmo    = chkVenmo.Checked;
                person.IsPaypal   = chkPaypal.Checked;
                person.IsParent   = IsParent;
                person.Rate       = (int?)numRate.Value;

                //Create a new person if a key was not passed in when the form was created.
                if (PersonKey == 0)
                {
                    db.People.Add(person);
                }

                db.SaveChanges();
                PersonKey = person.PersonID;
            }

            using (var db = new MusicManEntities())
            {
                var person = db.People.FirstOrDefault(x => x.PersonID == PersonKey);

                if (!IsParent)
                {
                    if (cboParent.SelectedItem is Person selectedParent && ParentKey != selectedParent.PersonID)
                    {
                        if (person.Relationships.FirstOrDefault() != null)
                        {
                            person.Relationships.FirstOrDefault().ParentID = selectedParent.PersonID;
                        }
                        else
                        {
                            var relationship = new Relationship {
                                ChildID = PersonKey, ParentID = selectedParent.PersonID
                            };
                            db.Relationships.Add(relationship);
                        }
                    }

                    Enum.TryParse <DayOfWeek>(cboDayOfWeek.SelectedValue.ToString(), out var dayOfWeek);

                    Schedule.UpdateScheduleFromStudentId(person.PersonID, dayOfWeek, dtTime.Value.TimeOfDay);
                }

                db.SaveChanges();
            }
        }
Esempio n. 3
0
        /// <summary>Updates the schedule from student identifier.  Creates a
        /// new schedule if one isn't found for the current student</summary>
        /// <param name="studentId">The student identifier.</param>
        /// <param name="dayOfWeek">The day of week.</param>
        /// <param name="time">The time.</param>
        public static void UpdateScheduleFromStudentId(int studentId, DayOfWeek dayOfWeek, TimeSpan time)
        {
            using (var db = new MusicManEntities())
            {
                var newSchedule = false;
                var schedule    = db.Schedules.FirstOrDefault(x => x.PersonID == studentId);
                if (schedule == null)
                {
                    newSchedule = true;
                    schedule    = new Schedule {
                        PersonID = studentId
                    };
                }

                var intDayOfWeek = (int)dayOfWeek;

                schedule.DayOfTheWeek = intDayOfWeek;

                var timeWoSeconds = new TimeSpan(time.Hours, time.Minutes, 0);

                schedule.TimeOfDay = timeWoSeconds;

                if (newSchedule)
                {
                    db.Schedules.Add(schedule);
                }

                db.SaveChanges();
            }
        }
Esempio n. 4
0
 public static User GetDefaultUser()
 {
     using (var db = new MusicManEntities())
     {
         return(db.Users.FirstOrDefault());
     }
 }
Esempio n. 5
0
        /// <summary>Gets the student grid list.</summary>
        /// <returns></returns>
        public static object GetStudentGridList()
        {
            var context = new MusicManEntities();

            return(context.People.Where(x => x.IsParent == false).OrderBy(x => x.LastName)
                   .Select(x => new { x.PersonID, x.LastName, x.FirstName, x.Phone, x.Email, x.Rate, x.IsActive }).ToList());
        }
Esempio n. 6
0
 public static User GetUserFromEmail(string email)
 {
     using (var db = new MusicManEntities())
     {
         return(db.Users.FirstOrDefault(x => x.Email == email));
     }
 }
Esempio n. 7
0
        /// <summary>Gets the parent grid list.</summary>
        /// <returns></returns>
        public static object GetParentGridList()
        {
            var context = new MusicManEntities();

            return(context.People.Where(x => x.IsParent == true).OrderBy(x => x.LastName)
                   .Select(x => new { x.PersonID, x.LastName, x.FirstName, x.Phone, x.Email, x.IsVenmo, x.IsPaypal }).ToList());
        }
Esempio n. 8
0
 public void UpdateUser(string password)
 {
     using (var db = new MusicManEntities())
     {
         PasswordHash = SecurePasswordHasher.Hash(password);
         db.SaveChanges();
     }
 }
Esempio n. 9
0
 //Static methods
 /// <summary>Gets all parents.</summary>
 /// <returns></returns>
 public static List <Person> GetActiveStudents()
 {
     using (var db = new MusicManEntities())
     {
         var parents = db.People.Where(x => x.IsParent == false);
         return(parents.ToList());
     }
 }
Esempio n. 10
0
 /// <summary>Gets the person from primary key.</summary>
 /// <param name="personId">The person identifier.</param>
 /// <returns></returns>
 public static Person GetPersonFromId(int personId)
 {
     using (var db = new MusicManEntities())
     {
         var person = db.People.FirstOrDefault(x => x.PersonID == personId);
         return(person);
     }
 }
Esempio n. 11
0
 /// <summary>
 ///   <para>
 ///  Gets the schedule from student foreign key.
 /// </para>
 /// </summary>
 /// <param name="studentId">The student identifier.</param>
 /// <returns></returns>
 public static Schedule GetScheduleFromStudentId(int studentId)
 {
     using (var db = new MusicManEntities())
     {
         var schedule = db.Schedules.FirstOrDefault(x => x.PersonID == studentId);
         return(schedule);
     }
 }
Esempio n. 12
0
 public static List <Note> GetNotesForUser(int personId)
 {
     using (var db = new MusicManEntities())
     {
         var notes = db.Notes.Where(x => x.PersonID == personId);
         return(notes.ToList());
     }
 }
Esempio n. 13
0
 public static Note GetNoteFromId(int noteId)
 {
     using (var db = new MusicManEntities())
     {
         var note = db.Notes.FirstOrDefault(x => x.NoteID == noteId);
         return(note);
     }
 }
Esempio n. 14
0
 public static void UpdateNote(int noteKey, string noteText)
 {
     using (var db = new MusicManEntities())
     {
         var note = db.Notes.FirstOrDefault(x => x.NoteID == noteKey);
         note.Note1 = noteText;
         db.SaveChanges();
     }
 }
Esempio n. 15
0
 public static void DeleteNote(int noteKey)
 {
     using (var db = new MusicManEntities())
     {
         var note = db.Notes.FirstOrDefault(x => x.NoteID == noteKey);
         db.Notes.Attach(note);
         db.Notes.Remove(note);
         db.SaveChanges();
     }
 }
Esempio n. 16
0
 public static void CreateNote(int personKey, string noteText)
 {
     using (var db = new MusicManEntities())
     {
         var note = new Note {
             PersonID = personKey, Note1 = noteText, Date = DateTime.Now, IsSent = false
         };
         db.Notes.Add(note);
         db.SaveChanges();
     }
 }
Esempio n. 17
0
 /// <summary>Marks the invoice as paid.</summary>
 /// <param name="billingId">The billing identifier.</param>
 public static void MarkInvoiceAsPaid(short billingId)
 {
     using (var db = new MusicManEntities())
     {
         var billingDetail = db.BillingDetails.FirstOrDefault(x => x.BillingDetailID == billingId);
         if (billingDetail != null)
         {
             billingDetail.IsPaid = true;
             db.SaveChanges();
         }
     }
 }
Esempio n. 18
0
        /// <summary>Gets the billing entry list.</summary>
        /// <param name="parentId">The parent identifier.</param>
        /// <param name="start">The start date.</param>
        /// <param name="end">The end date.</param>
        /// <returns>A list of billing entries related to a given parent, within a certain date range</returns>
        public static object GetBillingEntryList(int parentId, DateTime start, DateTime end)
        {
            using (var db = new MusicManEntities())
            {
                var billingEntries = from p in db.People
                                     join b in db.BillingDetails on p.PersonID equals b.PersonID
                                     orderby b.BillMonth
                                     where p.PersonID == parentId && b.BillMonth >= start && b.BillMonth <= end
                                     select new { b.BillingDetailID, b.BillMonth, b.Amount, b.IsInvoiced, b.IsPaid };

                return(billingEntries.ToList());
            }
        }
Esempio n. 19
0
 /// <summary>Sets the initial form control values.</summary>
 private void SetInitialValues()
 {
     using (var db = new MusicManEntities())
     {
         var billingDetail = db.BillingDetails.FirstOrDefault(x => x.BillingDetailID == _billingDetailKey);
         if (billingDetail != null)
         {
             if (billingDetail.BilledDate != null)
             {
                 txtInvoiceDate.Text = billingDetail.BilledDate.Value.ToShortDateString();
             }
             txtParentName.Text = billingDetail.Person.FullName;
             txtTotal.Text      = billingDetail.Amount.ToString();
         }
     }
 }
Esempio n. 20
0
        /// <summary>Handles the Click event of the btnSave control. Saves changes to the current billing record.
        /// Only the amount can change </summary>
        private void btnSave_Click(object sender, EventArgs e)
        {
            using (var db = new MusicManEntities())
            {
                var billingDetail = db.BillingDetails.FirstOrDefault(x => x.BillingDetailID == _billingDetailKey);

                if (billingDetail == null)
                {
                    return;
                }
                billingDetail.Amount = Convert.ToDecimal(txtTotal.Text);
                db.SaveChanges();
            }

            Close();
        }
Esempio n. 21
0
        /// <summary>Gets the parent from the current student.</summary>
        /// <returns></returns>
        public Person GetParent()
        {
            using (var db = new MusicManEntities())
            {
                var relationship = db.Relationships
                                   .FirstOrDefault(s => s.ChildID == PersonID);

                if (relationship != null)
                {
                    var parent = db.People.Find(relationship.ParentID);
                    return(parent);
                }

                return(null);
            }
        }
Esempio n. 22
0
        public static void SendInvoices()
        {
            using (var db = new MusicManEntities())
            {
                var unsentInvoices = db.BillingDetails.Where(x => x.IsInvoiced == false);
                foreach (var unsentInvoice in unsentInvoices)
                {
                    if (unsentInvoice.Person.InvoiceDay <= DateTime.Today.Day)
                    {
                        SendInvoice(unsentInvoice, unsentInvoice.Person.Phone);
                    }

                    unsentInvoice.IsInvoiced = true;
                }
                db.SaveChanges();
            }
        }
Esempio n. 23
0
 public static void UpdateUser(string email, string companyName, string payPal, string venmo, string twilioSID, string twilioAuthKey, string twilioPhone)
 {
     using (var db = new MusicManEntities())
     {
         var user = db.Users.FirstOrDefault(x => x.Email == email);
         if (user != null)
         {
             user.CompanyName       = companyName;
             user.PayPalEmail       = payPal;
             user.VenmoUser         = venmo;
             user.TwilioAccountSid  = twilioSID;
             user.TwilioAuthToken   = twilioAuthKey;
             user.TwilioPhoneNumber = twilioPhone;
             db.SaveChanges();
         }
     }
 }
Esempio n. 24
0
        /// <summary>Creates the invoices for the current month.</summary>

        public static void CreateInvoices()
        {
            var date     = DateTime.Now.AddMonths(-1);
            var fromDate = new DateTime(date.Year, date.Month, 1);
            var toDate   = fromDate.AddMonths(1);

            var context = new MusicManEntities();
            var parents = context.People.Where(x => x.IsParent == true && x.IsActive == true)
                          .Select(x => new { x.PersonID }).ToList();

            foreach (var parent in parents)
            {
                var parentId  = parent.PersonID;
                var billCount = context.BillingDetails
                                .Count(x => x.PersonID == parentId &&
                                       x.BillMonth >= fromDate && x.BillMonth < toDate);

                if (billCount == 0)
                {
                    var total = 0;
                    using (var db = new MusicManEntities())
                    {
                        var studentQuery = from r in db.Relationships
                                           join p in db.People on r.ChildID equals p.PersonID
                                           join s in db.Schedules on p.PersonID equals s.PersonID
                                           where r.ParentID == parentId
                                           select new { p.PersonID, p.Rate, s.DayOfTheWeek, };

                        var studentView = studentQuery.ToList();

                        foreach (var student in studentView)
                        {
                            var dayOfWeek  = (DayOfWeek)student.DayOfTheWeek;
                            var numLessons = CountDays(dayOfWeek, fromDate, toDate);

                            total += numLessons * student.Rate.Value;
                        }
                        if (total > 0)
                        {
                            CreateBillingEntry(parentId, total, fromDate);
                        }
                    }
                }
            }
        }
Esempio n. 25
0
        /// <summary>Creates the billing entry.</summary>
        /// <param name="parentId">The parent identifier.</param>
        /// <param name="total">The total.</param>
        private static void CreateBillingEntry(int parentId, int total, DateTime fromDate)
        {
            using (var db = new MusicManEntities())
            {
                var bill = new BillingDetail
                {
                    PersonID   = parentId,
                    BilledDate = DateTime.Today,
                    Amount     = total,
                    IsInvoiced = false,
                    IsPaid     = false,
                    BillMonth  = fromDate
                };

                db.BillingDetails.Add(bill);
                db.SaveChanges();
            }
        }
Esempio n. 26
0
        public static User CreateUser(string email, string password)
        {
            using (var db = new MusicManEntities())
            {
                var user = new User
                {
                    Email        = email,
                    PasswordHash = SecurePasswordHasher.Hash(password)
                };

                //var hash = SecurePasswordHasher.Hash(password);
                db.Users.Add(user);
                db.SaveChanges();
                // Verify
                //var result = SecurePasswordHasher.Verify("mypassword", hash);


                return(db.Users.FirstOrDefault());
            }
        }