/// <summary> /// Registers the user. /// </summary> /// <param name="user">The user.</param> public void RegisterUser(UserColleague user) { if (Users.ContainsKey(user.Id)) { WriteLine($"User with id - {user.Id} already registered"); } else { Users.Add(user.Id, user); WriteLine($"User with id - {user.Id} has been registered"); } }
/// <summary> /// Creates the activity. /// </summary> /// <param name="id">The identifier.</param> /// <param name="name">The name.</param> /// <param name="user">The user.</param> public void CreateActivity(string id, String name, UserColleague user) { if (!Users.ContainsKey(user.Id)) { throw new ApplicationException("User not yet registred"); } var newActivity = new Activity(id, name, user); Activities.Add(id, newActivity); var usersToBeNotified = Users.Where(uc => !uc.Key.Equals(user.Id)).Select(uc => uc.Value); foreach (var userToBeNotified in usersToBeNotified) { userToBeNotified.NotifyActivity(newActivity); } }
/// <summary> /// Bids the specified activity identifier. /// </summary> /// <param name="activityId">The activity identifier.</param> /// <param name="user">The user.</param> /// <param name="bidValue">The bid value.</param> public void Bid(string activityId, UserColleague user, float bidValue) { Activity activity = null; if (!Activities.TryGetValue(activityId, out activity)) { WriteLine($"Activity with activity id: {activityId} doesn't exist"); } else { if (!activity.Buyers.Any(uc => uc.Id.Equals(user.Id))) { WriteLine($"User with user id: {user.Id} is not a valid buyer for activity with id: {activityId}."); } else { activity.Bids.Add(bidValue, user); activity.Seller.NotifyOnBid(user, activity, bidValue); } } }
/// <summary> /// Registers for bid. /// </summary> /// <param name="activityId">The activity identifier.</param> /// <param name="user">The user.</param> public void RegisterForBid(string activityId, UserColleague user) { Activity activity = null; if (!Activities.TryGetValue(activityId, out activity)) { WriteLine($"Activity with activity id: {activityId} doesn't exist"); } else { if (!activity.Buyers.Any(uc => uc.Id.Equals(user.Id))) { activity.Buyers.Add(user); activity.Seller.NotifyOnNewBuyerRegistration(user, activity); //WriteLine($"User with user id: {user.Id} has been added as buyer for activity with id: {activityId}."); } else { WriteLine($"User with user id: {user.Id} is already buyer for activity with id: {activityId}."); } } }
/// <summary> /// Notifies the on bid. /// </summary> /// <param name="buyer">The buyer.</param> /// <param name="activity">The activity.</param> /// <param name="bidValue">The bid value.</param> public void NotifyOnBid(UserColleague buyer, IActivity activity, float bidValue) { WriteLine($"Seller {Id} has been notified about the bid {bidValue} by buyer {buyer.Id} for activity {activity.ActivityId}."); }
/// <summary> /// Notifies the on new buyer registration. /// </summary> /// <param name="buyer">The buyer.</param> /// <param name="activity">The activity.</param> public void NotifyOnNewBuyerRegistration(UserColleague buyer, IActivity activity) { WriteLine($"Seller {Id} has been notified about the buyer {buyer.Id} for activity {activity.ActivityId}."); }
/// <summary> /// Initializes a new instance of the <see cref="Activity"/> class. /// </summary> /// <param name="id">The identifier.</param> /// <param name="name">The name.</param> /// <remarks>Getter only auto properties (ActivityId, ActivityName, Seller)</remarks> public Activity(string id, String name, UserColleague user) { ActivityId = id; ActivityName = name; Seller = user; }