public RedeemResponse Redeem(string orderNumber, string email) { OrderDB db = new OrderDB(); Order2 order = db.GetOrder(orderNumber); if (order == null) { return(new RedeemResponse { Message = "", Success = false }); } else if (String.IsNullOrWhiteSpace(email) || !Regex.IsMatch(email, "[a-zA-Z0-9]*@[a-zA-Z0-9]*\\.{1}[a-zA-Z]{1,}")) { return(new RedeemResponse { Success = false, Message = "Email required to redeem password." }); } else if (order.EMail != null && !order.EMail.Equals(email)) { return(new RedeemResponse { Success = false, Message = "An email has already been set." }); } order.EMail = email; if (order.PasswordClaimed == null) { order.PasswordClaimed = DateTime.Now; db.SaveOrder(order); } RedeemResponse resp = new RedeemResponse(); resp.OrderInfoText = "Addr: " + order.Address + "\n" + "Mail: " + order.EMail + "\n" + "Name: " + order.Name + "\n" + "Password: "******"\n" + (order.PasswordClaimed != null ? "REDEEMED" : ""); resp.Success = true; resp.Message = ""; return(resp); }
public string SearchOrder(string orderNumber) { if (orderNumber == null || orderNumber.Length != 8) { return("Type an order number above..."); } OrderDB db = new OrderDB(); Order2 order = db.GetOrder(orderNumber); if (order == null) { return("Type an order number above..."); } db.CleanRedeemedPasswords(); return("Addr: " + order.Address + "\n" + "Mail: " + order.EMail + "\n" + "Name: " + order.Name + "\n" + "Password: "******"\n" + (order.PasswordClaimed != null ? "REDEEMED" : "")); }
/*Denne metode tager et int kaldet ID in som parameter, kalderen metode i database lageret*/ public Order GetOrder(int ID) { return(oDb.GetOrder(ID)); }
public Order GetOrder(int id) { return(OrderDB.GetOrder(id)); }
/*Denne metode ændre total prise på order og en specifik orderline*/ public void EditOrderLinePrice(int id, int orderID, string text) { decimal price = 0; int amount = 0; //OrderLine orderline = null; OrderDB oDB = new OrderDB(); foreach (var o in oDB.GetOrder(orderID).OrderLines) { /*Her tjekkes der om hvilken type drink der er på orderlinen, da den skal kalde forskellige metoder * som kalder en forskellige del i databasen*/ if (o.ID == id && o.Drink.GetType() == typeof(HelFlask)) { /*Først tager vi den orderline total pris fra order total pris*/ price = oDB.GetOrder(orderID).TotalPrice - o.TotalPrice; oDB.updateTotalPrice(oDB.GetOrder(orderID), price); amount = Convert.ToInt32(text); /*Herefter ændres total prisen og amount på orderlinen til det nye, som kan være både højere * eller mindre end hvad den var før*/ o.TotalPrice = amount * o.Drink.Price; o.Amount = amount; olDb.EditOrderLineHelflask(o); /*Nu ændres price til den nye prid der skal tilføres på order's total pris*/ price = oDB.GetOrder(orderID).TotalPrice + o.TotalPrice; oDB.updateTotalPrice(oDB.GetOrder(orderID), price); } else if (o.ID == id && o.Drink.GetType() == typeof(Drink)) { price = oDB.GetOrder(orderID).TotalPrice - olDb.GetOrderLine(id).TotalPrice; oDB.updateTotalPrice(oDB.GetOrder(orderID), price); amount = Convert.ToInt32(text); //orderline = olDb.GetOrderLine(id); o.TotalPrice = amount * o.Drink.Price; o.Amount = amount; olDb.EditOrderLine(o); price = oDB.GetOrder(orderID).TotalPrice + olDb.GetOrderLine(id).TotalPrice; oDB.updateTotalPrice(oDB.GetOrder(orderID), price); } else if (o.ID == id && o.Drink.GetType() == typeof(Alchohol)) { price = oDB.GetOrder(orderID).TotalPrice - olDb.GetOrderLineAlchohol(id).TotalPrice; oDB.updateTotalPrice(oDB.GetOrder(orderID), price); amount = Convert.ToInt32(text); //orderline = olDb.GetOrderLine(id); o.TotalPrice = amount * o.Drink.Price; o.Amount = amount; olDb.EditOrderAlchohol(o); price = oDB.GetOrder(orderID).TotalPrice + olDb.GetOrderLineAlchohol(id).TotalPrice; oDB.updateTotalPrice(oDB.GetOrder(orderID), price); } } }