Пример #1
0
        public IActionResult Calculate(string bandAColor, string bandBColor, string bandCColor, string bandDColor)
        {
            var response     = new Models.AjaxResponse();
            var ohmResultStr = string.Empty;

            if (ModelState.IsValid && bandAColor != null && bandBColor != null && bandCColor != null)
            {
                var calc      = new Models.Calculator();
                var ohmResult = calc.CalculateOhmValue(bandAColor, bandBColor, bandCColor, bandDColor);
                if (ohmResult != -1)
                {
                    ohmResultStr = ohmResult.ToString() + " ohms";
                }
                response.Success      = true;
                response.Data         = ohmResultStr;
                response.ErrorMessage = null;
            }
            else
            {
                response.Success      = false;
                response.Data         = null;
                response.ErrorMessage = (!ModelState.IsValid) ? "Invalid model state" : "Please provide required input colors";
            }
            return(Json(response));
        }
Пример #2
0
        public ActionResult NeedHelp(CustomerViewModel customerVM)
        {
            bool   success = false;
            string message = string.Empty;
            string homeUrl = string.Empty;

            try
            {
                _logMessage.Append("Reached the Need Help section.");
                if (!ModelState.IsValid)
                {
                    message = "Please enter all required data correctly!";
                    _logMessage.Append("All required fields werent provided");
                }
                else
                {
                    Customer customer = new Customer
                    {
                        SelectedIssue    = customerVM.SelectedIssueId == 0 ? "Reset Password" : EnumHelper.GetDescription((AccountIssues)customerVM.SelectedIssueId),
                        Email            = customerVM.Email,
                        FirstName        = customerVM.FirstName,
                        LastName         = customerVM.LastName,
                        Company          = customerVM.Company,
                        PhoneNumber      = customerVM.PhoneNumber,
                        IssueDescription = customerVM.IssueDescription
                    };

                    _logMessage.Append("Sending email with customer request details.");
                    bool wasMailSentSuccessfully = _restClient.PostNeedHelpMessage(customer);

                    if (wasMailSentSuccessfully)
                    {
                        _logMessage.Append("Mail has been sent successfully.");
                        success = true;
                        homeUrl = @Url.Action("Home", "Customer");
                        if (customerVM.SelectedIssueId == 0)
                        {
                            message = "Your message has been sent. Password reset requests will be handled by AHM Support within 24 business hours.";
                        }
                        else
                        {
                            message = "Your message has been sent.";
                        }
                    }
                    else
                    {
                        _logMessage.Append("Email could not be sent. An error occurred in PostNeedHelpMessage method.");
                        success = false;
                        message = "Message couldn't be sent! Please try again!";
                    }
                }
            }
            catch (Exception ex)
            {
                _logMessage.Append("Error occurred requesting help error message is " + ex.Message + ".");
                Elmah.ErrorLog.GetDefault(null).Log(new Elmah.Error(ex));
            }
            _logger.Info(_logMessage.ToString());
            Models.AjaxResponse response = new Models.AjaxResponse();
            response.Success = success;
            response.Message = message;
            response.HomeUrl = homeUrl;
            return(Json(response));
        }