Beispiel #1
0
        public async Task <ActionResult> OverrideOrder(int id)
        {
            var order = await _dbContext.Orders.Include(i => i.Creator).SingleOrDefaultAsync(o => o.Id == id);

            if (order == null)
            {
                return(NotFound());
            }

            var model = new OverrideOrderModel
            {
                OrderReviewModel =
                {
                    Order          = order,
                    OrderDetails   = order.GetOrderDetails(),
                    HideLabDetails = false
                },
                IsDeleted = order.IsDeleted,
                Paid      = order.Paid,
                Status    = order.Status,
                Emails    = order.AdditionalEmails
            };

            return(View(model));
        }
Beispiel #2
0
        public async Task <ActionResult> OverrideOrder(int id)
        {
            var order = await _dbContext.Orders.Include(i => i.Creator).SingleOrDefaultAsync(o => o.Id == id);

            if (order == null)
            {
                return(NotFound());
            }

            var model = new OverrideOrderModel
            {
                OrderReviewModel =
                {
                    Order          = order,
                    OrderDetails   = order.GetOrderDetails(),
                    HideLabDetails = false
                },
                IsDeleted = order.IsDeleted,
                Paid      = order.Paid,
                Status    = order.Status,
                Emails    = order.AdditionalEmails
            };

            if (order.PaymentType == PaymentTypeCodes.UcDavisAccount ||
                order.PaymentType == PaymentTypeCodes.UcOtherAccount)
            {
                model.Account = model.OrderReviewModel.OrderDetails.Payment.Account;
            }

            await GetHistories(id, model.OrderReviewModel);

            return(View(model));
        }
Beispiel #3
0
        public async Task <ActionResult> OverrideOrder(int id, OverrideOrderModel model)
        {
            var orderToUpdate = await _dbContext.Orders.Include(i => i.Creator).SingleOrDefaultAsync(o => o.Id == id);

            if (orderToUpdate == null)
            {
                return(NotFound());
            }

            if (orderToUpdate.Status != model.Status)
            {
                if (!OrderStatusCodes.All.Contains(model.Status))
                {
                    ErrorMessage = $"Unexpected Status Value: {model.Status}";
                    return(RedirectToAction("OverrideOrder", new { id }));
                }
            }

            //TODO: Parse emails to validate
            if (orderToUpdate.AdditionalEmails != model.Emails)
            {
                if (string.IsNullOrWhiteSpace(model.Emails))
                {
                    orderToUpdate.AdditionalEmails = string.Empty;
                }
                else
                {
                    var filteredEmailList = new List <string>();
                    var emailList         = model.Emails.Split(';', StringSplitOptions.RemoveEmptyEntries);
                    foreach (var em in emailList)
                    {
                        var em1 = em.ToLower().Trim();
                        if (em1.IsEmailValid())
                        {
                            if (!filteredEmailList.Contains(em1))
                            {
                                filteredEmailList.Add(em1);
                            }
                        }
                        else
                        {
                            ErrorMessage = $"Invalid email detected: {em1}";
                            return(RedirectToAction("OverrideOrder", new { id }));
                        }
                    }

                    orderToUpdate.AdditionalEmails = string.Join(';', filteredEmailList);
                }
            }

            orderToUpdate.Paid      = model.Paid;
            orderToUpdate.Status    = model.Status;
            orderToUpdate.IsDeleted = model.IsDeleted;
            if (model.UploadFile != null && model.UploadFile.Length >= 0)
            {
                Log.Information($"Old Results File Identifier {orderToUpdate.ResultsFileIdentifier}");
                orderToUpdate.ResultsFileIdentifier = await _fileStorageService.UploadFile(model.UploadFile);

                Log.Information($"New Results File Identifier {orderToUpdate.ResultsFileIdentifier}");
            }

            await _dbContext.SaveChangesAsync();

            if (model.IsDeleted)
            {
                ErrorMessage = "Order deleted!!!";
                return(RedirectToAction("Orders"));
            }
            Message = "Order Updated";
            if (model.Status == OrderStatusCodes.Created)
            {
                return(RedirectToAction("Index", "Home"));
            }

            return(RedirectToAction("Details", new{ id }));
        }
