public static int SaveVolunteer(Models.EventVolunteer eventVolunteer)
        {
            using (var db = new Context.SqlContext())
            {
                db.Entry(eventVolunteer).State = eventVolunteer.EventVolunteerId.Equals(0) ? EntityState.Added : EntityState.Modified;
                if (db.Entry(eventVolunteer).State == EntityState.Added)
                {
                    //Load School event
                    if (eventVolunteer.SchoolEvent == null)
                    {
                        db.Entry(eventVolunteer).Reference(p => p.SchoolEvent).Load();
                    }
                    //Prevent new volunteer logic:
                    if (eventVolunteer.SchoolEvent.End <= DateTime.Now)
                    {
                        return(-1);                                               //can't register for event that has already happened
                    }
                    if (!eventVolunteer.SchoolEvent.IsVolunteerOpportunity)
                    {
                        return(-1);                                                   //can't register for event that isn't a volunteer opportunity
                    }
                    if (eventVolunteer.SchoolEvent.MaxVolunteers > 0 && eventVolunteer.SchoolEvent.RegisteredVolunteers >= eventVolunteer.SchoolEvent.MaxVolunteers)
                    {
                        return(-1);                                                                                                                                            //can't register for event that has reached the max volunteers allowed
                    }
                    eventVolunteer.RegisteredDate = DateTime.Now;
                    eventVolunteer.SchoolEvent.RegisteredVolunteers++;
                    var ret = db.SaveChanges();
                    //Send email notification to primary contact and new volunteer
                    if ((!string.IsNullOrEmpty(eventVolunteer.Email)) || string.IsNullOrEmpty(eventVolunteer.SchoolEvent.PrimaryContactsEmail))
                    {
                        List <string> to = new List <string>();
                        to.Add(eventVolunteer.Email);
                        List <string> cc = new List <string>();
                        if (!string.IsNullOrEmpty(eventVolunteer.SchoolEvent.PrimaryContactsEmail))
                        {
                            cc.Add(eventVolunteer.SchoolEvent.PrimaryContactsEmail);
                        }
                        string subject = "You volunteered for \"" + eventVolunteer.SchoolEvent.Title + "\" (starts on " + eventVolunteer.SchoolEvent.Start + ")";
                        string body    = "Thank you, " + eventVolunteer.FirstName + ", for volunteering for the \"" + eventVolunteer.SchoolEvent.Title + "\" event. <br>" +
                                         "<b>Start</b>: " + string.Format("{0:f}", eventVolunteer.SchoolEvent.Start) + "<br>" +
                                         "<b>End</b>: " + string.Format("{0:f}", eventVolunteer.SchoolEvent.End) + "<br>" +
                                         (!string.IsNullOrEmpty(eventVolunteer.SchoolEvent.Location) ? ("<b>Location</b>: " + eventVolunteer.SchoolEvent.Location + "<br>") : "") +
                                         (!string.IsNullOrEmpty(eventVolunteer.SchoolEvent.Description) ? ("<b>Description</b>: " + eventVolunteer.SchoolEvent.Description + "<br>") : "");
                        bool emailsent = SendEventEmail(to, cc, null, subject, body);
                    }

                    return(ret);
                }
                else
                {
                    return(db.SaveChanges());
                }
            }
        }
Esempio n. 2
0
 public static int Save(Models.ConfigurationItem configurationItem)
 {
     using (var db = new Context.SqlContext())
     {
         db.Entry(configurationItem).State = configurationItem.ConfigurationItemId.Equals(0) ? EntityState.Added : EntityState.Modified;
         return(db.SaveChanges());
     }
 }
Esempio n. 3
0
        public static Int32 Save(Models.AppManagement appManagement)
        {
            using (var db = new Context.SqlContext())
            {
                db.Entry(appManagement).State = appManagement.AppManagementId.Equals(0) ? EntityState.Added : EntityState.Modified;

                return(db.SaveChanges());
            }
        }
        public static object Delete(Models.Document document)
        {
            using (var db = new Context.SqlContext())
            {
                db.Entry(document).State = document.DocumentId.Equals(0) ? EntityState.Unchanged : EntityState.Deleted;
                var ret = db.SaveChanges();

                return(ret);
            }
        }
Esempio n. 5
0
        public static object Delete(Models.Audience audience)
        {
            using (var db = new Context.SqlContext())
            {
                db.Entry(audience).State = audience.AudienceId.Equals(0) ? EntityState.Unchanged : EntityState.Deleted;
                var ret = db.SaveChanges();

                return(ret);
            }
        }
Esempio n. 6
0
        public static int Save(Models.Audience audience)
        {
            using (var db = new Context.SqlContext())
            {
                db.Entry(audience).State = audience.AudienceId.Equals(0) ? EntityState.Added : EntityState.Modified;
                var ret = db.SaveChanges();

                return(ret);
            }
        }
