Пример #1
0
        public void UpdateOrder(long orderKey, OrderStatus newStatus)
        {
            var unitCollection = dal.GetAllUnits();//gets all hosting units

            HostingUnit currentUnit = new HostingUnit();

            foreach (var item in unitCollection)//find the current hosting unit
            {
                if (item.HostingUnitKey == FindOrderByKey(orderKey).HostingUnitKey)
                {
                    currentUnit = item;
                }
            }
            if (newStatus == OrderStatus.MailSend && currentUnit.Owner.BankBranchDetails.CollectionClearance == YesNo.No)
            {
                throw new DataException("Their is not collection clearence");
            }

            Order currentOrder = FindOrderByKey(orderKey);//find the current order to update

            if (currentOrder.Status == OrderStatus.DillMade)
            {
                throw new DataException("cannot change the status when dill made");
            }

            DateTime     entryDate      = new DateTime();
            DateTime     releaseDate    = new DateTime();
            GuestRequest currentRequest = FindReqByKey(currentOrder.GuestRequestKey);

            entryDate   = currentRequest.EntryDate;
            releaseDate = currentRequest.ReleaseDate;

            if (newStatus == OrderStatus.MailSend)
            {
                currentOrder.OrderDate = DateTime.Now;
                //MailMessage mail = new MailMessage();
                ////find the mail address of the guest request creator
                //mail.To.Add(FindReqByKey(FindOrderByKey(orderKey).GuestRequestKey).MailAddress);
                //mail.From = new MailAddress("*****@*****.**");
            }

            if (newStatus == OrderStatus.DillMade)
            {
                //Calculate the commition for the website
                currentUnit.Owner.BankBranchDetails.MyCommition +=
                    DaysBetween(entryDate, releaseDate) * BE.Configuration.Commition;

                //change the dates in the diary of the unit
                for (DateTime i = entryDate; i < releaseDate; i = i.AddDays(1))
                {
                    currentUnit.Diary[i.Month, i.Day] = true;
                }

                //Change the status of all the requests of the client
                currentRequest.Status = GuestRequestStatus.DealComplete;
                List <GuestRequest> allclientReq =
                    RequestUnderCond(x => x.FirstName == currentRequest.FirstName &&
                                     x.LastName == currentRequest.LastName);
                foreach (var item in allclientReq)
                {
                    item.Status = GuestRequestStatus.DealComplete;
                }
            }

            dal.UpdateOrder(currentOrder);
        }
Пример #2
0
        public void UpdateOrder(Order order, string text, string pic)//Updates Order
        {
            Order orig = GetAllOrders().FirstOrDefault(t => t.OrderKey == order.OrderKey);

            if ((orig.Status == Status.Closed_ClientRequest || orig.Status == Status.Closed_NoReply))
            {
                throw new TaskCanceledException("Status cannot be changed");
            }

            if (orig.Status == Status.Active && order.Status == Status.Active)
            {
                return;
            }
            if (orig.Status != Status.Active && order.Status == Status.Active)
            {
                return;
            }
            if (orig.Status == Status.Mail_Sent && order.Status == Status.Mail_Sent)
            {
                try
                {
                    //dal.UpdateOrder(order.Clone());
                }
                catch (KeyNotFoundException e)
                {
                    throw e;
                }
            }
            if (order.Status == Status.Closed_NoReply)
            {
                if (order.OrderDate == default(DateTime))
                {
                    throw new TaskCanceledException("Cannot Update order to closed before an email was sent");
                }
                try
                {
                    dal.UpdateOrder(order.Clone());
                }
                catch (KeyNotFoundException e)
                {
                    throw e;
                }
            }
            if (order.Status == Status.Closed_ClientRequest)
            {
                if (order.OrderDate == default(DateTime))
                {
                    throw new TaskCanceledException("Cannot Update order to closed before an email was sent");
                }
                Guest guest = dal.GetGuest(order.GuestRequestKey);
                guest.GuestStatus = Status.Closed_ClientRequest;
                UpdateGuestReq(guest);

                HostingUnit tmp = dal.GetHostingUnit(order.HostingUnitKey);
                if (!CheckOffDates(tmp, guest.EntryDate, guest.ReleaseDate))
                {
                    throw new TaskCanceledException("could not book dates");
                }
                Charge(FindHost(order.HostingUnitKey), DaysBetween(guest.EntryDate, guest.ReleaseDate)); //charges the host 10 nis
                // Charge(tmp, DaysBetween(guest.EntryDate, guest.ReleaseDate));
                UpdateHostUnit(tmp.Clone());                                                             //need if we figure out how to clone diary
                foreach (Order order1 in dal.GetAllOrders())                                             //closes all orders that are open for this guest
                {
                    if (order1.GuestRequestKey == guest.GuestRequestKey)
                    {
                        order1.Status = Status.Closed_ClientRequest;
                        dal.UpdateOrder(order1);
                    }
                }
                return;
            }
            if (order.Status == Status.Mail_Sent)
            {
                HostingUnit hosting = dal.GetHostingUnit(order.HostingUnitKey);
                if (!CheckIsBankAllowed(hosting.Owner, order))
                {
                    throw new TaskCanceledException("Cannot send mail. No debit authorization\n please update Automatic billing.");
                }
                SendMail(order, text, pic);
                order.OrderDate = DateTime.Now;
            }
            try
            {
                dal.UpdateOrder(order.Clone());
            }
            catch (KeyNotFoundException e)
            {
                throw e;
            }
        }