Beispiel #4
0
        public async Task <ActionResult> OverrideOrder(int id, OverrideOrderModel model)
        {
            var historyNote = string.Empty;

            var orderToUpdate = await _dbContext.Orders.Include(i => i.Creator).SingleOrDefaultAsync(o => o.Id == id);

            if (orderToUpdate == null)
            {
                return(NotFound());
            }

            if (orderToUpdate.Status != model.Status)
            {
                if (!OrderStatusCodes.All.Contains(model.Status))
                {
                    ErrorMessage = $"Unexpected Status Value: {model.Status}";
                    return(RedirectToAction("OverrideOrder", new { id }));
                }
            }

            if (orderToUpdate.PaymentType == PaymentTypeCodes.UcDavisAccount ||
                orderToUpdate.PaymentType == PaymentTypeCodes.UcOtherAccount)
            {
                var orderDetails = orderToUpdate.GetOrderDetails();
                model.Account = model.Account.SafeToUpper();
                if (orderDetails.Payment.Account != model.Account)
                {
                    model.OrderReviewModel = new OrderReviewModel
                    {
                        Order          = orderToUpdate,
                        OrderDetails   = orderDetails,
                        HideLabDetails = false
                    };
                    if (string.IsNullOrWhiteSpace(model.Account))
                    {
                        model.Account = model.OrderReviewModel.OrderDetails.Payment.Account;
                        ModelState.AddModelError("Account", "Account is required");
                    }

                    if (orderToUpdate.PaymentType == PaymentTypeCodes.UcDavisAccount)
                    {
                        try
                        {
                            orderDetails.Payment.AccountName = await _financialService.GetAccountName(model.Account);
                        }
                        catch
                        {
                            orderDetails.Payment.AccountName = string.Empty;
                        }

                        //order.SaveDetails(orderDetails);
                        if (string.IsNullOrWhiteSpace(orderDetails.Payment.AccountName))
                        {
                            ModelState.AddModelError("Account", "Unable to verify UC Account number.");
                        }
                    }
                    if (!ModelState.IsValid)
                    {
                        await GetHistories(id, model.OrderReviewModel);

                        ErrorMessage = "Errors Detected. Override failed";
                        return(View(model));
                    }
                    historyNote = $"Account Changed Old: {orderDetails.Payment.Account} New: {model.Account}.";

                    orderDetails.Payment.Account = model.Account;
                    orderToUpdate.SaveDetails(orderDetails);
                }
            }

            //TODO: Parse emails to validate
            if (orderToUpdate.AdditionalEmails != model.Emails)
            {
                if (string.IsNullOrWhiteSpace(model.Emails))
                {
                    orderToUpdate.AdditionalEmails = string.Empty;
                }
                else
                {
                    var filteredEmailList = new List <string>();
                    var emailList         = model.Emails.Split(';', StringSplitOptions.RemoveEmptyEntries);
                    foreach (var em in emailList)
                    {
                        var em1 = em.ToLower().Trim();
                        if (em1.IsEmailValid())
                        {
                            if (!filteredEmailList.Contains(em1))
                            {
                                filteredEmailList.Add(em1);
                            }
                        }
                        else
                        {
                            ErrorMessage = $"Invalid email detected: {em1}";
                            return(RedirectToAction("OverrideOrder", new { id }));
                        }
                    }

                    historyNote = $"Additional emails changed. Old: {orderToUpdate.AdditionalEmails} New: {model.Emails}. {historyNote}";

                    orderToUpdate.AdditionalEmails = string.Join(';', filteredEmailList);
                }
            }

            if (orderToUpdate.Paid != model.Paid)
            {
                historyNote = $"Paid value changed. New: {model.Paid.ToYesNoString()}. {historyNote}";
            }
            if (orderToUpdate.Status != model.Status)
            {
                historyNote = $"Status value changed. Old: {orderToUpdate.Status}. {historyNote}";
            }
            if (model.IsDeleted)
            {
                historyNote = $"Marked as Deleted. {historyNote}";
            }

            if (model.UploadFile != null && model.UploadFile.Length >= 0)
            {
                historyNote = $"New File Uploaded. {historyNote}";
            }

            orderToUpdate.Paid      = model.Paid;
            orderToUpdate.Status    = model.Status;
            orderToUpdate.IsDeleted = model.IsDeleted;
            if (model.UploadFile != null && model.UploadFile.Length >= 0)
            {
                Log.Information($"Old Results File Identifier {orderToUpdate.ResultsFileIdentifier}");
                orderToUpdate.ResultsFileIdentifier = await _fileStorageService.UploadFile(model.UploadFile);

                Log.Information($"New Results File Identifier {orderToUpdate.ResultsFileIdentifier}");
            }

            var user = _dbContext.Users.Single(a => a.Id == CurrentUserId);

            orderToUpdate.History.Add(new History
            {
                Action      = "Admin Override",
                Status      = orderToUpdate.Status,
                ActorId     = user.NormalizedUserName,
                ActorName   = user.Name,
                JsonDetails = orderToUpdate.JsonDetails,
                Notes       = historyNote,
            });

            if ((orderToUpdate.PaymentType == PaymentTypeCodes.UcOtherAccount || orderToUpdate.PaymentType == PaymentTypeCodes.Other) &&
                (model.IsDeleted || orderToUpdate.Status == OrderStatusCodes.Created))
            {
                await _orderMessageService.EnqueueBillingOverride(orderToUpdate);
            }

            await _dbContext.SaveChangesAsync();

            if (model.IsDeleted)
            {
                ErrorMessage = "Order deleted!!!";
                return(RedirectToAction("Orders"));
            }
            Message = "Order Updated";
            if (model.Status == OrderStatusCodes.Created)
            {
                return(RedirectToAction("Confirmation", "Order", new { id }));
            }

            return(RedirectToAction("Details", new{ id }));
        }