Esempio n. 7
0
        public static int Delete(Models.DocumentLibrary library)
        {
            using (var db = new Context.SqlContext())
            {
                db.Entry(library).State = library.DocumentLibraryId.Equals(0) ? EntityState.Unchanged : EntityState.Deleted;
                var ret = db.SaveChanges();

                return(ret);
            }
        }
Esempio n. 8
0
        public static long Save(Models.DocumentLibrary library)
        {
            using (var db = new Context.SqlContext())
            {
                db.Entry(library).State = library.DocumentLibraryId.Equals(0) ? EntityState.Added : EntityState.Modified;
                var ret = db.SaveChanges();

                return(library.DocumentLibraryId);
            }
        }
        public static int RemoveStudent(Student student)
        {
            int ret = -1;

            using (var db = new Context.SqlContext())
            {
                db.Entry(student).State = student.StudentId.Equals(0) ? EntityState.Unchanged : EntityState.Deleted;
                ret = db.SaveChanges();
            }
            return(ret);
        }
        public static int Save(Models.SchoolEvent schoolEvent, bool notifyVolunteers, string customMessage)
        {
            try
            {
                using (var db = new Context.SqlContext())
                {
                    db.Entry(schoolEvent).State = schoolEvent.SchoolEventId.Equals(0) ? EntityState.Added : EntityState.Modified;
                    var ret = db.SaveChanges();

                    if ((schoolEvent.IsVolunteerOpportunity) && (notifyVolunteers))
                    {
                        List <string> volunteerEmails = new List <string>();
                        if (schoolEvent.Volunteers == null)
                        {
                            db.Entry(schoolEvent).Collection(v => v.Volunteers).Load();
                        }
                        if (schoolEvent.Volunteers.Count > 0)
                        {
                            foreach (EventVolunteer ev in schoolEvent.Volunteers)
                            {
                                if (!string.IsNullOrEmpty(ev.Email))
                                {
                                    volunteerEmails.Add(ev.Email);
                                }
                            }
                        }
                        if ((volunteerEmails.Count > 0) || !string.IsNullOrEmpty(schoolEvent.PrimaryContactsEmail))
                        {
                            List <string> bcc = volunteerEmails;
                            List <string> to  = new List <string>();
                            if (!string.IsNullOrEmpty(schoolEvent.PrimaryContactsEmail))
                            {
                                to.Add(schoolEvent.PrimaryContactsEmail);
                            }
                            string subject = "Updated: \"" + schoolEvent.Title + "\" (starts on " + string.Format("{0:g}", schoolEvent.Start) + ")";
                            string body    = "Details regarding the \"" + schoolEvent.Title + "\" event have been updated. <br>" +
                                             (string.IsNullOrEmpty(customMessage) ? "" : customMessage) + "<br>" +
                                             "<b>Start</b>: " + string.Format("{0:f}", schoolEvent.Start) + "<br>" +
                                             "<b>End</b>: " + string.Format("{0:f}", schoolEvent.End) + "<br>" +
                                             (!string.IsNullOrEmpty(schoolEvent.Location) ? ("<b>Location</b>: " + schoolEvent.Location + "<br>") : "") +
                                             (!string.IsNullOrEmpty(schoolEvent.Description) ? ("<b>Description</b>: " + schoolEvent.Description + "<br>") : "");
                            bool emailsent = SendEventEmail(to, null, bcc, subject, body);
                        }
                    }

                    return(ret);
                }
            }
            catch (Exception ex)
            {
                return(-1);
            }
        }
        public static object Delete(Models.SchoolEvent schoolEvent, bool notifyVolunteers, string customMessage)
        {
            using (var db = new Context.SqlContext())
            {
                List <string> volunteerEmails = new List <string>();
                if (schoolEvent.Volunteers == null)
                {
                    db.Entry(schoolEvent).Collection(v => v.Volunteers).Load();
                }
                if (schoolEvent.Volunteers.Count > 0)
                {
                    if (notifyVolunteers)
                    {
                        foreach (EventVolunteer ev in schoolEvent.Volunteers)
                        {
                            if (!string.IsNullOrEmpty(ev.Email))
                            {
                                volunteerEmails.Add(ev.Email);
                            }
                        }
                    }
                    schoolEvent.Volunteers.Clear();
                }
                db.Entry(schoolEvent).State = schoolEvent.SchoolEventId.Equals(0) ? EntityState.Unchanged : EntityState.Deleted;
                var ret = db.SaveChanges();

                //Send email notifying primary contact and all volunteers this event has been canceled
                if (notifyVolunteers)
                {
                    if ((volunteerEmails.Count > 0) || string.IsNullOrEmpty(schoolEvent.PrimaryContactsEmail))
                    {
                        List <string> bcc = volunteerEmails;
                        List <string> to  = new List <string>();
                        if (!string.IsNullOrEmpty(schoolEvent.PrimaryContactsEmail))
                        {
                            to.Add(schoolEvent.PrimaryContactsEmail);
                        }
                        string subject = "Canceled: \"" + schoolEvent.Title + "\" (starts on " + string.Format("{0:g}", schoolEvent.Start) + ")";
                        string body    = "The \"" + schoolEvent.Title + "\" event has been canceled. <br>" +
                                         (string.IsNullOrEmpty(customMessage) ? "" : customMessage) + "<br>" +
                                         "<b>Start</b>: " + string.Format("{0:f}", schoolEvent.Start) + "<br>" +
                                         "<b>End</b>: " + string.Format("{0:f}", schoolEvent.End) + "<br>" +
                                         (!string.IsNullOrEmpty(schoolEvent.Location) ? ("<b>Location</b>: " + schoolEvent.Location + "<br>") : "") +
                                         (!string.IsNullOrEmpty(schoolEvent.Description) ? ("<b>Description</b>: " + schoolEvent.Description + "<br>") : "");
                        bool emailsent = SendEventEmail(to, null, bcc, subject, body);
                    }
                }

                return(ret);
            }
        }
 public static int SaveStudent(Models.Student student)
 {
     //Todo: validate student against web service here!
     try
     {
         using (var db = new Context.SqlContext())
         {
             db.Entry(student).State = student.StudentId.Equals(0) ? EntityState.Added : EntityState.Modified;
             if (db.Entry(student).State == EntityState.Added)
             {
                 var ret  = db.SaveChanges();
                 var auds = Repository.Audience.CreateMissingAudiencesFromNewStudent(student);
                 return(ret);
             }
             else
             {
                 return(db.SaveChanges());
             }
         }
     }catch (Exception ex)
     {
         return(-1);
     }
 }
        public static long Save(Models.Document document)
        {
            try
            {
                using (var db = new Context.SqlContext())
                {
                    db.Entry(document).State = document.DocumentId.Equals(0) ? EntityState.Added : EntityState.Modified;
                    var ret = db.SaveChanges();

                    return(document.DocumentId);
                }
            }catch (Exception ex)
            {
                return(-1);
            }
        }
        public static int UnVolunteer(Models.EventVolunteer eventVolunteer)
        {
            using (var db = new Context.SqlContext())
            {
                try
                {
                    db.Configuration.LazyLoadingEnabled = false;
                    if (eventVolunteer.EventVolunteerId.Equals(0))
                    {
                        return(-1);                                           //can't delete a record that hasn't been created in the db yet
                    }
                    if (eventVolunteer.SchoolEvent == null)
                    {
                        db.Entry(eventVolunteer).Reference("SchoolEvent").Load();
                    }
                    eventVolunteer.SchoolEvent.RegisteredVolunteers = eventVolunteer.SchoolEvent.RegisteredVolunteers <= 0 ? 0 : eventVolunteer.SchoolEvent.RegisteredVolunteers - 1;
                    db.Entry(eventVolunteer.SchoolEvent).State      = EntityState.Modified;
                    db.Entry(eventVolunteer).State = EntityState.Deleted;
                    var ret = db.SaveChanges();
                    //Send email notification to primary contact the volunteer
                    if ((!string.IsNullOrEmpty(eventVolunteer.Email)) || string.IsNullOrEmpty(eventVolunteer.SchoolEvent.PrimaryContactsEmail))
                    {
                        List <string> to = new List <string>();
                        to.Add(eventVolunteer.Email);
                        List <string> cc = new List <string>();
                        if ((eventVolunteer.SchoolEvent != null) && (!string.IsNullOrEmpty(eventVolunteer.SchoolEvent.PrimaryContactsEmail)))
                        {
                            cc.Add(eventVolunteer.SchoolEvent.PrimaryContactsEmail);
                        }
                        string subject = "Canceled: \"" + eventVolunteer.SchoolEvent.Title + "\", on " + eventVolunteer.SchoolEvent.Start;
                        string body    = "Thank you, " + eventVolunteer.FirstName + ", for notifying us that you need to cancel for the \"" + eventVolunteer.SchoolEvent.Title +
                                         "\" event that starts " + string.Format("{0:f}", eventVolunteer.SchoolEvent.Start) + ".";
                        bool emailsent = SendEventEmail(to, cc, null, subject, body);
                    }

                    return(ret);
                }
                catch (Exception ex)
                {
                    var e = ex.Message;
                    return(-1);
                }
            }
        }