Example #1
0
        public async Task <IHttpActionResult> post(NotifyAlert <TKey> alert)
        {
            var id = alert.Id;
            //convert alert key to status enum
            CurrentOrderStatus status = (CurrentOrderStatus)Enum.Parse(typeof(CurrentOrderStatus), alert.Key);

            var order = await _service.GetAsync(id);

            if (order == null)
            {
                return(new ContentErrorResult(Request, HttpStatusCode.NotFound, "No order found for the notification request"));
            }
            if (order.OrderStatus.Status == status)
            {
                return(new ContentErrorResult(Request, HttpStatusCode.BadRequest, "Submitted order status is the same as the current status"));
            }
            alert.PhoneNumber = order.BillingAddress.PhoneNumber;
            alert.Email       = order.Email;
            alert.TrackingUrl = order.TrackingUrl;

            var orderAlertTasks = _taskList.Tasks.Where(x => x.TaskType == NotifyTaskType.OrderAlert);

            //run tasks
            orderAlertTasks.ToList().ForEach(x => x.RunAsync(alert));

            //save status, notification to order
            await _service.UpdateStatusAsync(id, status, new OrderNotification
            {
                Key   = alert.Key,
                Value = alert.Value,
                Date  = DateTime.Now
            });

            return(Ok(alert));
        }
Example #2
0
        public bool UpdateStatus(TKey id, CurrentOrderStatus status, OrderNotification notification)
        {
            var order = _repository.Find(x => x.Compare(x.Id, id)).FirstOrDefault();

            if (order == null)
            {
                return(false);
            }
            order.OrderStatus.Status = status;
            order.OrderStatus.Notifications.Add(notification);
            _repository.Update(order);

            return(true);
        }
Example #3
0
 public Task <bool> UpdateStatusAsync(TKey id, CurrentOrderStatus status, OrderNotification notification)
 {
     return(Task.FromResult(UpdateStatus(id, status, notification)));
 }