public bool addAddress(GutterCleanOrder entity)
        {
            var customer = _workContext.CurrentCustomer;

               // var zipcodeResult = _zipCodeService.GetZipCodeDetailByZipcode(entity.Zipcode);

            var address = new Address();

            address.Address1 = entity.Address;
            //address.Address2 = entity.Address2;

            //address.Email = model.Email;
            /*
            if (zipcodeResult != null)
            {
                address.City = model.City;
                address.State = model.StateProvinceName;
            }

            address.PhoneNumber = model.PhoneNumber; */
            address.ZipPostalCode = entity.Zipcode;
            address.CreatedOnUtc = entity.CreatedOnUtc;//DateTime.UtcNow;

            customer.Addresses.Add(address);
            _customerService.UpdateCustomer(customer);

            return true;
        }
        public void InsertOrder(GutterCleanOrder entity)
        {
            if (entity == null)
                throw new ArgumentNullException("GutterCleanOrder");

            _gutterCleanOrderRepository.Insert(entity);
        }
        public int SendOrderPlacedWorkCompletedCustomerNotification(GutterCleanOrder order)
        {
            string mailBody = System.IO.File.ReadAllText(_webHelper.MapPath("~/EmailTemplates/OrderPlacedWorkCompletedCustomerNotification.htm"));

            var zipcodedetail = _zipCodeService.GetZipCodeDetailByZipcode(order.Zipcode);
            var r = _questionAnswerEntityDataService.StyleOfGuttersAnswer().Where(i => i.Value == order.QuestionStyleOfGutter).SingleOrDefault();
            var year = _questionAnswerEntityDataService.YearBuiltAnswer().Where(i => i.Value == order.QuestionYearBuilt.ToString()).SingleOrDefault();

            string OrderURLForCustomer = string.Format("{0}order-details/{1}", GetSiteUrl(),
                order.Id);

            mailBody = mailBody.Replace("%Order.OrderURLForCustomer%", OrderURLForCustomer);

            mailBody = mailBody.Replace("%customerfullname%", order.Customer.FirstName + " " + order.Customer.LastName);
            mailBody = mailBody.Replace("%orderid%", order.Id.ToString());
            mailBody = mailBody.Replace("%createddate%", order.CreatedOnUtc.ToString());
            mailBody = mailBody.Replace("%completiondate%", "");
            mailBody = mailBody.Replace("%ordertotal%", string.Format("{0:C}", order.OrderTotal));

            mailBody = mailBody.Replace("%street%", order.Address);
            if (zipcodedetail != null)
                mailBody = mailBody.Replace("%citystate%", zipcodedetail.CityName + ", " + zipcodedetail.StateName);
            else
                mailBody = mailBody.Replace("%citystate%", "");
            mailBody = mailBody.Replace("%zipcode%", order.Zipcode);

            mailBody = mailBody.Replace("%squarefootage%", order.QuestionSquareFootage.ToString());
            mailBody = mailBody.Replace("%styleofgutters%", r.Text);
            mailBody = mailBody.Replace("%yearbuilt%", year.Text);
            mailBody = mailBody.Replace("%roofmaterial%", order.RoofMaterial);

            mailBody = mailBody.Replace("%rateurl%", _siteSetting.SiteUrl + "Survey/"+order.OrderGuid.ToString());

            mailBody = mailBody.Replace("%siteurl%", _siteSetting.SiteUrl);
            mailBody = mailBody.Replace("%customeremail%", order.Customer.Email);

            EmailAccess.SendMail(_siteSetting.SenderEmail, _siteSetting.SenderName, order.Customer.Email, "", _siteSetting.BCCEmail, mailBody, "Eric's Gutter Cleaning Order #: " + order.Id + "| Work Completed");

            return 1;
        }
        public int SendOrderAssigneAgentNotification(GutterCleanOrder order, int AgentId)
        {
            var AgentDetail = _customerService.GetCustomerById(AgentId);

            string mailBody = System.IO.File.ReadAllText(_webHelper.MapPath("~/EmailTemplates/OrderAssigneAgentNotification.htm"));

            string OrderURLForCustomer = string.Format("{0}order-details/{1}", GetSiteUrl(),
                order.Id);

            var zipcodedetail = _zipCodeService.GetZipCodeDetailByZipcode(order.Zipcode);
            var r = _questionAnswerEntityDataService.StyleOfGuttersAnswer().Where(i => i.Value == order.QuestionStyleOfGutter).SingleOrDefault();
            var year = _questionAnswerEntityDataService.YearBuiltAnswer().Where(i => i.Value == order.QuestionYearBuilt.ToString()).SingleOrDefault();

            mailBody = mailBody.Replace("%agentfullname%", AgentDetail.FirstName + " " + AgentDetail.LastName);

            mailBody = mailBody.Replace("%orderid%", order.Id.ToString());
            mailBody = mailBody.Replace("%createddate%", _dateTimeHelper.ConvertToUserTime(order.CreatedOnUtc, DateTimeKind.Utc).ToString());
            mailBody = mailBody.Replace("%completiondate%", "");
            mailBody = mailBody.Replace("%ordertotal%", string.Format("{0:C}", order.OrderTotal));

            mailBody = mailBody.Replace("%street%", order.Address);
            if (zipcodedetail != null)
                mailBody = mailBody.Replace("%citystate%", zipcodedetail.CityName + ", " + zipcodedetail.StateName);
            else
                mailBody = mailBody.Replace("%citystate%", "");
            mailBody = mailBody.Replace("%zipcode%", order.Zipcode);

            mailBody = mailBody.Replace("%squarefootage%", order.QuestionSquareFootage.ToString());
            mailBody = mailBody.Replace("%styleofgutters%", r.Text);
            mailBody = mailBody.Replace("%yearbuilt%", year.Text);
            mailBody = mailBody.Replace("%roofmaterial%", order.RoofMaterial);

            mailBody = mailBody.Replace("%siteurl%", _siteSetting.SiteUrl);

            EmailAccess.SendMail(_siteSetting.SenderEmail, _siteSetting.SenderName, AgentDetail.Email, "*****@*****.**", _siteSetting.BCCEmail, mailBody, "NEW Order #: " + order.Id.ToString());

            return 1;
        }
        public ActionResult ProcessPayment(GutterCleanPaymentRequestModel paymentRequestmodel)
        {
            var customer = _workContext.CurrentCustomer;
            if ((_workContext.CurrentCustomer.IsGuest()))
                return RedirectToRoute("GutterCleanInfoRegister");
            //return new HttpUnauthorizedResult();

            //GutterCleanRequestModel requestModel = _httpContext.Session["GutterCleanRequestModel"] as GutterCleanRequestModel;
            GutterCleanRequestModel model = _httpContext.Session["GutterCleanRequestModel"] as GutterCleanRequestModel;
            if (model == null)
            {
                return RedirectToRoute("GutterCleanRequest");
            }

            ZipCode zipcodeResult;

               // int addAddress_flag = 0;

            if (paymentRequestmodel.SelectedAddressId > 0)
            {
                var selectedAddress = customer.Addresses.Where(a => a.Id == paymentRequestmodel.SelectedAddressId).SingleOrDefault();
                zipcodeResult = _zipCodeService.GetZipCodeDetailByZipcode(selectedAddress.ZipPostalCode);
                if (zipcodeResult != null)
                {
                }
                else
                {
                    ModelState.AddModelError("Zipcode", "Selected Address Zipcode is not valid. Please select Another Addresss Or Enter New Address.");
                }

            }
            else
            {
                zipcodeResult = _zipCodeService.GetZipCodeDetailByZipcode(paymentRequestmodel.Zipcode);
                if (zipcodeResult != null)
                {
                }
                else
                {
                    ModelState.AddModelError("Zipcode", "Zipcode is not valid.");
                }
            }

            if (ModelState.IsValid)
            {
                //GutterCleanRequestModel model = _httpContext.Session["GutterCleanRequestModel"] as GutterCleanRequestModel;
                if (model == null)
                {
                    return RedirectToRoute("GutterCleanRequest");
                }
                paymentRequestmodel.OrderTotal = model.OrderTotal;
                ProcessPaymentRequest processPaymentRequest = new ProcessPaymentRequest();
                processPaymentRequest.OrderTotal = model.OrderTotal;

                processPaymentRequest.CreditCardName = paymentRequestmodel.NameOnCard;
                processPaymentRequest.CreditCardNumber = paymentRequestmodel.CardNumber;
                processPaymentRequest.CreditCardCvv2 = paymentRequestmodel.CardSecurityCode;
                processPaymentRequest.CreditCardExpireMonth = paymentRequestmodel.CardExpiryMonth;
                processPaymentRequest.CreditCardExpireYear = paymentRequestmodel.CardExpiryYear;

                processPaymentRequest.CustomerId = _workContext.CurrentCustomer.Id;
                if (processPaymentRequest.OrderGuid == Guid.Empty)
                    processPaymentRequest.OrderGuid = Guid.NewGuid();

                try
                {
                    ProcessPaymentResult processPaymentResult = null;
                    processPaymentResult = _paymentMethod.ProcessPayment(processPaymentRequest);

                    if (processPaymentResult.Success)
                    {
                        var zipcodeDetail = _zipCodeService.GetZipCodeDetailByZipcode(paymentRequestmodel.Zipcode);

                        GutterCleanOrder entity = new GutterCleanOrder();
                        entity.CustomerId = _workContext.CurrentCustomer.Id;
                        entity.CustomerIp = _webHelper.GetCurrentIpAddress();
                        entity.OrderStatusId = (int)OrderStatus.Processing;
                        entity.PaymentStatusId = (int)PaymentStatus.Paid;
                        entity.CaptureTransactionId = processPaymentResult.CaptureTransactionId;
                        entity.CaptureTransactionResult = processPaymentResult.CaptureTransactionResult;

                        entity.QuestionSquareFootage = model.QuestionSquareFootage;
                        entity.QuestionStyleOfGutter = model.QuestionStyleOfGutter;
                        entity.QuestionYearBuilt = model.QuestionYearBuilt;
                        entity.RoofMaterial = model.RoofMaterial;
                        entity.QuestionDeliveryTime = model.QuestionDeliveryTime;

                        entity.OrderTotal = model.OrderTotal;
                        entity.OrderGuid = processPaymentRequest.OrderGuid;

                        if (paymentRequestmodel.SelectedAddressId > 0)
                        {
                            var selectedAddress = customer.Addresses.Where(a => a.Id == paymentRequestmodel.SelectedAddressId).SingleOrDefault();

                            entity.Address = selectedAddress.Address1;
                            entity.Zipcode = selectedAddress.ZipPostalCode;

                            zipcodeDetail = _zipCodeService.GetZipCodeDetailByZipcode(entity.Zipcode);

                            if (zipcodeDetail != null)
                            {
                                entity.City = zipcodeDetail.CityName; ;
                                entity.State = zipcodeDetail.StateName;
                            }
                        }
                        else
                        {
                            entity.Address = paymentRequestmodel.Address;
                            entity.Zipcode = paymentRequestmodel.Zipcode;

                            if (zipcodeDetail != null)
                            {
                                entity.City = zipcodeDetail.CityName; ;
                                entity.State = zipcodeDetail.StateName;
                            }
                        }

                        entity.AgentId = 0;
                        entity.WorkerId = 0;
                        entity.AgentStatusId = 0;
                        entity.WorkerStatusId = 0;
                        entity.CreatedOnUtc = DateTime.UtcNow;
                        //entity.LastUpdatedDateUtc = DateTime.UtcNow;
                        _orderService.InsertOrder(entity);

                        // add new address if user enter new address which is not in its address list
                        if (paymentRequestmodel.SelectedAddressId <= 0)
                        {
                            addAddress(entity);
                        }

                        _httpContext.Session["GutterCleanRequestModel"] = null;

                        _workflowMessageService.SendOrderPlacedCustomerNotification(entity);
                        _workflowMessageService.SendOrderPlacedSiteOwnerNotification(entity);

                        return RedirectToRoute("Completed", new { orderId = entity.Id });

                    }

                    foreach (var error in processPaymentResult.Errors)
                        paymentRequestmodel.Warnings.Add(error);
                }
                catch (Exception exc)
                {

                    paymentRequestmodel.Warnings.Add(exc.Message);
                }

                // return View(paymentRequestmodel);
            }

            // Model is not valid then redisplay model

            var AddressList = customer.Addresses.ToList();
            string AddressText = string.Empty;
            foreach (var address in AddressList)
            {
                AddressText = string.Empty;
                AddressText = address.Address1 + ", " + address.City + "," + address.State + "," + address.ZipPostalCode;
                paymentRequestmodel.AvailableAddress.Add(new SelectListItem
                {
                    Text = AddressText,
                    Value = address.Id.ToString(),
                });
            }
            paymentRequestmodel.AvailableAddress.Add(new SelectListItem
            {
                Text = "New Address",
                Value = "-1",
            });

            //CC types
            paymentRequestmodel.CreditCardTypes.Add(new SelectListItem
            {
                Text = "Visa",
                Value = "Visa",
            });
            paymentRequestmodel.CreditCardTypes.Add(new SelectListItem
            {
                Text = "Master card",
                Value = "MasterCard",
            });
            paymentRequestmodel.CreditCardTypes.Add(new SelectListItem
            {
                Text = "Discover",
                Value = "Discover",
            });
            paymentRequestmodel.CreditCardTypes.Add(new SelectListItem
            {
                Text = "Amex",
                Value = "Amex",
            });

            //years
            paymentRequestmodel.ExpireYears.Add(new SelectListItem
            {
                Text = "Year",
                Value = "",
            });
            for (int i = 0; i < 25; i++)
            {
                string year = Convert.ToString(DateTime.Now.Year + i);
                paymentRequestmodel.ExpireYears.Add(new SelectListItem
                {
                    Text = year,
                    Value = year,
                });
            }

            //months
            paymentRequestmodel.ExpireMonths.Add(new SelectListItem
            {
                Text = "Month",
                Value = "",
            });
            for (int i = 1; i <= 12; i++)
            {
                string text = (i < 10) ? "0" + i : i.ToString();
                paymentRequestmodel.ExpireMonths.Add(new SelectListItem
                {
                    Text = text,
                    Value = i.ToString(),
                });
            }

            //prepare review Parameter
            paymentRequestmodel.QuestionSquareFootage = model.QuestionSquareFootage;

            var r = _questionAnswerEntityDataService.StyleOfGuttersAnswer().Where(i => i.Value == model.QuestionStyleOfGutter).SingleOrDefault();
            paymentRequestmodel.QuestionStyleOfGutterStr = r.Text;

            var yearRecord = _questionAnswerEntityDataService.YearBuiltAnswer().Where(i => i.Value == model.QuestionYearBuilt.ToString()).SingleOrDefault();
            paymentRequestmodel.QuestionYearBuiltStr = yearRecord.Text;

            paymentRequestmodel.RoofMaterial = model.RoofMaterial;

            paymentRequestmodel.QuestionDeliveryTimeStr = "5 business days";
            if (model.QuestionDeliveryTime == 1)
                paymentRequestmodel.QuestionDeliveryTimeStr = "5 business days";

            if (model.QuestionDeliveryTime == 2)
                paymentRequestmodel.QuestionDeliveryTimeStr = "8 hours";

            if (model.QuestionDeliveryTime == 3)
                paymentRequestmodel.QuestionDeliveryTimeStr = "4 hours";

            //var zipcodeResultCustomer = _zipCodeService.GetZipCodeDetailByZipcode(customer.ZipPostalCode);
            //paymentRequestmodel.Address = customer.Address1;

            //paymentRequestmodel.AddressService = customer.Address1;
            //if (zipcodeResult != null)
            //{
            //    paymentRequestmodel.AddressService = customer.Address1 + ", " + zipcodeResultCustomer.CityName + ", " + zipcodeResultCustomer.StateName;
            //}
            //paymentRequestmodel.zipcodeService = customer.ZipPostalCode;

            paymentRequestmodel.AccetTermandCondition = false;

            return View(paymentRequestmodel);
        }
        public ActionResult ProcessPayment()
        {
            var customer = _workContext.CurrentCustomer;
            if ((_workContext.CurrentCustomer.IsGuest()))
                return RedirectToRoute("GutterCleanInfoRegister");
                //return new HttpUnauthorizedResult();

            GutterCleanRequestModel model = _httpContext.Session["GutterCleanRequestModel"] as GutterCleanRequestModel;
            if (model == null)
            {
                return RedirectToRoute("GutterCleanRequest");

            }

            GutterCleanPaymentRequestModel paymentRequestmodel = new GutterCleanPaymentRequestModel();

            //paymentRequestmodel.Address = customer.Address1;
            //paymentRequestmodel.Zipcode = customer.ZipPostalCode;
            paymentRequestmodel.OrderTotal = model.OrderTotal;

            //            select top (1) *  from GutterCleanOrder where CustomerId='998'
            //order by CreatedOnUtc desc
            var AddressToShow= new GutterCleanOrder();
            string first_add = string.Empty;

            if (customer.GutterCleanOrders.Count > 0)
            {

                AddressToShow = customer.GutterCleanOrders.OrderByDescending(n => n.CreatedOnUtc).First();
                //take(1)

                // var AddressToShow = customer.GutterCleanOrders.ToList();

                String AddressShow = string.Empty;

                //foreach (var address in AddressToShow)
                {
                    AddressShow = string.Empty;
                    AddressShow = AddressToShow.Address + ", " + AddressToShow.City + "," + AddressToShow.State + "," + AddressToShow.Zipcode;
                    paymentRequestmodel.AvailableAddress.Add(new SelectListItem
                    {
                        Text = AddressShow,
                        Value = AddressToShow.Id.ToString(),
                    });
                }

                first_add = "true";

            }
            else
            {
                first_add = "false";
            }

            var AddressList = customer.Addresses.ToList();

            string AddressText = string.Empty;
            foreach (var address in AddressList)
            {
                 AddressText = string.Empty;

                 AddressText = address.Address1 + ", " + address.City + "," + address.State + "," + address.ZipPostalCode;

                 if (address.Address1.Equals(AddressToShow.Address) && (address.ZipPostalCode == AddressToShow.Zipcode) &&  first_add.Equals("true"))
                 {
                     paymentRequestmodel.AvailableAddress[0].Value = address.Id.ToString();
                     first_add = "change"; continue;
                 }
                 paymentRequestmodel.AvailableAddress.Add(new SelectListItem
                     {
                         Text = AddressText,
                         Value = address.Id.ToString(),
                     });
            }

            if (first_add != "change" && first_add.Equals("true"))
            {
                paymentRequestmodel.AvailableAddress.Remove(paymentRequestmodel.AvailableAddress[0]);
            }

            paymentRequestmodel.AvailableAddress.Add(new SelectListItem
            {
                Text = "New Address",
                Value = "-1",
            });

            //CC types
            paymentRequestmodel.CreditCardTypes.Add(new SelectListItem
            {
                Text = "Visa",
                Value = "Visa",
            });
            paymentRequestmodel.CreditCardTypes.Add(new SelectListItem
            {
                Text = "Master card",
                Value = "MasterCard",
            });
            paymentRequestmodel.CreditCardTypes.Add(new SelectListItem
            {
                Text = "Discover",
                Value = "Discover",
            });
            paymentRequestmodel.CreditCardTypes.Add(new SelectListItem
            {
                Text = "Amex",
                Value = "Amex",
            });

            //years
            paymentRequestmodel.ExpireYears.Add(new SelectListItem
            {
                Text = "Year",
                Value = "",
            });
            for (int i = 0; i < 25; i++)
            {
                string year = Convert.ToString(DateTime.Now.Year + i);
                paymentRequestmodel.ExpireYears.Add(new SelectListItem
                {
                    Text = year,
                    Value = year,
                });
            }

            //months
            //months
            paymentRequestmodel.ExpireMonths.Add(new SelectListItem
            {
                Text = "Month",
                Value = "",
            });
            for (int i = 1; i <= 12; i++)
            {
                string text = (i < 10) ? "0" + i : i.ToString();
                paymentRequestmodel.ExpireMonths.Add(new SelectListItem
                {
                    Text = text,
                    Value = i.ToString(),
                });
            }

            //prepare review Parameter
            paymentRequestmodel.QuestionSquareFootage = model.QuestionSquareFootage;

            var r = _questionAnswerEntityDataService.StyleOfGuttersAnswer().Where(i => i.Value == model.QuestionStyleOfGutter).SingleOrDefault();
            paymentRequestmodel.QuestionStyleOfGutterStr = r.Text;

            var yearRecord = _questionAnswerEntityDataService.YearBuiltAnswer().Where(i => i.Value == model.QuestionYearBuilt.ToString()).SingleOrDefault();
            paymentRequestmodel.QuestionYearBuiltStr = yearRecord.Text;

            paymentRequestmodel.RoofMaterial = model.RoofMaterial;

            paymentRequestmodel.QuestionDeliveryTimeStr = "5 business days";
            if (model.QuestionDeliveryTime == 1)
                paymentRequestmodel.QuestionDeliveryTimeStr = "5 business days";

            if (model.QuestionDeliveryTime == 2)
                paymentRequestmodel.QuestionDeliveryTimeStr = "8 hours";

            if (model.QuestionDeliveryTime == 3)
                paymentRequestmodel.QuestionDeliveryTimeStr = "4 hours";

            var zipcodeResult = _zipCodeService.GetZipCodeDetailByZipcode(customer.ZipPostalCode);
            //paymentRequestmodel.Address = customer.Address1;

            paymentRequestmodel.AddressService = customer.Address1;
            if (zipcodeResult != null)
            {
                paymentRequestmodel.AddressService = customer.Address1+", "  + zipcodeResult.CityName+", " + zipcodeResult.StateName  ;
            }
            paymentRequestmodel.zipcodeService = customer.ZipPostalCode;

            return View(paymentRequestmodel);
        }
        protected virtual GutterCleanOrderModel PrepareOrderDetailsModel(GutterCleanOrder order)
        {
            if (order == null)
                throw new ArgumentNullException("order");
            var model = new GutterCleanOrderModel();
            model.Id = order.Id;
            model.OrderGuid =(Guid) order.OrderGuid;
            model.QuestionSquareFootage = order.QuestionSquareFootage;
            model.QuestionStyleOfGutter = order.QuestionStyleOfGutter;
            model.CustomerId = order.CustomerId;
            model.CustomerName = order.Customer.FirstName + " " + order.Customer.LastName;

            var r = _questionAnswerEntityDataService.StyleOfGuttersAnswer().Where(i => i.Value == order.QuestionStyleOfGutter).SingleOrDefault();
            model.QuestionStyleOfGutterStr = r.Text;

            model.QuestionYearBuilt = order.QuestionYearBuilt;

            var year = _questionAnswerEntityDataService.YearBuiltAnswer().Where(i => i.Value == order.QuestionYearBuilt.ToString()).SingleOrDefault();
            model.QuestionYearBuiltStr = year.Text;

            model.RoofMaterial = order.RoofMaterial;

            model.QuestionDeliveryTimeStr = "5 business days";
            if (order.QuestionDeliveryTime == 1)
                model.QuestionDeliveryTimeStr = "5 business days";

            if (order.QuestionDeliveryTime == 2)
                model.QuestionDeliveryTimeStr = "8 hours";

            if (order.QuestionDeliveryTime == 3)
                model.QuestionDeliveryTimeStr = "4 hours";

            model.OrderTotal = order.OrderTotal;

            model.Address = order.Address;

            model.City = order.City;
            model.State = order.State;

            model.Zipcode = order.Zipcode;
            model.AgentId = order.AgentId.HasValue ? (int)order.AgentId.Value : 0;

            model.PaymentStatusId = order.PaymentStatusId;
            model.OrderStatusId = order.OrderStatusId;
            model.CaptureTransactionId = order.CaptureTransactionId;
            model.CaptureTransactionResult = order.CaptureTransactionResult;
            //model.CreatedOnUtc = order.CreatedOnUtc;
            model.CreatedOnUtc = _dateTimeHelper.ConvertToUserTime(order.CreatedOnUtc, DateTimeKind.Utc);
            if (order.CompletionDateUtc.HasValue)
                model.CompletionDateUtc = _dateTimeHelper.ConvertToUserTime(order.CompletionDateUtc.Value, DateTimeKind.Utc);

            // This button only show 'Admin User'
            model.HideSetAgentButton = _workContext.CurrentCustomer.IsAgent();

            // agent Mark Paid Button
            model.HideMarkPaidButton = true;

            model.IsAgentPaid = order.IsPayAgentWorker.HasValue ? order.IsPayAgentWorker.Value : false;

            if (_workContext.CurrentCustomer.IsAdmin())
                model.orderViewByAdmin = true;

            if (order.AgentId <= 0)
                model.HideSetWorkedCompletedButton = true;
            else
            {
                if (((OrderStatus)model.OrderStatusId).ToString() == OrderStatus.Complete.ToString())
                {
                    model.HideSetWorkedCompletedButton = true;
                    model.HideSetAgentButton = true;

                    if (!model.IsAgentPaid && !_workContext.CurrentCustomer.IsAgent())
                    {
                        model.HideMarkPaidButton = false;
                    }
                }
            }

            if (order.IsCustomerQa.HasValue)
            {
                if (order.IsCustomerQa.Value)
                {
                    model.ShowRating = true;

                    var orderSurvey=order.Surveries.FirstOrDefault();
                    if(orderSurvey!=null)
                    {
                        //model.Question1 =Convert.ToString( orderSurvey.Question1);
                        model.Question2 = Convert.ToString(orderSurvey.Question2);
                        model.Question3 = Convert.ToString(orderSurvey.Question3);
                        model.Question4 = Convert.ToString(orderSurvey.Question4);
                    }

                    // Rating detail will not show to agent.
                    if (_workContext.CurrentCustomer.IsAgent())
                    {
                        model.ShowRating = false;
                    }
                }

            }

            return model;
        }
        protected virtual GutterCleanOrderModel PrepareOrderDetailsModel(GutterCleanOrder order)
        {
            if (order == null)
                throw new ArgumentNullException("order");
            var model = new GutterCleanOrderModel();
            model.QuestionSquareFootage = order.QuestionSquareFootage;
            model.QuestionStyleOfGutter = order.QuestionStyleOfGutter;
            model.QuestionDeliveryTime = order.QuestionDeliveryTime;
            var r = _questionAnswerEntityDataService.StyleOfGuttersAnswer().Where(i => i.Value == order.QuestionStyleOfGutter).SingleOrDefault();
            model.QuestionStyleOfGutterStr = r.Text;

            model.QuestionYearBuilt = order.QuestionYearBuilt;

            var year = _questionAnswerEntityDataService.YearBuiltAnswer().Where(i => i.Value == order.QuestionYearBuilt.ToString()).SingleOrDefault();
            model.QuestionYearBuiltStr = year.Text;

            model.RoofMaterial = order.RoofMaterial;

            model.QuestionDeliveryTimeStr = "5 business days";
            if (model.QuestionDeliveryTime == 1)
                model.QuestionDeliveryTimeStr = "5 business days";

            if (model.QuestionDeliveryTime == 2)
                model.QuestionDeliveryTimeStr = "8 hours";

            if (model.QuestionDeliveryTime == 3)
                model.QuestionDeliveryTimeStr = "4 hours";

            model.OrderTotal = order.OrderTotal;

            model.Address = order.Address;

            model.City = order.City;
            model.State = order.State;

            model.Zipcode = order.Zipcode;

            model.PaymentStatusId = order.PaymentStatusId;
            model.OrderStatusId = order.OrderStatusId;
            model.CaptureTransactionId = order.CaptureTransactionId;
            model.CaptureTransactionResult = order.CaptureTransactionResult;
            model.CreatedOnUtc = order.CreatedOnUtc;

            return model;
        }