Exemplo n.º 1
0
        private WebOrderRequestEditViewModel GetData(int id, bool reviewMode)
        {
            ResultContainer              resultContainer   = null;
            WebOrderRequest              webOrderRequest   = null;
            GRINGlobalService            grinGlobalService = new GRINGlobalService(this.AuthenticatedUserSession.Environment);
            WebOrderRequestEditViewModel viewModel         = new WebOrderRequestEditViewModel();

            try
            {
                if (reviewMode)
                {
                    resultContainer = grinGlobalService.SetReviewStatus(id, AuthenticatedUser.Cooperator.WebCooperator.ID, true);
                    resultContainer = grinGlobalService.AddWebOrderRequestAction(new WebOrderRequestAction {
                        WebOrderRequestID = id, ActionCode = "NRR_REVIEW", CreatedByCooperatorID = AuthenticatedUser.WebUserID
                    });
                }

                webOrderRequest = grinGlobalService.GetWebOrderRequest(id);
                if (webOrderRequest == null)
                {
                    throw new NullReferenceException(String.Format("Null web order request returned for ID {0}", id));
                }
                viewModel.AuthenticatedUser = AuthenticatedUser;
                viewModel.WebCooperatorID   = AuthenticatedUser.Cooperator.WebCooperator.ID;
                viewModel.StatusCode        = webOrderRequest.StatusCode;
                viewModel.OrderDate         = webOrderRequest.OrderDate;
                viewModel.WebCooperator     = webOrderRequest.Cooperators.First();
                viewModel.IsReviewMode      = reviewMode;
                viewModel.IsLocked          = webOrderRequest.IsLocked;
                viewModel.ID                       = webOrderRequest.ID;
                viewModel.OrderDate                = webOrderRequest.OrderDate;
                viewModel.IntendedUseCode          = webOrderRequest.IntendedUseCode;
                viewModel.IntendedUseNote          = webOrderRequest.IntendedUseNote;
                viewModel.Note                     = webOrderRequest.Note;
                viewModel.SpecialInstruction       = webOrderRequest.SpecialInstruction;
                viewModel.OwnedDate                = webOrderRequest.OwnedDate;
                viewModel.OwnedByCooperatorID      = webOrderRequest.OwnedByCooperatorID;
                viewModel.OwnedByCooperatorName    = webOrderRequest.OwnedByCooperatorName;
                viewModel.WebOrderRequestItems     = webOrderRequest.WebOrderRequestItems;
                viewModel.WebOrderRequestAddresses = webOrderRequest.Addresses;
                viewModel.EmailAddressList         = webOrderRequest.EmailAddressList;
                viewModel.EmailTemplates           = grinGlobalService.GetEmailTemplates();

                var queryWebOrderRequestDates =
                    from action in webOrderRequest.WebOrderRequestActions
                    group action by action.ActionDate into webOrderRequestActionGroup
                    orderby webOrderRequestActionGroup.Key descending
                    select webOrderRequestActionGroup;

                foreach (var group in queryWebOrderRequestDates)
                {
                    WebOrderRequestActionGroupViewModel webOrderRequestActionGroupViewModel = new WebOrderRequestActionGroupViewModel();
                    webOrderRequestActionGroupViewModel.ActionDate = DateTime.Parse(group.Key.ToString());
                    foreach (var subGroup in group)
                    {
                        WebOrderRequestAction webOrderRequestAction = new WebOrderRequestAction();
                        webOrderRequestAction.ID                      = subGroup.ID;
                        webOrderRequestAction.ActionCode              = subGroup.ActionCode;
                        webOrderRequestAction.Title                   = subGroup.Title;
                        webOrderRequestAction.Description             = subGroup.Description;
                        webOrderRequestAction.Note                    = subGroup.Note;
                        webOrderRequestAction.ActionDate              = subGroup.ActionDateTime;
                        webOrderRequestAction.CreatedByCooperatorName = subGroup.CreatedByCooperatorName;
                        webOrderRequestActionGroupViewModel.WebOrderRequestActions.Add(webOrderRequestAction);
                    }
                    viewModel.WebOrderRequestActionGroupViewModels.Add(webOrderRequestActionGroupViewModel);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, ex.Message);
            }
            return(viewModel);
        }