Example #1
0
        public ActionResult ForgotPassword(string emailOrName)
        {
            string result = Failed;

            try
            {
                string apiUrl = ConfigurationManager.AppSettings["WebApiUrl"];

                HttpClient client = new HttpClient();

                HttpResponseMessage response = client.GetAsync(apiUrl + "/AdminManagement/GetAdminList").Result;
                if (response.IsSuccessStatusCode)
                {
                    result = response.Content.ReadAsStringAsync().Result;
                    var adminDetails = JsonConvert.DeserializeObject <List <AdminDetails> >(result);
                    if (adminDetails.Count() > 0)
                    {
                        var userDetailsEmail   = adminDetails.FirstOrDefault(x => x.Email.ToUpper().Trim() == emailOrName.Trim().ToUpper() && x.Isdeleted == false);
                        var admuserDetailsName = adminDetails.FirstOrDefault(x => x.UserName.ToUpper().Trim() == emailOrName.Trim().ToUpper() && x.Isdeleted == false);
                        var userDetail         = userDetailsEmail == null ? admuserDetailsName : userDetailsEmail;
                        if (userDetail != null)
                        {
                            const string chars    = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
                            var          password = new string(Enumerable.Repeat(chars, 8)
                                                               .Select(s => s[random.Next(s.Length)]).ToArray());

                            GoogleMail mail = new GoogleMail();
                            mail.Body    = "Hi " + userDetail.Name + ", Your temporary password is - " + password;
                            mail.Subject = "Forgot Password";
                            mail.ToMail  = userDetail.Email;
                            var data = JsonConvert.SerializeObject(mail);
                            response = client.PostAsJsonAsync(apiUrl + "/GoogleMail/SendGoogleMail", mail).Result;
                            result   = response.Content.ReadAsStringAsync().Result;
                            result   = JsonConvert.DeserializeObject <string>(result);
                            if (result == Success)
                            {
                                userDetail.Password = password;
                                response            = client.PostAsJsonAsync(apiUrl + "/AdminManagement/SaveAdminDetails", userDetail).Result;
                                if (response.IsSuccessStatusCode)
                                {
                                    result = response.Content.ReadAsStringAsync().Result;
                                    result = JsonConvert.DeserializeObject <string>(result);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.WriteToLogFile(ex.ToString());
                if (ex.InnerException != null)
                {
                    logger.WriteToLogFile(ex.InnerException.ToString());
                }
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Example #2
0
        public ActionResult PostCreateAssessment(PostAssessmentModal postAssessmentModal)
        {
            string result = "Failed";

            string Result = "Failed";

            try
            {
                string postData = JsonConvert.SerializeObject(postAssessmentModal);
                logger.WriteToLogFile("Post Data " + postData);

                if (postAssessmentModal == null)
                {
                    postAssessmentModal.lstBulkScheduleIds = new List <Guid>();
                }

                string              apiUrl   = System.Configuration.ConfigurationManager.AppSettings["WebApiUrl"];
                HttpClient          client   = new HttpClient();
                HttpResponseMessage response = client.PostAsJsonAsync(apiUrl + "/Assessment/PostCreateAssessment", postAssessmentModal).Result;
                if (response.IsSuccessStatusCode)
                {
                    var    retresult    = response.Content.ReadAsStringAsync().Result;
                    string assessmentID = JsonConvert.DeserializeObject <string>(retresult);
                    if (postAssessmentModal.lstBulkScheduleIds != null)
                    {
                        if (postAssessmentModal.lstBulkScheduleIds.Any())
                        {
                            var userDetailId = postAssessmentModal.lstBulkScheduleIds.FirstOrDefault();

                            HttpClient clientuser = new HttpClient();

                            HttpResponseMessage responsfinal = clientuser.GetAsync(apiUrl + "/Assessment/GetUploadedUserDetail?UserDetailId=" + userDetailId).Result;
                            if (responsfinal.IsSuccessStatusCode)
                            {
                                Result = responsfinal.Content.ReadAsStringAsync().Result;

                                var finalUserdetails = JsonConvert.DeserializeObject <List <UsersDetailsModel> >(Result);

                                foreach (var item in finalUserdetails)
                                {
                                    if (item != null)
                                    {
                                        var        password = item.Password;
                                        GoogleMail mail     = new GoogleMail();
                                        string     url      = ConfigurationManager.AppSettings["ExamPortalUrl"] + assessmentID;
                                        mail.Body    = "Hi " + item.Name + ",UserName -" + item.Email + " Password  - " + item.Password + "<a href=\"" + url + "\">Click Here</a>";
                                        mail.Subject = "Assessment Detail";
                                        mail.ToMail  = item.Email;
                                        logger.WriteToLogFile("PostCreateAssessment Google Mail -" + " Mail Body : " + mail.Body + "Mail To : " + mail.ToMail);
                                        response = client.PostAsJsonAsync(apiUrl + "/GoogleMail/SendGoogleMail", mail).Result;
                                        result   = response.Content.ReadAsStringAsync().Result;
                                        result   = JsonConvert.DeserializeObject <string>(result);
                                    }
                                }
                            }
                        }
                    }
                    else if (postAssessmentModal.SingleScheduleModal != null)
                    {
                        GoogleMail mail = new GoogleMail();
                        string     url  = ConfigurationManager.AppSettings["ExamPortalUrl"] + assessmentID;
                        mail.Body    = "Hi " + postAssessmentModal.SingleScheduleModal.FirstName + ",UserName -" + postAssessmentModal.SingleScheduleModal.UserName + " Password  - " + postAssessmentModal.SingleScheduleModal.Password + "<a href=\"" + url + "\">Click Here</a>";
                        mail.Subject = "Assessment Detail";
                        mail.ToMail  = postAssessmentModal.SingleScheduleModal.Email;
                        logger.WriteToLogFile("PostCreateAssessment Google Mail -" + " Mail Body : " + mail.Body + "Mail To : " + mail.ToMail);
                        //var data = JsonConvert.SerializeObject(mail);
                        response = client.PostAsJsonAsync(apiUrl + "/GoogleMail/SendGoogleMail", mail).Result;
                        result   = response.Content.ReadAsStringAsync().Result;
                        result   = JsonConvert.DeserializeObject <string>(result);
                    }
                    if (assessmentID.ToUpper() != "FAILED")
                    {
                        result = "SUCCESS";
                    }
                }
            }
            catch (Exception ex)
            {
                logger.WriteToLogFile("PostCreateAssessment - " + ex.ToString());
                if (ex.InnerException != null)
                {
                    logger.WriteToLogFile("PostCreateAssessment InnerException - " + ex.ToString());
                }
            }
            return(Json(new { Result = result }));
        }