Пример #1
0
        public async Task <IHttpActionResult> post(NotifyAlert <TKey> alert)
        {
            var id    = alert.Id;
            var order = await _service.GetAsync(id);

            if (order == null)
            {
                return(new ContentErrorResult(Request, HttpStatusCode.NotFound, "Error: No Order found for the notification request"));
            }
            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 notification to order
            await _service.AddNotificationAsync(id, new OrderNotification
            {
                Key   = alert.Key,
                Value = alert.Value,
                Date  = DateTime.Now
            });

            return(Ok(alert));
        }
Пример #2
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));
        }
Пример #3
0
        public async Task <IHttpActionResult> post(NotifyAlert <TKey> alert)
        {
            var userAlertTasks = _taskList.Tasks.Where(x => x.TaskType == NotifyTaskType.UserAlert);

            if (userAlertTasks.Any())
            {
                foreach (var task in userAlertTasks)
                {
                    await task.RunAsync(alert);
                }
            }
            return(Ok(alert));
        }
Пример #4
0
        protected ActionResult NotificationAction(TKey id, string key, string value, bool authenticated, string name)
        {
            var entity = new NotifyAlert <TKey>
            {
                Id              = id,
                Key             = key,
                Value           = value,
                Date            = DateTime.Now,
                IsAuthenticated = authenticated,
                Name            = name
            };

            var uri     = new UriUtility(Request);
            var message = _alertMessageService.Get(entity, uri);

            return(View(message));
        }
Пример #5
0
        public AlertMessage <TKey> Get(NotifyAlert <TKey> entity, UriUtility uri)
        {
            var host    = uri.Host;
            var logoUrl = Company.LogoUrl;

            if (logoUrl.IndexOf("http") != 0)
            {
                logoUrl = host + logoUrl;
            }
            string trackingLabel = "Sign Up";
            string trackingUrl   = User.SignUpAction;

            if (entity.IsAuthenticated)
            {
                trackingLabel = "Sign In";
                trackingUrl   = User.SignInAction;
            }
            var result = new AlertMessage <TKey>
            {
                Id = entity.Id,
                IsAuthenticated    = entity.IsAuthenticated,
                PhoneNumber        = entity.PhoneNumber,
                Email              = entity.Email,
                Name               = entity.Name,
                Date               = DateTime.Now,
                Day                = DateTime.Now.DayOfWeek.ToString(),
                TrackingUrl        = host + trackingUrl,
                TrackingLabel      = trackingLabel,
                Company            = Company.Name,
                CompanyAddress     = Company.Address,
                CompanyPhone       = Company.Phone,
                CompanyLogoUrl     = logoUrl,
                CssHightlightColor = Html.HighlightColor,
                CssLinkColor       = Html.LinkColor,
                Key                = entity.Key,
                Value              = entity.Value
            };

            return(result);
        }
Пример #6
0
 public Task <AlertMessage <TKey> > GetAsync(NotifyAlert <TKey> entity, UriUtility uri)
 {
     return(Task.FromResult(Get(entity, uri)));
 }