Esempio n. 1
0
        public HttpResponseMessage ImportGensetData()
        {
            return(CreateHttpResponse(() =>
            {
                if (HttpContext.Current.Request.Files.AllKeys.Any())
                {
                    string fileSavePath, fileName = "";
                    try
                    {
                        var httpPostedFile = HttpContext.Current.Request.Files["UploadedFile"];

                        var userName = HttpContext.Current.Request.Form["UserName"].ToString();

                        if (httpPostedFile != null)
                        {
                            // Validate the uploaded file(optional)

                            fileName = new FileInfo(httpPostedFile.FileName.Trim(' ')).Name;
                            fileSavePath = Path.Combine(HostingEnvironment.MapPath("~/App_Data"), fileName);

                            httpPostedFile.SaveAs(fileSavePath);

                            var connString = $"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileSavePath + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
                            var command = "SELECT * FROM [Generator$]";
                            var gensetData = GetImportDataRequestDto <ImportGensetDataRequestDto>(fileSavePath, connString, command);

                            // call processor method to process and save ImportGensetRequestDto...
                            return Request.CreateResponse(_adminProcessor.ImportGensetData(gensetData, userName));
                        }
                    }
                    catch (PowerDesignProException ex)
                    {
                        var errorMessage = string.Empty;
                        if (!string.IsNullOrEmpty(ex.ErrorMessage))
                        {
                            errorMessage = ex.ErrorMessage;
                        }

                        else
                        {
                            errorMessage = MessageCollection.Instance.GetMessage(ex.Code, ex.Category);
                        }

                        var messageLength = errorMessage.Length > 255 ? 255 : errorMessage.Length;
                        _traceMessageProcessor.WriteTrace(TraceMessaging.EventSource, TraceLevel.Error, "ImportGensetData", HostingEnvironment.MapPath("~/App_Data") + "---" + ex.TargetSite.Name + "---" + fileName
                                                          , errorMessage.Substring(0, messageLength), ex.StackTrace);

                        throw;
                    }
                    catch (Exception ex)
                    {
                        var messageLength = ex.Message.Length > 255 ? 255 : ex.Message.Length;
                        _traceMessageProcessor.WriteTrace(TraceMessaging.EventSource, TraceLevel.Error, "ImportGensetData", HostingEnvironment.MapPath("~/App_Data") + "---" + ex.TargetSite.Name + "---" + fileName
                                                          , ex.Message.Substring(0, messageLength), ex.StackTrace);
                        throw;
                    }
                }
                return null;
            }));
        }
Esempio n. 2
0
 public HttpResponseMessage GetPDF(ReportModel reportModel)
 {
     return(CreateHttpResponse(() =>
     {
         if (reportModel != null)
         {
             var user = GetUserDetailsByUserName(UserName);
             if (user != null)
             {
                 reportModel.Company = user.CompanyName;
                 reportModel.Email = user.Email;
                 reportModel.UserID = UserID;
                 reportModel.UserName = UserName;
                 reportModel.Phone = user.Phone;
                 reportModel.brand = user.CompanyName;
                 var pdfStream = _pdfProcesor.GeneratePDF(reportModel);
                 if (pdfStream != null)
                 {
                     var memoryStream = new MemoryStream(pdfStream.ToArray());
                     if (memoryStream != null)
                     {
                         HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
                         result.Content = new StreamContent(memoryStream);
                         _pdfProcesor.DeleteImage();
                         return result;
                     }
                     else
                     {
                         _traceMessage.WriteTrace(TraceMessaging.EventSource, TraceLevel.Error, "SolutionID: " + reportModel.SolutionId.ToString(), "GetPDF", "PDF Memory stream null.", "PDF Memory stream null.");
                         //return Request.CreateResponse(HttpStatusCode.NoContent, "PDF not found");
                         return null;
                     }
                 }
                 else
                 {
                     _traceMessage.WriteTrace(TraceMessaging.EventSource, TraceLevel.Error, "SolutionID: " + reportModel.SolutionId.ToString(), "GetPDF", "PDF Memory stream null.", "PDF Memory stream null.");
                     //return Request.CreateResponse(HttpStatusCode.NoContent, "PDF not found");
                     return null;
                 }
             }
             else
             {
                 _traceMessage.WriteTrace(TraceMessaging.EventSource, TraceLevel.Error, "SolutionID: " + reportModel.SolutionId.ToString(), "GetPDF", "User not available.", "User not available.");
                 return null;
             }
         }
         else
         {
             _traceMessage.WriteTrace(TraceMessaging.EventSource, TraceLevel.Error, "SolutionID: " + reportModel.SolutionId.ToString(), "GetPDF", "Report model variable is null.", "Report model variable is null.");
             //return Request.CreateResponse(HttpStatusCode.BadRequest, "Report Parameter is NULL");
             return null;
         }
     }));
 }
