Ejemplo n.º 1
0
        /// <summary>
        /// This function return all the GuestRequest match the <paramref name="hu"/>
        /// </summary>
        /// <param name="hu">The hostingUnit to return all the guestRequest match him</param>
        /// <exception cref="NoItemsException">Thrown when there isnt any guestRequest in the data</exception>
        /// <returns><see cref="List{GuestRequest}"/> of all the GuestRequest match <paramref name="hu"/></returns>
        public List <GuestRequest> GetMatchingGuestRequests(HostingUnit hu)
        {
            try
            {
                var linq = from i in DAL_Adapter.GetDAL().GetAllGuestRequests()
                           where i.Adults <= hu.NumberOfPlacesForAdults &&
                           i.Children <= hu.NumberOfPlacesForChildren &&
                           CheckIfAvailable(hu.Diary, i.EntryDate, i.ReleaseDate) &&
                           IsRelevant(i.ChildrensAttractions, hu.IsThereChildrensAttractions) &&
                           IsRelevant(i.Garden, hu.IsThereGarden) &&
                           IsRelevant(i.Jacuzzi, hu.IsThereJacuzzi) &&
                           IsRelevant(i.Pool, hu.IsTherePool) &&
                           IsRelevant(i.Area, hu.Area) &&
                           IsRelevant(i.Type, hu.Type) &&
                           i.Status == Enums.RequestStatus.Open

                           select i;

                List <GuestRequest> ret = new List <GuestRequest>();
                foreach (var i in linq)
                {
                    ret.Add(i);
                }

                return(ret);
            }
            catch (NoItemsException e)
            {
                throw;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Add Order to the data
        /// </summary>
        /// <exception cref="AlreadyExistsException">Thrown when the key is already in the list</exception>
        /// <exception cref="InfoNotExistsException">Thrown when the GuestRequest or HostingUnit of the Order does not exist</exception>
        /// <exception cref="OccupiedDatesException">Thrown When requested dates are not available in the hosting unit (ie occupied by another)</exception>
        /// <param name="ord">Order to add</param>
        public void AddOrder(Order ord)
        {
            ///<remarks>we dont need to check if the entry date and the release date are good because its checked when you create the guestRequest(in <see cref="AddGuestRequest(GuestRequest)"/>)</remarks>
            //REMARK: יש לוודא בעת יצירת הזמנה ללקוח, שהתאריכים המבוקשים פנויים ביחידת האירוח שמוצעת לו.
            //REMARK: לא ניתן לקבוע אירוח לתאריך שכבר תפוס ע"י לקוח אחר
            //REMARK: • אם מוסיפים הזמנה, אזי יש לוודא שהלקוח ויחידת האירוח אכן קיימים.

            //check that the GuestRequest and HostingUnit of the Order exist
            if (!CheckIfHostingUnitExists(ord.HostingUnitKey))
            {
                throw new InfoNotExistsException("HostingUnit", "Order");
            }
            if (!CheckIfGuestRequestExists(ord.GuestRequestKey))
            {
                throw new InfoNotExistsException("GuestRequest", "Order");
            }

            //check that the requested dates are available in the hosting unit (ie. not occupied by another),
            //its will never throw the "KeyNotFoundException" because we already check that the HostingUnit and the GuestRequest are exists
            if (!CheckIfAvailable(DAL_Adapter.GetDAL().GetHostingUnit(ord.HostingUnitKey).Diary, DAL_Adapter.GetDAL().GetGuestRequest(ord.GuestRequestKey).EntryDate, DAL_Adapter.GetDAL().GetGuestRequest(ord.GuestRequestKey).ReleaseDate))
            {
                throw new OccupiedDatesException();
            }
            try
            {
                DAL_Adapter.GetDAL().AddOrder(ord);
            }
            catch (AlreadyExistsException e)
            {
                throw new AlreadyExistsException(e.Message);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This function updates a hosting unit
        /// </summary>
        /// <exception cref="KeyNotFoundException">Thrown when hosting unit with <paramref name="key"/> is not found</exception>
        ///<exception cref="ChangedWhileLinkedException">Thrown if there is any open <see cref="Order"/> linked to the hosting unit with the <paramref name="key"/> and you try to change the <see cref="Host.CollectionClearance"/> property in the <see cref="HostingUnit.Owner"/> property</exception>
        /// <param name="hostingUnit">Hosting unit to update to</param>
        /// <param name="key">Key of hosting unit to update</param>
        public void UpdateHostingUnit(HostingUnit hostingUnit, int key)
        {
            //we assume that An Order considered "open" if  its status is "Enums.OrderStatus.UnTreated" and also "Enums.OrderStatus.SentMail
            //REMARK: • לא ניתן לבטל הרשאה לחיוב חשבון כאשר יש הצעה הקשורה אליה במצב פתוח.
            Host hostBeforeUpdating;

            try
            {
                hostBeforeUpdating = DAL_Adapter.GetDAL().GetHostingUnit(key).Owner;
            }
            catch (KeyNotFoundException e)
            {
                throw new KeyNotFoundException(e.Message);
            }

            if (!hostingUnit.Owner.CollectionClearance && hostBeforeUpdating.CollectionClearance)//If you try to cancel the account cancellation permission
            {
                var linkedOpenOrderList = from order in DAL_Adapter.GetDAL().GetAllOrders()
                                          where order.HostingUnitKey == key && (order.Status == Enums.OrderStatus.UnTreated || order.Status == Enums.OrderStatus.SentMail)
                                          select order;
                if (linkedOpenOrderList.Count() != 0)
                {
                    throw new ChangedWhileLinkedException("change CollectionClearance of", "HostingUnit", key, "Order", linkedOpenOrderList.First().OrderKey);
                }
            }
            DAL_Adapter.GetDAL().UpdateHostingUnit(hostingUnit, key);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// This function removes a hosting unit from the data
        /// </summary>
        /// <exception cref="KeyNotFoundException">Thrown if no hosting unit in the data match the hosting unit with the <paramref name="key"/></exception>
        ///<exception cref="ChangedWhileLinkedException">Thrown if there is any open <see cref="Order"/> linked to the hosting unit with the <paramref name="key"/> and you try to delete it</exception>
        /// <param name="key">Key to remove the hosting unit of</param>
        public void RemoveHostingUnit(int key)
        {
            //we assume that An Order considered "open" if  its status is "Enums.OrderStatus.UnTreated" and also "Enums.OrderStatus.SentMail"
            //REMARK לא ניתן למחוק יחידת אירוח כל עוד יש הצעה הקשורה אליה במצב פתוח.
            bool isEmpty = false;

            try // We do this since if we want to delete a hosting unit before an order is made
            {
                DAL_Adapter.GetDAL().GetAllOrders();
            }
            catch (NoItemsException)
            {
                isEmpty = true;
            }
            if (!isEmpty)
            {
                var linkedOpenOrderList = from order in DAL_Adapter.GetDAL().GetAllOrders()
                                          where order.HostingUnitKey == key && (!IsClosed(order.Status))
                                          select order;
                if (linkedOpenOrderList.Count() != 0)
                {
                    throw new ChangedWhileLinkedException("delete", "HostingUnit", key, "Order", linkedOpenOrderList.First().OrderKey);
                }
            }
            try
            {
                DAL_Adapter.GetDAL().RemoveHostingUnit(key);
            }
            catch (KeyNotFoundException e)
            {
                throw new KeyNotFoundException(e.Message);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// This function return all the HostingUnit match the <paramref name="gr"/> and belong to <paramref name="host"/>
        /// </summary>
        /// <param name="gr">The guestRequest to return all the guestRequest match him</param>
        ///<param name="host">The Host that all the hostingUnit in the result must belong to him</param>
        /// <exception cref="NoItemsException">Thrown when there are no HostingUnit in the list</exception>
        /// <returns><see cref="List{Hos}"/> of all the HostingUnit match <paramref name="gr"/> and belong to<paramref name="host"/></returns>
        public List <HostingUnit> GetMatchingHostingUnits(GuestRequest gr, Host host)
        {
            var linq = from i in DAL_Adapter.GetDAL().GetAllHostingUnits()
                       where gr.Adults <= i.NumberOfPlacesForAdults &&
                       gr.Children <= i.NumberOfPlacesForChildren &&
                       CheckIfAvailable(i.Diary, gr.EntryDate, gr.ReleaseDate) &&
                       IsRelevant(gr.ChildrensAttractions, i.IsThereChildrensAttractions) &&
                       IsRelevant(gr.Garden, i.IsThereGarden) &&
                       IsRelevant(gr.Jacuzzi, i.IsThereJacuzzi) &&
                       IsRelevant(gr.Pool, i.IsTherePool) &&
                       IsRelevant(gr.Area, i.Area) &&
                       IsRelevant(gr.Type, i.Type) &&
                       gr.Status == Enums.RequestStatus.Open &&
                       i.Owner.HostKey == host.HostKey

                       select i;

            List <HostingUnit> ret = new List <HostingUnit>();

            foreach (var i in linq)
            {
                ret.Add(i);
            }

            return(ret);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Add HostingUnit to the data
 /// </summary>
 /// <exception cref="AlreadyExistsException">Thrown when the key is already in the list</exception>
 /// <param name="hostingUnit">The HostingUnit to add</param>
 public void AddHostingUnit(HostingUnit hostingUnit)
 {
     try
     {
         DAL_Adapter.GetDAL().AddHostingUnit(hostingUnit);
     }
     catch (AlreadyExistsException e)
     {
         throw new AlreadyExistsException(e.Message);
     }
 }
Ejemplo n.º 7
0
 /// <summary>
 /// This function return all the Order
 /// </summary>
 /// <exception cref="NoItemsException">Thrown when there are no orders in the list</exception>
 /// <returns><see cref="IEnumerable{Order}"/> to go over the list of orders</returns>
 public IEnumerable <Order> GetAllOrders()
 {
     try
     {
         return(DAL_Adapter.GetDAL().GetAllOrders());
     }
     catch (KeyNotFoundException e)
     {
         throw new KeyNotFoundException(e.Message);
     }
 }
Ejemplo n.º 8
0
 /// <summary>
 /// The Function return all the Hosting unit
 /// </summary>
 /// <exception cref="NoItemsException">Thrown if there are no items in the hosting units list</exception>
 /// <returns><see cref="IEnumerable{HostingUnit}"/> to go over the list of hosting units</returns>
 public IEnumerable <HostingUnit> GetAllHostingUnits()
 {
     try
     {
         return(DAL_Adapter.GetDAL().GetAllHostingUnits());
     }
     catch (NoItemsException)
     {
         throw;
     }
 }
Ejemplo n.º 9
0
 /// <summary>
 /// This function return BankBranch according to <paramref name="key"/>
 /// </summary>
 /// <exception cref="KeyNotFoundException">Thrown if object with key of <paramref name="key"/> does not exist</exception>
 /// <param name="key">The key of the BankBranch</param>
 public BankBranch GetBankBranch(int key)
 {
     try
     {
         return(DAL_Adapter.GetDAL().GetBankBranch(key));
     }
     catch (KeyNotFoundException e)
     {
         throw new KeyNotFoundException(e.Message);
     }
 }
Ejemplo n.º 10
0
 /// <summary>
 /// The function returns the list of all existing bank branches in Israel
 /// </summary>
 /// <exception cref="NoItemsException">Thrown when there are no bank accounts in the list</exception>
 /// <returns><see cref="IEnumerable{BankBranch}"/> to go over the list of bank accounts</returns>
 public IEnumerable <BankBranch> GetAllBankAccounts()
 {
     try
     {
         return(DAL_Adapter.GetDAL().GetAllBankAccounts());
     }
     catch (NoItemsException e)
     {
         throw new NoItemsException(e.Message);
     }
 }
Ejemplo n.º 11
0
 /// <summary>
 /// This function return all the GuestRequest in the data
 /// </summary>
 /// <exception cref="NoItemsException">Thrown if there are no guest requests</exception>
 /// <returns><see cref="IEnumerable{GuestRequest}"/> to go over the list of guest requests</returns>
 public IEnumerable <GuestRequest> GetAllGuestRequests()
 {
     try
     {
         return(DAL_Adapter.GetDAL().GetAllGuestRequests());
     }
     catch (NoItemsException e)
     {
         throw new NoItemsException(e.Message);
     }
 }
Ejemplo n.º 12
0
 /// <summary>
 /// This function return the Host with the <paramref name="key"/>
 /// </summary>
 /// <exception cref="KeyNotFoundException">Thrown if object with key of <paramref name="key"/> does not exist</exception>
 /// <param name="key">The requested <see cref="Host"/>'s KEY</param>
 /// <returns>The Host with the  <paramref name="key"/></returns>
 public Host GetHost(int key)
 {
     try
     {
         return(DAL_Adapter.GetDAL().GetHost(key));
     }
     catch (KeyNotFoundException e)
     {
         throw new KeyNotFoundException(e.Message);
     }
 }
Ejemplo n.º 13
0
 /// <summary>
 /// This function add GuestRequest to the data
 /// </summary>
 /// <exception cref="AlreadyExistsException">Thrown when the key is already in the list</exception>
 /// <exception cref="ArgumentException">Thrown when the vacation start date is not at least one day before the vacation end date</exception>
 /// <param name="gr">The GuestRequst to add</param>
 public void AddGuestRequest(GuestRequest gr)
 {
     //REMARK: תאריך תחילת הנופש קודם לפחות ביום אחד לתאריך סיום הנופש
     if (!IsLeastThenOneDay(gr.EntryDate, gr.ReleaseDate))
     {
         throw new ArgumentException("The release date must be at least one day after the entry date", "ReleaseDate");
     }
     try
     {
         DAL_Adapter.GetDAL().AddGuestRequest(gr);
     }
     catch (AlreadyExistsException e)
     {
         throw new AlreadyExistsException(e.Message);
     }
 }
Ejemplo n.º 14
0
        /// <summary>
        /// This function updates a guest request of key <paramref name="key"/> to the status <paramref name="stat"/>
        /// </summary>
        /// <exception cref="KeyNotFoundException">Thrown if object with key of <paramref name="key"/> does not exist</exception>
        ///<exception cref="AlreadyClosedException">Thrown when tryin to change the status of GuestRequest Whose status has already been set to "closed"</exception>
        /// <param name="key">Key of guest request to update</param>
        /// <param name="stat">Status to update guest request to</param>
        ///<remarks>I assume that like <see cref="UpdateOrderStatus(int, Enums.OrderStatus)"/> if the status is already close itsn't need to throw Exception</remarks>
        public void UpdateGuestRequestStatus(int key, Enums.RequestStatus stat)
        {
            if (!CheckIfGuestRequestExists(key))
            {
                throw new KeyNotFoundException("There is no order with the key specified");
            }
            GuestRequest gr = DAL_Adapter.GetDAL().GetGuestRequest(key);

            if (IsClosed(gr.Status) && !IsClosed(stat))
            {
                throw new AlreadyClosedException("GuestRequest", gr.GuestRequestKey);
            }
            try
            {
                DAL_Adapter.GetDAL().UpdateGuestRequestStatus(key, stat);
            }
            catch (KeyNotFoundException e)
            {
                throw new KeyNotFoundException(e.Message);
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// This function updates an order with a key of <paramref name="key"/> to a status of <paramref name="stat"/>
        /// </summary>
        /// <exception cref="KeyNotFoundException">Thrown when an order with the specified key is not found</exception>
        ///<exception cref="AlreadyClosedException">Thrown when tryin to change the status of Order Whose status has already been set to "closed"</exception>
        ///<exception cref="UnauthorizedActionException">Throw when try to change the status to <see cref="Enums.OrderStatus.SentMail"/> but the <see cref="Host.CollectionClearance"/> is false</exception>
        /// <param name="key">Key of Order to update the status of</param>
        /// <param name="stat">Status to update Order status to</param>
        public void UpdateOrderStatus(int key, Enums.OrderStatus stat)
        {
            //REMARK: בעל יחידת אירוח יוכל לשלוח הזמנה ללקוח )שינוי הסטטוס ל "נשלח מייל"(, רק אם חתם על הרשאה לחיוב חשבון בנק - done
            //REMARK: לאחר שסטטוס ההזמנה השתנה לסגירת עיסקה – לא ניתן לשנות יותר את הסטטוס שלה. - done
            //REMARK: כאשר סטטוס ההזמנה משתנה בגלל סגירת עסקה – יש לבצע חישוב עמלה בגובה של 10 ₪ ליום אירוח. )עיין הערה למטה(
            //REMARK: כאשר סטטוס ההזמנה משתנה בגלל סגירת עסקה – יש לסמן במטריצה את התאריכים הרלוונטיים. - done
            //REMARK: כאשר סטטוס הזמנה משתנה עקב סגירת עסקה – יש לשנות את הסטטוס של דרישת הלקוח בהתאם, וכן לשנות את הסטטוס של כל ההזמנות האחרות של אותו לקוח. - done
            //REMARK:   כאשר סטטוס ההזמנה משתנה ל"נשלח מייל" – המערכת תשלח באופן אוטומטי מייל  ללקוח עם פרטי ההזמנה. ניתן לדחות את הביצוע בפועל של שליחת המייל לשלב הבא, וכעת רק להדפיס הודעה על המסך. -done
            if (!CheckIfOrderExists(key))
            {
                throw new KeyNotFoundException("There is no order with the key specified");
            }

            Order ord = GetOrder(key);

            //I assumed that when the status is changed to close ("CustomerResponsiveness" or "CustomerUnresponsiveness")
            //you can still change the type of close but not to any open status("UnTreated" or "SentMail")
            if (IsClosed(ord.Status) && !IsClosed(stat))
            {
                throw new AlreadyClosedException("Order", key);
            }

            if (stat == Enums.OrderStatus.SentMail)
            {
                if (!GetHostingUnit(ord.HostingUnitKey).Owner.CollectionClearance)
                {
                    throw new UnauthorizedAccessException("a host cannot send an email if it does not authorize an account billing authorization");
                }
                Console.WriteLine("Send mail");
                DAL_Adapter.GetDAL().UpdateOrderStatus(key, Enums.OrderStatus.SentMail);
            }

            if (stat == Enums.OrderStatus.ClosedByCustomerResponsiveness)
            {
                HostingUnit  hostingUnit  = GetHostingUnit(ord.HostingUnitKey);
                GuestRequest guestRequest = GetGuestRequest(ord.GuestRequestKey);

                ///<remarks>
                ///This log check is here in addition to the check when creating the order(<see cref="AddOrder(Order)"/>)
                ///to avoid a situation where 2 guestRequest have booked the same day and the one host send order to each of them
                ///and one of them approved then if the other approve and mark even though the dates are busy, he can do it
                ///so we added another check her
                ///</remarks>
                if (CheckIfAvailable(hostingUnit.Diary, guestRequest.EntryDate, guestRequest.ReleaseDate))
                {
                    hostingUnit.Diary = MarkingInTheDiary(hostingUnit, guestRequest.EntryDate, guestRequest.ReleaseDate);
                    UpdateHostingUnit(hostingUnit, ord.HostingUnitKey);
                }
                else
                {
                    DAL_Adapter.GetDAL().UpdateOrderStatus(key, Enums.OrderStatus.ClosedByHost);
                    throw new OccupiedDatesException(guestRequest.EntryDate.Day + "." + guestRequest.EntryDate.Month + " - " + guestRequest.ReleaseDate.Day + "." + guestRequest.ReleaseDate.Month);
                }

                //close all the orders to this guestRequest
                UpdateGuestRequestStatus(ord.GuestRequestKey, Enums.RequestStatus.ClosedWithDeal);
                var linkedOrder = from order in GetAllOrders()
                                  where order.GuestRequestKey == ord.GuestRequestKey
                                  select order;
                linkedOrder.AsParallel().ForAll((x => UpdateOrderStatus(x.OrderKey, Enums.OrderStatus.ClosedByHost)));

                //calculate the Commission
                hostingUnit.Commission += GetNumberOfDateInRange(guestRequest.EntryDate, guestRequest.ReleaseDate) * Configuration.Commission;
                UpdateHostingUnit(hostingUnit, hostingUnit.HostingUnitKey);
            }
        }
Ejemplo n.º 16
0
 /// <summary>
 /// This function return if host exists in the data
 /// </summary>
 /// <param name="key">The key of the host</param>
 /// <returns>boolean, if the host exists or not</returns>
 public bool CheckIfHostExists(int key)
 {
     return(DAL_Adapter.GetDAL().CheckIfHostExists(key));
 }
Ejemplo n.º 17
0
 /// <summary>
 /// This function return if bankAccount exists in the data
 /// </summary>
 /// <param name="key">The key of the bankAccount</param>
 /// <returns>boolean, if the bankAccount exists or not</returns>
 public bool CheckIfBankAccountExists(int key)
 {
     return(DAL_Adapter.GetDAL().CheckIfBankAccountExists(key));
 }