public enumStatus AddOrder(Order order) { string jsonDoc = order.ToString(); try { Orders.Add(order.Id, jsonDoc); if (!OrderTable.ContainsKey(order.UserID)) { List <Order> orders = new List <Order>(); OrderTable[order.UserID] = orders; } OrderTable[order.UserID].Add(order); return(enumStatus.OrderPlaced); } catch (Exception ex) { ServerLog.LogException(ex, string.Format("Add Order: {0}", order.ToString())); return(enumStatus.OrderPlaceError); } //lock (syncRoot) //{ //} }
public enumStatus UpdateOrder(Order order) { string jsonDoc = order.ToString(); try { lock (syncRoot) { if (!Orders.ContainsKey(order.Id)) { ServerLog.LogError("Update Order, invalid Order Id: {0}", order.Id); return(enumStatus.Error); } if (!Users.ContainsKey(order.UserID) || !OrderTable.ContainsKey(order.UserID)) { ServerLog.LogError("Update Order, invalid User Id {0} in the order: {1}", order.UserID, order); return(enumStatus.Error); } int i = OrderTable[order.UserID].Select(a => a.Id).ToList().IndexOf(order.Id); if (i >= 0) { OrderTable[order.UserID][i] = order; } Orders[order.Id] = jsonDoc; } return(enumStatus.Successful); } catch (Exception ex) { ServerLog.LogException(ex, string.Format("Update Order: {0}", order.ToString())); return(enumStatus.Error); } }