Ejemplo n.º 1
0
 public void UpdateOrder(BO.Order order)
 {
     DO.Order dalOrder = new DO.Order();
     try
     {
         dalOrder = dal.RecieveOrder(order.Key);
     }
     catch (MissingMemberException e)
     {
         throw e;
     }
     if (!AbleToChangeOrderStatus(order))
     {
         throw new InvalidOperationException("You can't change a order status after other placed/ alradey irrelevant");
     }
     else
     {
         //check if order placed now
         if (IsOpenOrder(Conversions.CastingToBO_Order(dalOrder)))
         {
             if (order.Status == BO.Order_Status.EMAIL_SENT && dalOrder.Status != DO.Order_Status.EMAIL_SENT)
             {
                 SendEmail(order);
             }
             if (order.Status == BO.Order_Status.APPROVED)
             {
                 PlaceOrder(order);
                 order.CloseDate = DateTime.Now;
             }
         }
     }
     dal.UpdateOrder(Conversions.CastingToDO_Order(order));
 }
Ejemplo n.º 2
0
        public void SendEmail(BO.Order order)
        {
            BO.Person   client       = Conversions.CastingToBOPerson(dal.RecievePerson(order.GuestRequest.ClientID));
            string      EmailAddress = client.MailAddress;
            MailMessage email        = new MailMessage();

            email.To.Add(EmailAddress);
            email.From       = new MailAddress("*****@*****.**");
            email.Subject    = "הזמנה";
            email.IsBodyHtml = true;
            string htmlbody = File.ReadAllText("html1.txt", Encoding.UTF8);

            email.BodyEncoding = Encoding.Unicode;
            email.Body         = string.Format(htmlbody, order.Key, order.HostingUnit.HostingUnitName, order.HostingUnit.ToString(), client.MailAddress, order.HostingUnit.ImageLink1, order.HostingUnit.ImageLink2, order.HostingUnit.ImageLink3);
            SmtpClient smtp = new SmtpClient();

            smtp.Credentials = new System.Net.NetworkCredential("*****@*****.**", "rede24@@");
            smtp.EnableSsl   = true;
            smtp.Host        = "smtp.gmail.com";
            try
            {
                smtp.Send(email);
            }
            catch (Exception exp)
            {
                throw exp;
            }
        }
        public void UpdateStatusOrder(BO.OrderStatus updateorder, int key)
        {
            try
            {
                BO.Order tmp1 = Converters.Conv_DO_To_BO(dal.GetOrder(key));
                if (tmp1.Status == OrderStatus.IGNORED_CLOSED || tmp1.Status == OrderStatus.APPROVED)
                {
                    throw new Exception("אין אפשרות לשנות את הסטטוס לאחר סגירת עסקה");
                }
                BO.Host temp2 = Converters.Conv_DO_To_BO(dal.GetHost(tmp1.HostId));
                if (updateorder == OrderStatus.MAIL_SENT)
                {
                    if (!temp2.CollectionClearance)
                    {
                        throw new Exception("אין אפשרות לשלוח מייל ללקוח מבלי לחתום על הרשאה לחיוב חשבון");
                    }
                }
                if (updateorder == OrderStatus.APPROVED)
                {
                    BO.Order        update  = Converters.Conv_DO_To_BO(dal.GetOrder(key));
                    BO.HostingUnit  unit    = Converters.Conv_DO_To_BO(dal.GetHostingUnit(update.HostingUnitKey));
                    BO.GuestRequest request = Converters.Conv_DO_To_BO(dal.GetGuestRequest(update.GuestRequestKey));
                    SetDairy(unit, request);
                    dal.UpdateHostingUnit(Converters.Conv_BO_To_DO(unit));
                    update.ClientName = dal.GetPerson(update.ClientId).FirstName + dal.GetPerson(update.ClientId).LastName;
                    update.Commission = 10; //סכום העמלה
                    dal.UpdateOrder(Converters.Conv_BO_To_DO(update));
                    List <Order> lst = GetOrdersByRequestKey(request.Key).ToList();
                    foreach (var i in lst)//change all orders to Irrelevant
                    {
                        if (i.Key != update.Key)
                        {
                            dal.UpdateStatusOrder(i.Key, DO.OrderStatus.IRRELEVANT);
                        }
                    }
                    try
                    {
                        SendEmail(tmp1);
                    }
                    catch (Exception)
                    {
                        throw new Exception("Check your Internet connection");
                    }

                    ////////////////////////////////////////////////////////////////////////////////////////
                }
                dal.UpdateStatusOrder(key, (DO.OrderStatus)updateorder);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Ejemplo n.º 4
0
        public void PlaceOrder(BO.Order order)
        {
            MarkDates(order);
            order.Commission = CalculateCommision(order);
            CloseIrrelevantOrders(order);
            UpdateUserStatus(order);
            DO.Host host = dal.RecieveHost(order.HostID);
            host.TotalCommission += order.Commission;
            order.TotalCost       = order.HostingUnit.PricePerNight * PassedDays(order.GuestRequest.EntryDate, order.GuestRequest.ReleaseDate);

            dal.UpdateHost(host);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// In this function we recieve all orders that belong to this Guest Request which status changed to "approved".
        /// It also recieves all the orders that belong to this hosting unit with schedule overlap and change their status to "irrelevant".
        /// </summary>
        /// <param name="order"></param>
        public void CloseIrrelevantOrders(BO.Order order)//
        {
            var orders = from item in dal.GetOrdersList(x => x.Key != order.Key)
                         where item.GuestRequestKey == order.GuestRequest.GuestRequestKey ||
                         item.HostingUnitKey == order.HostingUnit.Key && !IsAvailableGuestRequest(Conversions.CastingToBOGuestRequest(dal.RecieveGuestRequest(item.GuestRequestKey)),
                                                                                                  Conversions.CastingToBOHostingUnit(dal.RecieveHostingUnit(item.HostingUnitKey)))
                         select item;

            foreach (var item in orders.ToList())
            {
                item.Status = DO.Order_Status.IRRELEVANT;
                dal.UpdateOrder(item);
            }
        }
        public static DO.Order ConverFrom_BO_To_DoOrder(BO.Order other)
        {
            DO.Order tmp = new DO.Order();
            tmp.CloseDate       = other.CloseDate;
            tmp.GuestRequestKey = other.GuestRequestKey;
            tmp.HostingUnitKey  = other.HostingUnitKey;
            tmp.Key             = other.KeyOrder;
            tmp.OrderDate       = other.OrderDate;
            tmp.SentDate        = other.SentDate;
            tmp.Status          = (DO.StatusOrder)other.Status;
            tmp.TotalPrice      = other.TotalPrice;


            return(tmp);
        }
Ejemplo n.º 7
0
        public void MarkDates(BO.Order order)//
        {
            DO.GuestRequest guestRequest = dal.RecieveGuestRequest(order.GuestRequest.GuestRequestKey);
            DO.HostingUnit  dHostingUnit = dal.RecieveHostingUnit(order.HostingUnit.Key);
            DateTime        temp         = guestRequest.EntryDate;

            //now we mark this days in true
            while (DateTime.Compare(temp, guestRequest.ReleaseDate) != 0)
            {
                dHostingUnit.SetDate(temp, true);
                temp = temp.AddDays(1);
            }
            dal.UpdateHostingUnit(dHostingUnit);
            guestRequest.Status = DO.Request_Statut.ORDERED;
            //dal.UpdateGusetRequestStatus(guestRequest);
        }
 public static BO.Order ConverFrom_DO_To_BoOrder(DO.Order other)
 {
     BO.Order tmp = new BO.Order();
     tmp.CloseDate       = other.CloseDate;
     tmp.GuestRequestKey = other.GuestRequestKey;
     tmp.HostingUnitKey  = other.HostingUnitKey;
     tmp.KeyOrder        = other.Key;
     tmp.OrderDate       = other.OrderDate;
     tmp.SentDate        = other.SentDate;
     tmp.Status          = (BO.StatusOrder)other.Status;
     tmp.TotalPrice      = other.TotalPrice;
     tmp.unit            = instance.GetHoustingUinit(other.HostingUnitKey);
     tmp.HostId          = (instance.GetHoustingUinit(other.HostingUnitKey)).Owner;
     tmp.NameClient      = other.NameClient;
     return(tmp);
 }
 public static DO.Order Conv_BO_To_DO(BO.Order item)
 {
     DO.Order temp = new DO.Order();
     temp.CloseDate       = item.CloseDate;
     temp.GuestRequestKey = item.GuestRequestKey;
     temp.HostingUnitKey  = item.HostingUnitKey;
     temp.Key             = item.Key;
     temp.OrderDate       = item.OrderDate;
     temp.SentDate        = item.SentDate;
     temp.Status          = (DO.OrderStatus)item.Status;
     temp.TotalPrice      = item.TotalPrice;
     temp.CliendId        = item.ClientId;
     temp.ClientName      = item.ClientName;
     temp.Commission      = item.Commission;
     temp.HostId          = item.HostId;
     return(temp);
 }
Ejemplo n.º 10
0
        /// <summary>
        /// geting all the orders for this guest request(that answered) and make them irrelevant
        /// </summary>
        /// <param name="order"></param>
        public void UpdateUserStatus(BO.Order order)

        {
            var guestRequest = dal.RecieveGuestRequest(order.GuestRequest.GuestRequestKey);

            guestRequest.Status = DO.Request_Statut.ORDERED;
            dal.UpdateGusetRequest(guestRequest);
            var orders = dal.GetOrdersList(x => x.CliendID == order.GuestRequest.ClientID && x.Key != order.Key);

            foreach (var item in orders.ToList())
            {
                if (AbleToChangeOrderStatus(Conversions.CastingToBO_Order(item)))
                {
                    item.Status = DO.Order_Status.IRRELEVANT;
                    dal.UpdateOrder(item);
                }
            }
        }
Ejemplo n.º 11
0
 public static DO.Order CastingToDO_Order(BO.Order order)
 {
     DO.Order dOrder = new DO.Order()
     {
         CloseDate       = order.CloseDate,
         OrderDate       = order.OrderDate,
         GuestRequestKey = order.GuestRequest.GuestRequestKey,
         SentDate        = order.SentDate,
         Commission      = order.Commission,
         HostingUnitKey  = order.HostingUnit.Key,
         CliendID        = order.GuestRequest.ClientID,
         Status          = (DO.Order_Status)order.Status,
         HostID          = order.HostID,
         Key             = order.Key,
         TotalCost       = order.TotalCost
     };
     return(dOrder);
 }
Ejemplo n.º 12
0
 public static BO.Order Conv_DO_To_BO(DO.Order item)
 {
     BO.Order temp = new BO.Order();
     temp.CloseDate       = item.CloseDate;
     temp.GuestRequestKey = item.GuestRequestKey;
     temp.HostingUnitKey  = item.HostingUnitKey;
     temp.Key             = item.Key;
     temp.OrderDate       = item.OrderDate;
     temp.SentDate        = item.SentDate;
     temp.Status          = (BO.OrderStatus)item.Status;
     temp.TotalPrice      = item.TotalPrice;
     //temp.unit = Instance.GetHoustingUinit(item.HostingUnitKey);
     temp.HostId     = (Instance.GetHoustingUinit(item.HostingUnitKey)).HostId;
     temp.ClientName = item.ClientName;
     temp.ClientId   = item.CliendId;
     temp.Commission = item.Commission;
     return(temp);
 }
Ejemplo n.º 13
0
 public static BO.Order CastingToBO_Order(DO.Order order)
 {
     BO.Order bOrder = new BO.Order()
     {
         CloseDate       = order.CloseDate,
         OrderDate       = order.OrderDate,
         GuestRequest    = imp.GetGuestRequest(order.GuestRequestKey),
         SentDate        = order.SentDate,
         Commission      = order.Commission,
         HostingUnit     = imp.GetHostingUnit(order.HostingUnitKey),
         ClientFirstName = imp.GetPerson(order.CliendID).FirstName,
         ClientLastName  = imp.GetPerson(order.CliendID).LastName,
         Status          = (BO.Order_Status)order.Status,
         HostID          = order.HostID,
         Key             = order.Key,
         TotalCost       = order.TotalCost
     };
     return(bOrder);
 }
Ejemplo n.º 14
0
 public bool IsOpenOrder(BO.Order bOrder)
 {
     DO.Order order = dal.RecieveOrder(bOrder.Key);
     return(order.Status != DO.Order_Status.CLIENT_CLOSED && order.Status != DO.Order_Status.IGNORED_CLOSED && order.Status != DO.Order_Status.IRRELEVANT);
 }
Ejemplo n.º 15
0
 public int CalculateCommision(BO.Order order)//
 {
     return(dal.GetCommissionRate() * PassedDays(order.GuestRequest.EntryDate, order.GuestRequest.ReleaseDate));
 }
Ejemplo n.º 16
0
 public int AddOrder(BO.Order order)//
 {
     return(dal.AddOrder(Conversions.CastingToDO_Order(order)));
 }
Ejemplo n.º 17
0
 public bool AbleToChangeOrderStatus(BO.Order order)//
 {
     DO.Order dOrder = dal.RecieveOrder(order.Key);
     return(dOrder.Status != DO.Order_Status.APPROVED && dOrder.Status != DO.Order_Status.IRRELEVANT);
 }