public ActionResult DeleteConfirmed(int id)
        {
            VolunteerEvent volunteerEvent = db.VolunteerEvent.Find(id);

            db.VolunteerEvent.Remove(volunteerEvent);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit(VolunteerEvent volunteerEvent)
 {
     if (ModelState.IsValid)
     {
         db.Entry(volunteerEvent).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("SendMail", "Home", volunteerEvent));
     }
     return(View(volunteerEvent));
 }
        // GET: VolunteerEvents/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            VolunteerEvent volunteerEvent = db.VolunteerEvent.Find(id);
            var            host           = (from a in db.Users
                                             join e in db.VolunteerEvent on a.Id equals e.HostID
                                             join v in db.User on a.UserID equals v.ID
                                             where e.ID == id && e.HostID == a.Id && a.UserID == v.ID
                                             select new
            {
                FirstName = v.FirstName,
                LastName = v.LastName,
                HostID = e.HostID,
                EndDate = e.EndDate
            });

            foreach (var x in host)
            {
                ViewBag.First   = x.FirstName;
                ViewBag.Last    = x.LastName;
                ViewBag.Host    = x.HostID;
                ViewBag.EndDate = x.EndDate;
            }

            ViewBag.LoggedUser = User.Identity.GetUserId();

            var loggedUser = User.Identity.GetUserName();
            var users      = db.User.Single(v => v.Email == loggedUser);

            var userEvents =
                from u in db.User_Event
                join e in db.VolunteerEvent on u.VolunteerEventID equals e.ID
                join v in db.User on u.UserID equals v.ID
                where u.UserID == users.ID && u.VolunteerEventID == id
                select v;

            if (!userEvents.Any())
            {
                ViewBag.Volunteer = "false";
            }

            if (volunteerEvent == null)
            {
                return(HttpNotFound());
            }
            return(View(volunteerEvent));
        }
Beispiel #4
0
        /// <summary>
        /// NAME: Zoey McDonald
        /// DATE: 2/7/2020
        /// CHECKED BY: Ethan Holmes
        ///
        /// This is a method for the volunteer event manager to update a volunteer event.
        ///
        /// </summary>
        /// <remarks>
        /// UPDATED BY: N/A
        /// UPDATED DATE: N/A
        /// WHAT WAS CHANGED: N/A
        /// </remarks>
        public int UpdateVolunteerEvent(VolunteerEvent oldVolunteerEvent, VolunteerEvent newVolunteerEvent)
        {
            int rows = 0;

            try
            {
                rows = _accessor.UpdateVolunteerEvent(oldVolunteerEvent, newVolunteerEvent);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(rows);
        }
        // GET: VolunteerEvents/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            VolunteerEvent volunteerEvent = db.VolunteerEvent.Find(id);

            if (volunteerEvent == null)
            {
                return(HttpNotFound());
            }
            return(View(volunteerEvent));
        }
        public void SendLeaveEventConfirmationEmail(User user, VolunteerEvent volunteerEventObject)
        {
            string email = user.Email;
            //var user1  = _service.GetUserByUsername(email);
            string subject    = "We are sorry to see you leaving this event!";
            string eventTitle = volunteerEventObject.EventName;
            string eventDate  = volunteerEventObject.EventStartDateTime.ToShortDateString();
            string eventTime  = volunteerEventObject.EventStartDateTime.ToShortTimeString();
            // string eventTime = volunteerEventObject.EventStartDateTime.TimeOfDay.ToString();
            string body = "<h2> Hey " + user.FirstName + "! </h3>" +
                          "<h4>" + "We can confirm that your place at  " + eventTitle + " event on " + eventDate + " at " + eventTime + " has been removed" + "</h4>" +
                          "<h4> We can't wait to see you again!";

            _mailerService.SendEmailAsync(email, subject, body);
        }
        public void SendJoinedEventConfirmationEmail(User user, VolunteerEvent volunteerEventObject)
        {
            string email = user.Email;
            //var user1  = _service.GetUserByUsername(email);
            string subject    = "Thank you for joining us on this event!";
            string eventTitle = volunteerEventObject.EventName;
            string eventDate  = volunteerEventObject.EventStartDateTime.ToShortDateString();
            string eventTime  = volunteerEventObject.EventStartDateTime.ToShortTimeString();
            // string eventTime = volunteerEventObject.EventStartDateTime.TimeOfDay.ToString();
            string body = "<h2> Hey " + user.FirstName + "! </h3>" +
                          "<h4>" + "Your place is confirmed for the " + eventTitle + " event " + "</h4>" +
                          "<h4> We can't wait to see you on " + eventDate + " at " + eventTime + "</h4>";

            _mailerService.SendEmailAsync(email, subject, body);
        }
 public void LeaveEvent(VolunteerEvent volunteerEventObject)
 {
     try
     {
         con.Open();
         var comm = con.CreateCommand();
         comm.CommandText = "DELETE FROM volunteerevent WHERE eventNumber = @eventNumber AND volunteerId = @volunteerId";
         comm.Parameters.AddWithValue("?eventNumber", volunteerEventObject.Id);
         comm.Parameters.AddWithValue("?volunteerId", volunteerEventObject.VolunteerId);
         comm.ExecuteNonQuery();
     }
     finally
     {
         con.Close();
     }
 }
