/// <summary author="Caitlin Abelson" created="2019/02/03">
 /// The DeleteEmployee method return an active or inactive employee from the EmployeeAccessor
 /// </summary>
 /// <param name="employeeID"></param>
 /// <param name="isActive"></param>
 public void DeleteEmployee(int employeeID, bool isActive)
 {
     // If the employee is active, they must be deactived first.
     if (isActive == true)
     {
         try
         {
             _employeeAccessor.DeactiveEmployee(employeeID);
         }
         catch (Exception ex)
         {
             ExceptionLogManager.getInstance().LogException(ex);
             throw ex;
         }
     }
     // If the employee is already inactive, they will be taken out of the system.
     else
     {
         try
         {
             _employeeAccessor.DeleteEmployeeRole(employeeID);
             _employeeAccessor.DeleteEmployee(employeeID);
         }
         catch (Exception ex)
         {
             ExceptionLogManager.getInstance().LogException(ex);
             throw ex;
         }
     }
 }
        /// <summary author="Austin Delaney" created="2019/04/25">
        /// Replies to a thread by passing the message manager a new message with that thread's ID.
        /// </summary>
        /// <param name="thread">The thread to add the message to.</param>
        /// <param name="reply">The message to add to the thread.</param>
        /// <returns>Whether the operation was a success or not.</returns>
        public bool ReplyToThread(IMessageThread thread, Message reply)
        {
            if (null == thread)
            {
                throw new ArgumentNullException("Thread to add participants to cannot be null.");
            }
            if (null == reply)
            {
                throw new ArgumentNullException("Message to use as reply cannot be null.");
            }

            bool            result         = false;
            IMessageManager messageManager = new RealMessageManager(daoType);

            try
            {
                result = messageManager.CreateNewReply(thread, reply);
            }
            catch (Exception ex)
            {
                ExceptionLogManager.getInstance().LogException(ex);
                throw ex;
            }

            return(result);
        }
        /// <summary author="Austin Delaney" created="2019/04/25">
        /// Changes a user's visibile alias within a thread. Method should check if the alias
        /// is already set to <paramref name="newAlias"/>, and if it is, should return and not
        /// fail.
        /// </summary>
        /// <param name="thread">The thread to alter the alias in.</param>
        /// <param name="newAlias">The new alias the user would like to use for this particular thread.</param>
        /// <param name="participant">The user who is changing their alias.</param>
        /// <returns>Whether the operation was a success or not.</returns>
        public bool UpdateThreadAlias(IMessageThread thread, string newAlias, ISender participant)
        {
            if (null == thread)
            {
                throw new ArgumentNullException("Thread to set the alias for to cannot be null.");
            }
            if (null == participant)
            {
                throw new ArgumentNullException("Participant to set the alias for cannot be null.");
            }
            if (!newAlias.IsValidMessengerAlias())
            {
                throw new ArgumentException("New alias is invalid.");
            }
            if (null == newAlias)
            {
                return(true);
            }

            bool result = false;

            try
            {
                result = dao.UpdateUserThreadAlias(thread.ThreadID, participant.Email, newAlias);
            }
            catch (Exception ex)
            {
                ExceptionLogManager.getInstance().LogException(ex);
                throw ex;
            }

            return(result);
        }
        /// <summary author="Wes Richardson" created="2019/03/07">
        /// Validtes and passes updated appointment data to the appointment accessor
        /// </summary>
        public bool UpdateAppointment(Appointment appointment)
        {
            int  rows    = 0;
            bool results = false;

            try
            {
                validateAppointmentData(appointment);
                if (appointmentValid)
                {
                    rows = _appointmentAccessor.UpdateAppointment(appointment);
                    if (rows > 0)
                    {
                        results = true;
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionLogManager.getInstance().LogException(ex);
                throw ex;
            }

            return(results);
        }
        /// <summary author="Austin Delaney" created="2019/04/25">
        /// Marks a thread as read for a certain participant.
        /// </summary>
        /// <param name="thread">The thread that is being read.</param>
        /// <param name="participant">The person that is reading/opening the thread.</param>
        /// <returns>If the change was successfully made to the data store.</returns>
        public bool MarkThreadAsReadByParticipant(IMessageThread thread, ISender participant)
        {
            if (null == thread)
            {
                throw new ArgumentNullException("A thread must be provided to be read by a participant, cannot be null.");
            }
            if (null == participant)
            {
                throw new ArgumentNullException("A participant must be provided that is reading the thread, cannot be null.");
            }

            bool result = false;

            try
            {
                result = dao.UpdateThreadParticipantNewMessageStatus(thread.ThreadID, participant.Email);
            }
            catch (Exception ex)
            {
                ExceptionLogManager.getInstance().LogException(ex);
                throw ex;
            }

            return(result);
        }
        /// <summary author="Eduardo Colon" created="2019/02/08">
        /// Sends a role to the the DAO to be added to the datastore.
        /// </summary>
        /// <updates>
        /// <update author="Austin Delaney" created="2019/04/27">
        /// Changed output from 'int' to 'bool', added exception logging, moved argument validation, added arguement
        /// null check.
        /// </update>
        /// </updates>
        /// <returns>The success of the operation, based on if the DAO signals 1 role was added to the data store.</returns>
        public bool CreateRole(Role newRole)
        {
            if (null == newRole)
            {
                throw new ArgumentNullException("Role to be created cannot be null");
            }
            if (!isValid(newRole))
            {
                throw new ArgumentException("The data for this role is invalid");
            }

            int result = -1;

            try
            {
                result = _roleAccessor.InsertRole(newRole);
            }
            catch (Exception ex)
            {
                ExceptionLogManager.getInstance().LogException(ex);
                throw ex;
            }

            return(1 == result);
        }
        /// <summary author="Francis Mingomba" created="2019/04/03">
        /// Checks employee privileges and activates vehicles
        /// if employee has privileges to do it
        /// </summary>
        /// <param name="resortVehicle">resort vehicle</param>
        /// <param name="employee">employee performing operation</param>
        public void ActivateVehicle(ResortVehicle resortVehicle, Employee employee = null)
        {
            try
            {
                if (resortVehicle == null)
                {
                    throw new ApplicationException("Vehicle cannot be null");
                }

                if (!employee.HasRoles(out string errorStr, "Admin"))
                {
                    throw new ApplicationException(errorStr);
                }

                var newVehicle = resortVehicle.DeepClone();

                newVehicle.Active = true;

                newVehicle.DeactivationDate = null;

                _resortVehicleAccessor.UpdateVehicle(resortVehicle, newVehicle);
            }
            catch (Exception ex)
            {
                ExceptionLogManager.getInstance().LogException(ex);
                throw ex;
            }
        }
        /// <summary author="James Heim" created="2019/03/07">
        /// Delete the shop via the accessor.
        /// </summary>
        /// <param name="shop"></param>
        /// <returns></returns>
        public bool DeleteShop(Shop shop)
        {
            bool result = false;

            if (RetrieveShopByID(shop.ShopID) == null)
            {
                // Shop Doesn't exist!
                throw new NullReferenceException(shop.NullShopError);
            }
            else if (shop.Active == true)
            {
                throw new InvalidOperationException(shop.DeleteActiveShopError);
            }
            else
            {
                try
                {
                    result = (1 == _shopAccessor.DeleteShop(shop));
                }
                catch (Exception ex)
                {
                    ExceptionLogManager.getInstance().LogException(ex);
                    throw ex;
                }
            }

            return(result);
        }
        public bool UpdateShop(Shop newShop, Shop oldShop)
        {
            bool result = false;

            try
            {
                if (newShop.IsValid())
                {
                    if (_shopAccessor.UpdateShop(newShop, oldShop) > 0)
                    {
                        result = true;
                    }
                }
                else
                {
                    throw new ArgumentException();
                }
            }
            catch (Exception ex)
            {
                ExceptionLogManager.getInstance().LogException(ex);
                throw new ArgumentException();
            }

            return(result);
        }
        /// <summary author="Richard Carroll" created="2019/01/30">
        /// Passes information from the Presentation Layer to the Data Access
        /// Layer and returns the result of the Insertion attempt.
        /// </summary>
        public bool CreateInternalOrder(InternalOrder itemOrder, List <VMInternalOrderLine> lines)
        {
            bool result = false;

            try
            {
                if (!itemOrder.isValid())
                {
                    throw new ArgumentException("Data entered for this order is invalid\n " +
                                                itemOrder.ToString());
                }
                foreach (var line in lines)
                {
                    if (!line.isValid())
                    {
                        throw new ArgumentException("Data entered for this order is invalid\n" +
                                                    line.ToString());
                    }
                }
                result = (_itemOrderAccessor.InsertItemOrder(itemOrder, lines) > 0);
            }
            catch (Exception ex)
            {
                ExceptionLogManager.getInstance().LogException(ex);
                throw ex;
            }

            return(result);
        }
        /// <summary author="Austin Delaney" created="2019/04/25">
        /// Sets the status of a thread to archived in the data store.
        /// </summary>
        /// <param name="threadID">The ID of the thread to be set as archived.</param>
        /// <param name="archived">What the status of the thread should be.</param>
        /// <returns>Whether the operation was a success or not.</returns>
        public bool UpdateThreadArchivedStatus(int threadID, bool archived)
        {
            int result = -1;

            var conn      = DBConnection.GetDbConnection();
            var procedure = @"sp_update_thread_archived_state";
            var cmd       = new SqlCommand(procedure, conn)
            {
                CommandType = CommandType.StoredProcedure
            };

            cmd.Parameters.AddWithValue("@ThreadID", threadID);
            cmd.Parameters.AddWithValue("@Archived", archived);

            try
            {
                conn.Open();

                result = (int)cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                ExceptionLogManager.getInstance().LogException(ex);
                throw ex;
            }
            finally
            {
                conn.Close();
            }

            return(1 == result || 0 == result);
        }
        public bool UpdateInspection(Inspection selectedInspection, Inspection newInspection)
        {
            bool result = false;

            try
            {
                LogicValidationExtensionMethods.ValidateInspectionName(selectedInspection.Name);
                LogicValidationExtensionMethods.ValidateInspectionRating(selectedInspection.Rating);
                LogicValidationExtensionMethods.ValidateAffiliation(selectedInspection.ResortInspectionAffiliation);
                LogicValidationExtensionMethods.ValidateInspectionProblemNotes(selectedInspection.InspectionProblemNotes);
                LogicValidationExtensionMethods.ValidateInspectionFixNotes(selectedInspection.InspectionFixNotes);
                result = (1 == inspectionAccessor.UpdateInspection(selectedInspection, newInspection));
            }
            catch (ArgumentNullException ane)
            {
                ExceptionLogManager.getInstance().LogException(ane);
                throw ane;
            }
            catch (ArgumentException ae)
            {
                ExceptionLogManager.getInstance().LogException(ae);
                throw ae;
            }
            catch (Exception ex)
            {
                ExceptionLogManager.getInstance().LogException(ex);
                throw ex;
            }

            return(result);
        }
Ejemplo n.º 13
0
        /// <summary author="Danielle Russo" created="2019/01/31">
        /// Edits building details
        /// </summary>
        /// <param name="oldBuilding">The original Building obj to be updated</param>
        /// <param name="updatedBuilding">The updated Building obj</param>
        /// <exception cref="SQLException">Insert Fails (example of exception tag)</exception>
        /// <returns>True if Building was successfully updated, False if Building was not updated.</returns>
        public bool UpdateBuilding(Building oldBuilding, Building updatedBuilding)
        {
            bool result = false;

            try
            {
                LogicValidationExtensionMethods.ValdateMatchingIDs(oldBuilding.BuildingID, updatedBuilding.BuildingID);
                LogicValidationExtensionMethods.ValidateBuildingID(updatedBuilding.BuildingID);
                LogicValidationExtensionMethods.ValidateBuildingName(updatedBuilding.Name);
                LogicValidationExtensionMethods.ValidateBuildingAddress(updatedBuilding.Address);
                LogicValidationExtensionMethods.ValidateBuildngDescription(updatedBuilding.Description);
                LogicValidationExtensionMethods.ValidateBuildingStatusID(updatedBuilding.StatusID);

                result = (1 == buildingAccessor.UpdateBuilding(oldBuilding, updatedBuilding));
            }
            catch (ArgumentNullException ane)
            {
                ExceptionLogManager.getInstance().LogException(ane);
                throw ane;
            }
            catch (ArgumentException ae)
            {
                ExceptionLogManager.getInstance().LogException(ae);
                throw ae;
            }
            catch (Exception ex)
            {
                ExceptionLogManager.getInstance().LogException(ex);
                throw ex;
            }

            return(result);
        }
Ejemplo n.º 14
0
        /// <summary author="Danielle Russo" created="2019/01/21">
        /// Adds a new Building obj.
        /// </summary>
        /// <updates>
        /// <update author="Danielle Russo" date="2019/02/28">
        /// Changed 1 to 2 so that it will pass for now
        /// </update>
        /// <param name="newBuilding">The Building obj to be added</param>
        /// <exception cref="SQLException">Insert Fails (example of exception tag)</exception>
        /// <returns>True if Building was successfully added, False if Building was not added.</returns>
        public bool CreateBuilding(Building newBuilding)
        {
            bool result = false;

            try
            {
                LogicValidationExtensionMethods.ValidateBuildingID(newBuilding.BuildingID);
                LogicValidationExtensionMethods.ValidateBuildingName(newBuilding.Name);
                LogicValidationExtensionMethods.ValidateBuildingAddress(newBuilding.Address);
                LogicValidationExtensionMethods.ValidateBuildngDescription(newBuilding.Description);
                LogicValidationExtensionMethods.ValidateBuildingStatusID(newBuilding.StatusID);

                result = (2 == buildingAccessor.InsertBuilding(newBuilding));
            }
            catch (ArgumentNullException ane)
            {
                ExceptionLogManager.getInstance().LogException(ane);
                throw ane;
            }
            catch (ArgumentException ae)
            {
                ExceptionLogManager.getInstance().LogException(ae);
                throw ae;
            }
            catch (Exception ex)
            {
                ExceptionLogManager.getInstance().LogException(ex);
                throw ex;
            }

            return(result);
        }
Ejemplo n.º 15
0
 /// <summary author="Matt LaMarche" created="2019/01/29">
 /// Delete Reservation will determing whether the Reservation needs to be deleted or deactivated and request deactivation or deletion from a Reservation Accessor
 /// </summary>
 /// <param name="ReservationID">The ID of the Reservation which we are deleting or deactivating</param>
 /// <param name="isActive">The active status from the Reservation we are deleting or deactivating</param>
 public void DeleteReservation(int ReservationID, bool isActive)
 {
     if (isActive)
     {
         //Is Active so we just deactivate it
         try
         {
             _reservationAccessor.DeactivateReservation(ReservationID);
         }
         catch (Exception ex)
         {
             ExceptionLogManager.getInstance().LogException(ex);
             throw ex;
         }
     }
     else
     {
         //Is Deactive so we purge it
         try
         {
             _reservationAccessor.PurgeReservation(ReservationID);
         }
         catch (Exception ex)
         {
             ExceptionLogManager.getInstance().LogException(ex);
             throw ex;
         }
     }
 }
        /// <summary author="James Heim" created="2019/03/08">
        /// Deactivate the shop passed in by calling the shop accessor method.
        /// </summary>
        /// <param name="shop"></param>
        /// <returns></returns>
        public bool DeactivateShop(Shop shop)
        {
            bool result = false;

            try
            {
                if (shop == null)
                {
                    throw new NullReferenceException(shop.NullShopError);
                }
                else if (shop.Active == false)
                {
                    throw new InvalidOperationException(shop.DeactivateInactiveShopError);
                }
                else
                {
                    result = (1 == _shopAccessor.DeactivateShop(shop));
                }
            }
            catch (Exception ex)
            {
                ExceptionLogManager.getInstance().LogException(ex);
                throw ex;
            }

            return(result);
        }
Ejemplo n.º 17
0
 /// <summary author="Gunardi Saputra" created="2019/02/20">
 /// The DeleteSponsor method return an active or inactive sponsor
 /// from the SponsorAccessor
 /// </summary>
 /// <param name="sponsorID"></param>
 /// <param name="isActive"></param>
 public void DeleteSponsor(int sponsorID, bool isActive)
 {
     if (isActive)
     {
         //Is Active so we just deactivate it
         try
         {
             _sponsorAccessor.DeactivateSponsor(sponsorID);
         }
         catch (Exception ex)
         {
             ExceptionLogManager.getInstance().LogException(ex);
             throw ex;
         }
     }
     else
     {
         //Is Deactive so we remove it
         try
         {
             _sponsorAccessor.DeleteSponsor(sponsorID);
         }
         catch (Exception ex)
         {
             ExceptionLogManager.getInstance().LogException(ex);
             throw ex;
         }
     }
 }
Ejemplo n.º 18
0
        /// <summary author="Richard Carroll" created="2019/03/08">
        /// Takes two Vehicle arguments and passes them to the
        /// Data Access Layer which attempts to update the Vehicle.
        /// Returns the result.
        /// </summary>
        public bool UpdateGuestVehicle(GuestVehicle oldVehicle, GuestVehicle vehicle)
        {
            bool result = false;

            try
            {
                if (vehicle.isValid())
                {
                    if (oldVehicle.isValid())
                    {
                        result = 1 == _guestVehicleAccessor.UpdateGuestVehicle(oldVehicle, vehicle);
                    }
                    else
                    {
                        throw new ArgumentException("Data for this Vehicle is Invalid: \n"
                                                    + oldVehicle.ToString());
                    }
                }
                else
                {
                    throw new ArgumentException("Data for this Vehicle is Invalid: \n"
                                                + vehicle.ToString());
                }
            }
            catch (Exception ex)
            {
                ExceptionLogManager.getInstance().LogException(ex);
                throw ex;
            }

            return(result);
        }
Ejemplo n.º 19
0
        /// <summary author="Jared Greenfield" created="2019/02/09">
        /// Updates an Item with a new Item.
        /// </summary>
        /// <param name="oldItem">The old Item.</param>
        /// <param name="newItem">The updated Item.</param>
        /// <exception cref="SQLException">Insert Fails (example of exception tag)</exception>
        /// <returns>True if the update was successful, false if not.</returns>
        public bool UpdateItem(Item oldItem, Item newItem)
        {
            bool result = false;

            try
            {
                if (oldItem.IsValid())
                {
                    if (newItem.IsValid())
                    {
                        if (1 == _itemAccessor.UpdateItem(oldItem, newItem))
                        {
                            result = true;
                        }
                    }
                    else
                    {
                        throw new ArgumentException("The new Item is not valid.");
                    }
                }
                else
                {
                    throw new ArgumentException("The old Item is not valid.");
                }
            }
            catch (Exception ex)
            {
                ExceptionLogManager.getInstance().LogException(ex);
                throw ex;
            }
            return(result);
        }
        /// <summary author="Austin Delaney" created="2019/04/12">
        /// Sets the thread list to the list found for local employee based on if the
        /// hidden or archived checks are checked.
        /// </summary>
        private void SetupThreadList()
        {
            List <UserThreadView> threads;

            try
            {
                if (chkShowHidden.IsChecked.Value)
                {
                    threads = _threadManager.GetUserThreadViewList(_employee, chkShowArchived.IsChecked.Value);
                }
                else
                {
                    List <UserThreadView> unfilteredList = _threadManager.GetUserThreadViewList(_employee, chkShowArchived.IsChecked.Value);
                    threads = unfilteredList.Where(t => !t.ThreadHidden).ToList();
                }
            }
            catch (Exception ex)
            {
                ExceptionLogManager.getInstance().LogException(ex);
                MessageBox.Show(ex.Message);
                threads = new List <UserThreadView>();
            }

            dgMessageThreadList.ItemsSource = threads;
        }
        /// <summary author="Francis Mingomba" created="2019/04/03">
        /// Checks employee privileges and deactivates vehicles
        /// if employee has privileges to do it
        /// </summary>
        /// <param name="resortVehicle">resort vehicle</param>
        /// <param name="employee">employee performing operation</param>
        public void DeactivateVehicle(ResortVehicle resortVehicle, Employee employee = null)
        {
            if (!employee.HasRoles(out string errorStr, "Admin"))
            {
                throw new ApplicationException(errorStr);
            }

            // make sure vehicle is not active
            if (!resortVehicle.Active)
            {
                throw new ApplicationException("Vehicle already inactive");
            }

            // make sure vehicle is not in use
            if (resortVehicle.ResortVehicleStatusId == new ResortVehicleStatus().InUse)
            {
                throw new ApplicationException("Vehicle currently in use");
            }

            try
            {
                _resortVehicleAccessor.DeactivateVehicle(resortVehicle.Id);
            }
            catch (Exception ex)
            {
                ExceptionLogManager.getInstance().LogException(ex);
                throw ex;
            }
        }
 /// <summary author="Dalton Cleveland" created="2019/02/21">
 /// Delete MaintenanceWorkOrder will determine whether the MaintenanceWorkOrder needs to be deleted or deactivated and request deactivation or deletion from a MaintenanceWorkOrder Accessor
 /// </summary>
 public void DeleteMaintenanceWorkOrder(int MaintenanceWorkOrderID, bool isActive)
 {
     if (isActive)
     {
         //Is Active so we just deactivate it
         try
         {
             _maintenanceWorkOrderAccessor.DeactivateMaintenanceWorkOrder(MaintenanceWorkOrderID);
         }
         catch (Exception ex)
         {
             ExceptionLogManager.getInstance().LogException(ex);
             throw ex;
         }
     }
     else
     {
         //Is Deactive so we purge it
         try
         {
             _maintenanceWorkOrderAccessor.PurgeMaintenanceWorkOrder(MaintenanceWorkOrderID);
         }
         catch (Exception ex)
         {
             ExceptionLogManager.getInstance().LogException(ex);
             throw ex;
         }
     }
 }
Ejemplo n.º 23
0
 /// <summary author="Caitlin Abelson" created="2019/02/28">
 /// The method for deactivating and deleting a setupList.
 /// </summary>
 /// <param name="setupListID"></param>
 /// <param name="isActive"></param>
 public void DeleteSetupList(int setupListID, bool isActive)
 {
     // If the setupList is completed, the setuplist needs to be deactivated or made incomplete
     // before it can be deleted.
     if (isActive == true)
     {
         try
         {
             _setupListAccessor.DeactiveSetupList(setupListID);
         }
         catch (Exception ex)
         {
             ExceptionLogManager.getInstance().LogException(ex);
             throw ex;
         }
     }
     // If the setuplist is incomplete then the setupList can be deleted.
     else
     {
         try
         {
             _setupListAccessor.DeleteSetupList(setupListID);
         }
         catch (Exception ex)
         {
             ExceptionLogManager.getInstance().LogException(ex);
             throw ex;
         }
     }
 }
Ejemplo n.º 24
0
        /// <summary author="Francis Mingomba" created="2019/04/24">
        /// Retrieves a list of checked out vehicles
        /// </summary>
        /// <returns>A list of checked out vehicles</returns>
        public IEnumerable <ResortVehicleCheckoutDecorator> RetrieveCurrentlyCheckedOutVehicles()
        {
            List <ResortVehicleCheckoutDecorator> resortVehicleCheckoutsDecorator;

            try
            {
                var resortVehicleCheckouts = RetrieveVehicleCheckouts()?.Where(x => x.Returned == false);

                resortVehicleCheckoutsDecorator = new List <ResortVehicleCheckoutDecorator>();

                if (resortVehicleCheckouts == null)
                {
                    return(resortVehicleCheckoutsDecorator);
                }

                resortVehicleCheckoutsDecorator.AddRange(resortVehicleCheckouts.Select(
                                                             item => new ResortVehicleCheckoutDecorator
                {
                    VehicleCheckoutId = item.VehicleCheckoutId,
                    EmployeeId        = item.EmployeeId,
                    DateCheckedOut    = item.DateCheckedOut,
                    DateReturned      = item.DateReturned,
                    DateExpectedBack  = item.DateExpectedBack,
                    Returned          = item.Returned,
                    ResortVehicleId   = item.ResortVehicleId
                }));
            }
            catch (Exception ex)
            {
                ExceptionLogManager.getInstance().LogException(ex);
                throw ex;
            }

            return(resortVehicleCheckoutsDecorator);
        }
        /// <summary author="Austin Delaney" created="2019/04/25">
        /// Removes a set of participants from a thread. Will return true if after the operation,
        /// all participants that were asked to be removed are no longer listed in the thread. This
        /// should succeed even if the listed participants were not in the thread to begin with.
        /// When removing a role/dept, will remove by alias, and if a user was added that has since
        /// changed their alias they will not be removed.
        /// </summary>
        /// <param name="thread">The thread to remove participants from.</param>
        /// <param name="removeParticipants">The set of participants to remove from the thread.</param>
        /// <returns>Whether the operation was a success or not.</returns>
        public bool RemoveThreadParticipants(IMessageThread thread, List <ISender> removeParticipants)
        {
            if (null == thread)
            {
                throw new ArgumentNullException("Thread to add participants to cannot be null.");
            }
            if (null == removeParticipants)
            {
                removeParticipants = new List <ISender>();
            }

            bool result = true;

            foreach (var participant in removeParticipants)
            {
                try
                {
                    if (!dao.RemoveThreadParticipant(thread.ThreadID, participant.Email))
                    {
                        result = false;
                    }
                }
                catch (Exception ex)
                {
                    ExceptionLogManager.getInstance().LogException(new Exception("Error encountered removing user " + participant.Email
                                                                                 + " from thread " + thread.ThreadID, ex));
                    result = false;
                }
            }

            return(result);
        }
        /// <summary author="Austin Delaney" created="2019/04/03">
        /// Creates a new message in the data store and returns the thread ID of the message created.
        /// Should return a -1 to indicate failure.
        /// </summary>
        /// <param name="message">The new message to be sent.</param>
        /// <returns>The thread that the newly created message generated, or a -1
        /// if the operation was a failure.</returns>
        public int CreateNewMessage(Message message)
        {
            if (null == message)
            {
                throw new ArgumentNullException("Message used to create thread cannot be null.");
            }
            if (!message.IsValid())
            {
                throw new ArgumentException("Message is invalid");
            }

            int result;

            try
            {
                result = dao.InsertNewMessage(message);
            }
            catch (Exception ex)
            {
                ExceptionLogManager.getInstance().LogException(ex);
                throw ex;
            }

            if (-1 == result)
            {
                throw new Exception("Error encountered while inserting a new message to the database.");
            }

            return(result);
        }
        /// <summary author="Austin Delaney" created="2019/04/20">
        /// Adds a list of participants to a thread.
        /// </summary>
        /// <param name="thread">The thread to add the participants to.</param>
        /// <param name="newParticipants">The list of participants to add to the thread.</param>
        /// <returns>Whether the operation was a success or not.</returns>
        public bool AddThreadParticipants(IMessageThread thread, List <IMessagable> newParticipants)
        {
            if (null == thread)
            {
                throw new ArgumentNullException("Thread to add participants to cannot be null.");
            }
            if (null == newParticipants)
            {
                return(true);
            }

            int remainingItems = newParticipants.Count;

            foreach (var participant in newParticipants)
            {
                try
                {
                    bool success;

                    if (participant is Role)
                    {
                        success = dao.AddRoleThreadParticipant(thread.ThreadID, participant.Alias);
                    }
                    else if (participant is Department)
                    {
                        success = dao.AddDepartmentThreadParticipant(thread.ThreadID, participant.Alias);
                    }
                    else if (participant is Employee)
                    {
                        success = dao.AddEmployeeThreadParticipant(thread.ThreadID, participant.Alias);
                    }
                    else if (participant is Guest)
                    {
                        success = dao.AddGuestThreadParticipant(thread.ThreadID, participant.Alias);
                    }
                    else if (participant is Member)
                    {
                        success = dao.AddMemberThreadParticipant(thread.ThreadID, participant.Alias);
                    }
                    else
                    {
                        success = false;
                        ExceptionLogManager.getInstance().LogException(
                            new NotSupportedException("Participant alias: " + participant.Alias + ". Unsupported participant type of " + participant.GetType().Name));
                    }
                    if (success)
                    {
                        remainingItems--;
                    }
                }
                catch (Exception ex)
                {
                    Exception exc = new Exception("Error encountered for participant " + participant.Alias + " during participant " +
                                                  "add operation", ex);
                    ExceptionLogManager.getInstance().LogException(exc);
                }
            }

            return(0 == remainingItems);
        }
        /// <summary author="Austin Delaney" created="2019/04/25">
        /// Creates a reply to a thread.
        /// </summary>
        /// <param name="thread">The thread to reply to.</param>
        /// <param name="message">The message to be sent to the thread.</param>
        /// <returns>Whether the operation was a success or not.</returns>
        public bool CreateNewReply(IMessageThread thread, Message message)
        {
            if (null == message)
            {
                throw new ArgumentNullException("Message used to create thread cannot be null.");
            }
            if (!message.IsValid())
            {
                throw new ArgumentException("Message is invalid");
            }

            bool result = false;

            try
            {
                dao.InsertNewReply(thread.ThreadID, message);
            }
            catch (Exception ex)
            {
                ExceptionLogManager.getInstance().LogException(ex);
                throw ex;
            }

            return(result);
        }
        /// <summary author="Austin Delaney" created="2019/04/25">
        /// Causes a thread not to notify a particular user of new messages to that thread.
        /// </summary>
        /// <param name="thread">The thread to change the notify status on.</param>
        /// <param name="status">The new status of the thread.</param>
        /// <param name="participant">The user for whom the status should change.</param>
        /// <returns>Whether the operation was a success or not.</returns>
        public bool UpdateThreadSilentStatus(IMessageThread thread, bool status, ISender participant)
        {
            if (null == thread)
            {
                throw new ArgumentNullException("Thread to set the notification status for to cannot be null.");
            }
            if (null == participant)
            {
                throw new ArgumentNullException("Participant to set the notification status for cannot be null.");
            }

            bool result = false;

            try
            {
                result = dao.UpdateThreadSilentStatus(thread.ThreadID, status, participant.Email);
            }
            catch (Exception ex)
            {
                ExceptionLogManager.getInstance().LogException(ex);
                throw ex;
            }

            return(result);
        }
Ejemplo n.º 30
0
 /// <summary author="Dalton Cleveland" created="2019/03/27">
 /// Delete HouseKeepingRequest will determine whether the HouseKeepingRequest needs to be deleted or deactivated and request deactivation or deletion from a HouseKeepingRequest Accessor
 /// </summary>
 public void DeleteHouseKeepingRequest(int HouseKeepingRequestID, bool isActive)
 {
     if (isActive)
     {
         //Is Active so we just deactivate it
         try
         {
             _houseKeepingRequestAccessor.DeactivateHouseKeepingRequest(HouseKeepingRequestID);
         }
         catch (Exception ex)
         {
             ExceptionLogManager.getInstance().LogException(ex);
             throw ex;
         }
     }
     else
     {
         //Is Deactive so we purge it
         try
         {
             _houseKeepingRequestAccessor.PurgeHouseKeepingRequest(HouseKeepingRequestID);
         }
         catch (Exception ex)
         {
             ExceptionLogManager.getInstance().LogException(ex);
             throw ex;
         }
     }
 }