Esempio n. 3
0
        public HttpResponseMessage Validate([FromBody] AddressValidationRequestDto request)
        {
            string requestString = "";

            try
            {
                requestString = JsonConvert.SerializeObject(request);
                var requestContentData = new StringContent(requestString, System.Text.Encoding.UTF8, "application/json");
                using (var httpClient = new HttpClient())
                {
                    var response = httpClient.PostAsync(_addressValidationAPIURL, requestContentData).Result;
                    if (!response.IsSuccessStatusCode || response.StatusCode != HttpStatusCode.OK)
                    {
                        var errorResponse = new
                        {
                            ErrorCode        = -1,
                            ErrorDescription = "Address validation call failed for " + requestString + "." + " API URL = " + _addressValidationAPIURL
                        };
                        _traceMessageProcessor.WriteTrace(TraceMessaging.EventSource, TraceLevel.Error, "Address Validation", "Validate", "Address Validation Failed for " + requestString, "");
                        return(Request.CreateResponse(HttpStatusCode.OK, errorResponse));
                    }
                    var successResponse = new
                    {
                        ErrorCode = 0,
                        Message   = "Address validation call succeeded for " + requestString
                    };
                    return(Request.CreateResponse(JsonConvert.DeserializeObject(response.Content.ReadAsStringAsync().Result)));
                }
            }
            catch (Exception ex)
            {
                var errorResponse = new
                {
                    ErrorCode        = -1,
                    ErrorDescription = "Address validation call failed for " + requestString + "." + " API URL = " + _addressValidationAPIURL
                };
                _traceMessageProcessor.WriteTrace(TraceMessaging.EventSource, TraceLevel.Error, "Address Validation", "Validate", "Address Validation Failed for " + requestString, ex.Message);
                return(Request.CreateResponse(HttpStatusCode.OK, errorResponse));
            }
        }
Esempio n. 4
0
        public async Task <HttpResponseMessage> Register(UserRegisterDto model)
        {
            string errorMessage = string.Empty;

            if (model == null || !ModelState.IsValid)
            {
                var errorResponse = new
                {
                    ErrorCode        = -1,
                    ErrorDescription = MessageCollection.Instance.GetMessage("UserRegisteredError", Message.UserAccount)
                };
                return(Request.CreateResponse(HttpStatusCode.OK, errorResponse));
            }

            try
            {
                var user = new ApplicationUser()
                {
                    UserName       = model.UserName,
                    Email          = model.UserName,
                    FirstName      = model.FirstName,
                    LastName       = model.LastName,
                    Phone          = model.Phone,
                    Mobile         = model.Mobile,
                    CompanyName    = model.CompanyName,
                    Address1       = model.Address1,
                    Address2       = model.Address2,
                    City           = model.City,
                    StateID        = model.StateID,
                    ZipCode        = model.ZipCode,
                    CountryID      = model.CountryID,
                    UserCategoryID = model.UserCategoryID,
                    CustomerNumber = model.CustomerNo,
                    //BrandID = model.BrandID,
                    CreatedDateTime   = DateTime.UtcNow,
                    ModifiedDateTime  = DateTime.UtcNow,
                    LastLoginDateTime = null
                };

                IdentityResult result = UserManager.Create(user, model.Password);

                //Comment the code not sure the role need to submit from there or not. Need to make sure.

                //if (AppRoleManager.Roles.Count() == 0)
                //{
                //    AppRoleManager.Create(new IdentityRole { Name = "Admin" });
                //    var adminUser = UserManager.FindByName("*****@*****.**");

                //    UserManager.AddToRoles(adminUser.Id, new string[] { "Admin" });
                //}

                if (!result.Succeeded)
                {
                    if (result.Errors != null)
                    {
                        foreach (string error in result.Errors)
                        {
                            errorMessage += error + " <br /> <hr /> ";
                        }
                    }

                    var errorResponse = new
                    {
                        ErrorCode        = -1,
                        ErrorDescription = errorMessage
                    };
                    return(Request.CreateResponse(HttpStatusCode.OK, errorResponse));
                }


                string callbackURL = await SendEmailConfirmationTokenAsync(user, model.Language);

                var successResponse = new
                {
                    ErrorCode = 0,
                    Message   = MessageCollection.Instance.GetMessage("UserRegisteredSuccess", Message.UserAccount)
                };

                _traceMessageProcessor.WriteTrace(TraceMessaging.EventSource, TraceLevel.Info, "User Registration", "Register", "Registration Success", "Registration Success for " + model.UserName);

                return(Request.CreateResponse(HttpStatusCode.OK, successResponse));
            }

            catch (Exception ex)
            {
                _traceMessageProcessor.WriteTrace(TraceMessaging.EventSource, TraceLevel.Error, "User Registration", "Register", "Registration Failed for " + model.UserName, ex.Message);

                var errorResponse = new
                {
                    ErrorCode        = -1,
                    ErrorDescription = "Exception occured in User registration"
                };
                return(Request.CreateResponse(HttpStatusCode.OK, errorResponse));
            }
        }