Beispiel #9
0
        /// <summary>
        /// Creator: Zoey McDonald
        /// Created: 2/7/2020
        /// Approver: Ethan Holmes
        ///
        /// This is an fake accessor method for removing a volunteer event.
        ///
        /// </summary>
        /// <remarks>
        /// Updater:
        /// Updated:
        /// Update:
        /// </remarks>
        public int RemoveVolunteerEvent(int volunteerEventID)
        {
            int rows = 0;

            VolunteerEvent eventToRemove = new VolunteerEvent();

            foreach (VolunteerEvent volunteerEvent in _volunteerEvents)
            {
                if (volunteerEventID == volunteerEvent.VolunteerEventID)
                {
                    eventToRemove = volunteerEvent;
                    rows++;
                }
            }
            _volunteerEvents.Remove(eventToRemove);
            return(rows);
        }
        public IActionResult AddVolunterEvent([FromBody] VolunteerEvent volunteerEventObject)
        {
            User checkUser = null;

            if (volunteerEventObject != null)
            {
                checkUser = _userService.GetUserById(volunteerEventObject.VolunteerId.GetValueOrDefault());
                if (checkUser != null)
                {
                    _service.AddVolunteerEvent(volunteerEventObject);
                    SendJoinedEventConfirmationEmail(checkUser, volunteerEventObject);
                    return(StatusCode(200));
                }
                return(StatusCode(204));
            }
            return(Ok());
        }
