public void UpdateOrder(Order newO) //status update { try { Order oldO = dal_bl.SearchOrbyID(newO.OrderKey); if (oldO.Status == Status.Closed) { throw new InvalidOperationException("cannot change status that is already closed"); } Host h = dal_bl.SearchHUbyID(newO.HostingUnitKey).Owner; if (newO.Status == Status.Booked) { GuestRequest g = dal_bl.searchGRbyID(newO.GuestRequestKey).Clone(); g.Status = Status.Closed; Updategr(g.Clone()); UpdateDiary(newO.Clone()); } //if (newO.Status == Status.SentEmail) //{ // if (h.CollectionClearance) // { // newO.SentEmail = Configuration.today; // SendEmail(newO.Clone()); // } // else throw new InvalidOperationException("cannot send email without permission to charge"); //} dal_bl.UpdateOrder(newO.Clone()); } catch (Exception a) { throw a; } }
public void AddOrder(Order o) { try { Host h = dal_bl.SearchHUbyID(o.HostingUnitKey).Owner; if (!AvailabilityCheck(dal_bl.SearchHUbyID(o.HostingUnitKey), dal_bl.searchGRbyID(o.GuestRequestKey))) { throw new InvalidOperationException("unit not available for this request"); } if (!dal_bl.HUexist(o.HostingUnitKey)) { throw new KeyNotFoundException("unit doesnt exist"); } if (!dal_bl.GRexist(o.GuestRequestKey)) { throw new KeyNotFoundException("request doesnt exist"); } dal_bl.AddOrder(o.Clone()); //o.Status = Status.SentEmail; //UpdateOrder(o.Clone()); if (h.CollectionClearance) { o.SentEmail = Configuration.today; SendEmail(o.Clone()); } else { throw new InvalidOperationException("cannot send email without permission to charge"); } } catch (Exception a) { throw a; } }
/// <summary> /// Add a new order to list of orders in Data Base /// </summary> /// <param name="order"></param> public void AddNewOrder(Order order) { //check if the id of the host correct if (!Validation.IsValidId(order.HostId)) { throw new Exception("the ID is invalid"); } //get the specific unit var getUnit = GetHostingUnit(order.HostingUnitKey, order.AccommodationKey, order.HostId); // get the specific guest request var guestRequest = _idalImp.GetAllGuestRequests(unit => unit.GuestRequestKey == order.GuestRequestKey) .FirstOrDefault().Clone(); if (guestRequest == null) { throw new Exception("Guest request not found in database"); } // check if the room calender is not occupied in the specifics date for (var i = guestRequest.CheckInDate; i < guestRequest.CheckOutDate; i = i.AddDays(1)) { if (getUnit[i]) { throw new Exception("The Date is occupied"); } } order.OrderStatus = enums.OrderStatus.Pending; order.OrderCreationDate = DateTime.Now; order.OrderKey = IDAL.Configuration.OrderKey++; _idalImp.HostingUnitSumOfOrdersUpdate(getUnit.HostingUnitKey, getUnit.AccommodationKey, getUnit.HostId, "offered"); _idalImp.AddNewOrder(order.Clone()); }
//----------------------------------------------------------------- public void addOrder(Order o) { if (dal.getHostingUnits().FindIndex(t => t.HostingUnitKey == o.HostingUnitKey) == -1) { throw new KeyNotFoundException("there is not such hosting unit to this order"); } if (dal.getGuestRequests().FindIndex(t => t.GuestRequestKey == o.GuestRequestKey) == -1) { throw new KeyNotFoundException("there is not such guest request to this order"); } if (isNotTaken(o)) { try { dal.addOrder(o.Clone()); } catch (Exception s) { throw s; } } else { throw new ArgumentException("This dates are already taken"); } }
public void AddOrder(Order order)//adds a new order { HostingUnit hosting = dal.GetHostingUnit(order.HostingUnitKey); if (hosting == null) { throw new KeyNotFoundException("Invalid Hosting Unit"); } Guest guest = dal.GetGuest(order.GuestRequestKey); if (guest == null) { throw new KeyNotFoundException("Invalid Guest"); } order.Status = Status.Active; order.CreateDate = DateTime.Now; try { dal.AddOrder(order.Clone()); } catch (DuplicateWaitObjectException e) { throw e; } }
public void ChangeRequestStatus(Order o) //to change order status to booked, other orders connected are closed, also the request status is changed to booked { IEnumerable <Order> orders = dal_bl.ListOfOrders(); //gets the list of orders GuestRequest gr = dal_bl.searchGRbyID(o.GuestRequestKey).Clone(); o.Status = Status.Booked; UpdateOrder(o.Clone()); gr.Status = Status.Booked; Updategr(gr.Clone()); CalculateComission(gr.Clone()); foreach (Order item in orders) { if (item.GuestRequestKey == gr.GuestRequestKey && item.OrderKey != o.OrderKey) { item.Status = Status.Closed; UpdateOrder(item); } } HostingUnit hu = dal_bl.SearchHUbyID(o.HostingUnitKey); Console.WriteLine(hu); }
//Update Order Status public bool UpdateOrder(Order O, OrderStatus status) { if (status == OrderStatus.Sent_Mail) { try { SendEmail(O); return(true); } catch (Exception e) { throw e; } } if (O.StatusOrder == OrderStatus.Closed_from_customer_not_respone || O.StatusOrder == OrderStatus.Closed_on_customer_response) { throw new Exception("Invitation status cannot be changed after it is closed"); } GuestRequest guestRequest_order = dal.GetClientRequest(O.GuestRequestKey); HostingUnit hostingUnit_order = dal.GetHostingUnit(O.HostingUnitKey); if (O.StatusOrder == OrderStatus.Closed_on_customer_response) { //checks if the dates are busy because maybe another customer has already closed these dates for (DateTime date = guestRequest_order.EntryDate; date < guestRequest_order.ReleaseDate; date = date.AddDays(1)) { if (hostingUnit_order[date] == true) { throw new Exception("These dates are busy"); } } } //Order orderToUpdate = O.Clone() dal.UpdateOrder(O.Clone(), status); //O //save the dates if (status == OrderStatus.Closed_from_customer_not_respone) { //calculate the fee for every day float Cal_fee = CalFee(O); // mark the days Mdays(O); dal.UpdateClientRequest(guestRequest_order, Request_Status.Closed_by_Web); List <Order> allTheCostumerOrders = dal.Lorder(item => item.GuestRequestKey == O.GuestRequestKey); foreach (var order in allTheCostumerOrders) { if (order.OrderKey != O.OrderKey) { dal.UpdateOrder(order, OrderStatus.Closed_from_customer_not_respone); } } } return(true); }
public void AddOrder(Order order) { BE.GuestRequest req = myDal.GetGuestRequest(order.GuestRequestKey); BE.HostingUnit unit = myDal.GetHostingUnit(order.HostingUnitKey); //checks if the dates are already occupied for (DateTime currentDate = req.EntryDate; currentDate < req.ReleaseDate; currentDate = currentDate.AddDays(1)) { if (unit.Diary[currentDate.Month - 1, currentDate.Day - 1]) { throw new TheUnitIsOccupiedException(); } } //checks if the request is available if (req.Status == GuestRequestStatus.ConnectedToOrder) { throw new StatusException(); } myDal.AddOrder(order.Clone()); }
private void SendEmail(Order O) { GuestRequest guestRequest_order = dal.GetClientRequest(O.GuestRequestKey); HostingUnit hostingUnit_order = dal.GetHostingUnit(O.HostingUnitKey); if (hostingUnit_order.Owner.CollectionClearance == false) { throw new Exception("Due to not allowing approval bank charge - mail was not sent"); } dal.UpdateOrder(O.Clone(), OrderStatus.Sent_Mail); MailMessage mail = new MailMessage(); mail.To.Add(guestRequest_order.MailAddress); mail.From = new MailAddress(dal.GetMail()); mail.Subject = "הזמנה ליחידת אירוח " + O.HostingUnitKey; mail.Body = "<div>" + "<p1>הזמנה ליחידת אירוח " + O.HostingUnitKey + "</p1>" + "<div>הזמנה מספר " + O.OrderKey + "</div>" + "</div>"; mail.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.Credentials = new NetworkCredential(dal.GetMail(), dal.GetPassword());//"*****@*****.**", "password"); smtp.EnableSsl = true; try { smtp.Send(mail); } catch (Exception e) { throw e; } }
private MailMessage MailSender(Order order, Order acceptedOrder, HostingUnit unit, GuestRequest req) { MailMessage mail = new MailMessage(); mail.To.Add(get_All_Requests().Find(X => X.GuestRequestKey == order.GuestRequestKey).MailAddress.ToString()); mail.From = new MailAddress(unit.Owner.MailAddress); mail.Subject = "Your order in Vacations Paradise"; mail.Body = "Hello and welcome to Vacations Paradise!\nHere are the details of your order:\n" + unit.ToString() + "Order create date: " + order.CreateDate + "\n"; mail.IsBodyHtml = true; var client = new SmtpClient("smtp.gmail.com", 587) { Credentials = new NetworkCredential("*****@*****.**", "yces24ou"), EnableSsl = true }; try { client.Send(mail); } catch (Exception ex) { throw new Exception(ex.Message); } finally { acceptedOrder.Status = Order_Status.Mail_Sent; Dal.Update_Order(acceptedOrder.Clone()); //After the client accepts one of the orders , we close all the other orders connected to him Order tempOrder = new Order(); foreach (Order o in Dal.Get_Order_List()) { if (o.GuestRequestKey == req.GuestRequestKey && o.OrderKey != acceptedOrder.OrderKey) { o.Status = Order_Status.Closed_No_Response; tempOrder = o; Dal.Update_Order(tempOrder.Clone()); } } if (unit.Owner.CollectionClearance == Clearance.Yes) { //Finding the duration int duration = (req.ReleaseDate - req.Entry_Date).Days; //Sum to pay unit.Sum_to_pay = duration * Configuration.Comission; //Updating the guest request unit.setRequest(req); Dal.Update_Hosting_Unit(unit); //Updating guest request status req.Status = Guest_Request_Status.Closed_on_Website; Dal.Update_Guest_Request(req); acceptedOrder.OrderDate = DateTime.Today; try { Dal.Update_Order(acceptedOrder.Clone()); } catch (KeyNotFoundException ex) { throw new KeyNotFoundException(ex.Message); } } } return(mail); }
/// <summary> /// Updating order (status) /// </summary> /// <param name="order"></param> /// public void Update_Order(Order order) { //If the order was closed , we can't change it anymore Order acceptedOrder = Dal.Get_Order_List().Find(o => o.OrderKey == order.OrderKey); if (acceptedOrder.Status == Order_Status.Closed_No_Response || acceptedOrder.Status == Order_Status.Closed_With_Success) { throw new CantUpdateException("The order was already closed ! From BL"); } HostingUnit unit = new HostingUnit(); try { unit = search_hostingunit(order.HostingUnitKey); } catch (KeyNotFoundException ex) { throw new KeyNotFoundException(ex.Message); } GuestRequest req = new GuestRequest(); try { req = Dal.Get_Guest_Request_List().Find(o => o.GuestRequestKey == order.GuestRequestKey); } catch (KeyNotFoundException ex) { throw new KeyNotFoundException(ex.Message); } if (order.Status == Order_Status.Mail_Sent) { //Sending mail MailMessage mail = new MailMessage(); SmtpClient smtp; try { Thread thread = new Thread(() => MailSender(order, acceptedOrder, unit, req)); thread.Start(); } catch (Exception ex) { throw new Exception(ex.Message); } return; } //If we closed the bussines, we will charge him for comission (10 NIS X duration) if (order.Status == Order_Status.Closed_With_Success) { //Checing that he signed if (unit.Owner.CollectionClearance == Clearance.Yes) { //Finding the duration int duration = (req.ReleaseDate - req.Entry_Date).Days; //Sum to pay unit.Sum_to_pay = duration * Configuration.Comission; //Updating the guest request unit.setRequest(req); Dal.Update_Hosting_Unit(unit); //Updating guest request status req.Status = Guest_Request_Status.Closed_on_Website; Dal.Update_Guest_Request(req); //Updating status(Mail Sent) acceptedOrder.Status = Order_Status.Closed_With_Success; acceptedOrder.OrderDate = DateTime.Today; try { Dal.Update_Order(acceptedOrder.Clone()); } catch (KeyNotFoundException ex) { throw new KeyNotFoundException(ex.Message); } //After the client accepts one of the orders , we close all the other orders connected to him Order tempOrder = new Order(); foreach (Order o in Dal.Get_Order_List()) { if (o.GuestRequestKey == req.GuestRequestKey && o.OrderKey != order.OrderKey) { o.Status = Order_Status.Closed_No_Response; tempOrder = o; Dal.Update_Order(tempOrder.Clone()); } } return; } else//If he didnt sign { throw new CantUpdateException("Couldn`t send e-mail , client didn`t sign for collection from bank account"); } } }
public Order UpdateOrder(Order or) //check if the update is ok or maybe we should add another update function { try { Order orOriginal = DAL.DalFactory.getDal().GetOrder(or.OrderKey); GuestRequest gr = DAL.DalFactory.getDal().GetGuestRequest(or.GuestRequestKey); HostingUnit hu = DAL.DalFactory.getDal().GetHostingUnit(or.HostingUnitKey); if ((orOriginal != null && gr != null && hu != null)) { if (orOriginal.Status == OrderStatus.ClosedForCustomerResponse || orOriginal.Status == OrderStatus.ClosedForCustomerUnresponsiveness) { throw new MyException("This order is closed for changes!"); } else if ((or.Status == OrderStatus.SentEmail || or.Status == OrderStatus.ClosedForCustomerResponse) && orOriginal.Status != OrderStatus.ClosedForCustomerResponse && orOriginal.Status != OrderStatus.ClosedForCustomerUnresponsiveness) { if (or.Status == OrderStatus.ClosedForCustomerResponse) { //***updating all the other linked orders***// List <Order> newList = DAL.DalFactory.getDal().CustomerReqOrder(or.GuestRequestKey); foreach (Order item in newList) { item.Status = OrderStatus.ClosedForCustomerUnresponsiveness; DAL.DalFactory.getDal().UpdateOrder(item.Clone()); } //***fee calculation***// or.OrderFee = ((gr.ReleaseDate - gr.EntryDate).TotalDays) * Configuration.fee; //***updating the diary***// for (DateTime i = gr.EntryDate; i != gr.ReleaseDate; i = i.AddDays(1)) { hu.Diary[i.Month - 1, i.Day - 1] = true; } return(DAL.DalFactory.getDal().UpdateOrder(or.Clone())); } else if (or.Status == OrderStatus.SentEmail && hu.Owner.CollectionClearance == true) { //or.Status = OrderStatus.SentEmail; or.OrderDate = DateTime.Today; or = DAL.DalFactory.getDal().UpdateOrder(or.Clone()); GuestRequest gr1 = DAL.DalFactory.getDal().GetGuestRequest(or.GuestRequestKey); if (gr1 != null) { gr1.Status = true; DAL.DalFactory.getDal().UpdateCustomerReq(gr1); thisOrder = or; Thread t = new Thread(SendMail); t.Start(); } throw new MyException("You have sent an Email to this customer!", or); } else { throw new MyException("You have not erranged the collection clearance with the bank - you can not send an email!"); } } else { return(DAL.DalFactory.getDal().UpdateOrder(or)); } } else { //DAL.DalFactory.getDal().UpdateCustomerReq(gr); //DAL.DalFactory.getDal().UpdateHostingUnit(hu); return(DAL.DalFactory.getDal().UpdateOrder(or)); } } catch (MyException ex) { throw new MyException(ex.Message, (Order)ex.item); } }
public int AddOrder(Order ord) { CheckOrder(ord); ord.createDate = DateTime.Now; return(dal.AddOrder(ord.Clone())); }
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; } }