Beispiel #11
0
        /// <summary>
        /// Creator: Zoey McDonald
        /// Created: 2/7/2020
        /// Approver: Ethan Holmes
        ///
        /// This is an fake accessor method for updating a volunteer event.
        ///
        /// </summary>
        /// <remarks>
        /// Updater:
        /// Updated:
        /// Update:
        /// </remarks>
        public int UpdateVolunteerEvent(VolunteerEvent oldVolunteerEvent, VolunteerEvent newVolunteerEvent)
        {
            int rows  = 0;
            int index = 0;

            foreach (VolunteerEvent tempEvent in _volunteerEvents)
            {
                if (tempEvent.VolunteerEventID == oldVolunteerEvent.VolunteerEventID)
                {
                    rows = 1;
                    break;
                }
                index++;
            }

            if (rows == 1)
            {
                _volunteerEvents[index] = newVolunteerEvent;
            }

            return(rows);
        }
        /// <summary>
        /// NAME: Zoey McDonald
        /// DATE: 2/7/2020
        /// CHECKED BY: Ethan Holmes
        ///
        /// This is an accessor method for updating a volunteer event.
        ///
        /// </summary>
        /// <remarks>
        /// UPDATED BY: N/A
        /// UPDATED DATE: N/A
        /// WHAT WAS CHANGED: N/A
        /// </remarks>
        public int UpdateVolunteerEvent(VolunteerEvent oldVolunteerEvent, VolunteerEvent newVolunteerEvent)
        {
            int rows = 0;
            var conn = DBConnection.GetConnection();
            var cmd  = new SqlCommand("sp_update_volunteer_event");

            // Setup cmd object
            cmd.Connection  = conn;
            cmd.CommandType = CommandType.StoredProcedure;

            // Add the parameters
            cmd.Parameters.Add("@VolunteerEventID", SqlDbType.Int);
            cmd.Parameters.Add("@EventName", SqlDbType.NVarChar, 400);
            cmd.Parameters.Add("@EventDescription", SqlDbType.NVarChar, 400);
            cmd.Parameters.Add("@Active", SqlDbType.Bit);

            // Set parameter values
            cmd.Parameters["@VolunteerEventID"].Value = oldVolunteerEvent.VolunteerEventID;
            cmd.Parameters["@EventName"].Value        = newVolunteerEvent.EventName;
            cmd.Parameters["@EventDescription"].Value = newVolunteerEvent.EventDescription;
            cmd.Parameters["@Active"].Value           = newVolunteerEvent.Active;

            // Try to execute the query
            try
            {
                conn.Open();
                rows = Convert.ToInt32(cmd.ExecuteScalar());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
            return(rows);
        }
        public ActionResult Create(VolunteerEvent volunteerEvent)
        {
            var loggedUser = User.Identity.GetUserName();
            var users      = db.User.Single(v => v.Email == loggedUser);

            volunteerEvent.HostID = User.Identity.GetUserId();

            User_Event user_event = new User_Event
            {
                UserID           = users.ID,
                VolunteerEventID = volunteerEvent.ID
            };

            if (ModelState.IsValid)
            {
                db.User_Event.Add(user_event);
                db.VolunteerEvent.Add(volunteerEvent);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(volunteerEvent));
        }
        /// <summary>
        /// NAME: Zoey McDonald
        /// DATE: 2/7/2020
        /// CHECKED BY: Ethan Holmes
        ///
        /// This is an accessor method for selecting all volunteer events.
        ///
        /// </summary>
        /// <remarks>
        /// UPDATED BY: N/A
        /// UPDATED DATE: N/A
        /// WHAT WAS CHANGED: N/A
        /// </remarks>
        public List <VolunteerEvent> SelectAllEvents()
        {
            // Declare the variables
            List <VolunteerEvent> volunteerEvents = new List <VolunteerEvent>();
            var conn = DBConnection.GetConnection();
            var cmd  = new SqlCommand("sp_select_all_volunteer_events");

            // Setup the cmd object
            cmd.Connection  = conn;
            cmd.CommandType = CommandType.StoredProcedure;

            // Try to execute the query
            try
            {
                conn.Open();
                var reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    VolunteerEvent volunteerEvent = new VolunteerEvent();
                    volunteerEvent.VolunteerEventID = Convert.ToInt32(reader.GetValue(0));
                    volunteerEvent.EventName        = Convert.ToString(reader.GetValue(1));
                    volunteerEvent.EventDescription = Convert.ToString(reader.GetValue(2));
                    volunteerEvents.Add(volunteerEvent);
                }
                reader.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
            return(volunteerEvents);
        }
 public void AddVolunteerEvent(VolunteerEvent volunteerEventObject)
 {
     Console.WriteLine(volunteerEventObject.VolunteerId);
     try
     {
         con.Open();
         string status = "In Progress";
         int    count  = 0;
         do
         {
             string sql =
                 @"update event 
                 set eventStatus = @eventStatus
                         where eventNumber = @id
                 ";
             MySqlCommand comm1 = new MySqlCommand(sql, con);
             comm1.Parameters.AddWithValue("?eventStatus", status);
             comm1.Parameters.AddWithValue("?id", volunteerEventObject.Id);
             comm1.CommandType = CommandType.Text;
             comm1.ExecuteNonQuery();
             count++;
         } while (count < 1);
         var comm = con.CreateCommand();
         comm.CommandText = @"INSERT INTO volunteerevent (eventNumber, volunteerId, volunteerEventAttended, volunteerEventNote) 
         VALUES(@eventNumber, @volunteerId, @volunteerEventAttended, @volunteerEventNote) ";
         comm.Parameters.AddWithValue("?eventNumber", volunteerEventObject.Id);
         comm.Parameters.AddWithValue("?volunteerId", volunteerEventObject.VolunteerId);
         comm.Parameters.AddWithValue("?volunteerEventAttended", volunteerEventObject.VolunteerEventAttended);
         comm.Parameters.AddWithValue("?volunteerEventNote", volunteerEventObject.VolunteerEventNote);
         comm.ExecuteNonQuery();
     }
     finally
     {
         con.Close();
     }
 }