public async Task <IHttpActionResult> ResetPassword([FromBody] Credential credential) { try { var restclient = new RestClient(_api); var request = new RestRequest("ResetPassword"); request.AddJsonBody(new { userName = credential.UserName }); //request.AddParameter("userName", credential.UserName); var response = await restclient.ExecutePostTaskAsync(request); //if (JsonConvert.DeserializeObject<IDictionary<string, dynamic>>(response.Content).FirstOrDefault().Value) // return NotFound(); var user = Deserialize(response.Content); var password = user["Password"]; string body = "<html>" + "<head></head>" + "<body>Estimado Cliente,<br/>" + $"Su nueva contraseña es : {password} " + "</body>" + "</html>"; SendEmailClient send = new SendEmailClient(); var userNames = new List <string>() { credential.UserName }; send.PostSendEmail(userNames, "Recuperación de Contraseña App Ferreyros", body); return(Ok()); } catch (Exception ex) { Log.Write(ex); return(InternalServerError()); } }
private void SendMail(dynamic assignment, ActivityType?type = null, string userId = null) { #region Workorder var client = new RestClient(_workorderApi); var request = new RestRequest("getorderbyid"); request.AddParameter("Id", assignment.WorkOrderId); var response = client.ExecuteGetTaskAsync(request).GetAwaiter().GetResult(); var workOrder = Deserialize(response.Content); #endregion #region Customer var customer = workOrder.Machinery; #endregion #region Machine var machine = new Machine() { Id = customer.Id, AssignmentId = assignment.Id, Brand = customer.Brand, Model = customer.Model, SerialNumber = customer.SerialNumber, TotalHoursFunction = customer.LifeHours }; #endregion #region Actividades client = new RestClient(_assignmentApi); request = new RestRequest("GetActivityByIdAndUserId"); request.AddParameter("Id", assignment.Id); request.AddParameter("userId", userId); response = client.ExecuteGetTaskAsync(request).GetAwaiter().GetResult(); var activity = JsonConvert.DeserializeObject <IDictionary <string, List <Activity> > >(response.Content) .FirstOrDefault() .Value; #endregion #region ValidateActivity #region New Version var notify = false; int countExists = activity.Where(x => x.ActivityType == ActivityType.FieldReport || x.ActivityType == ActivityType.FieldService || x.ActivityType == ActivityType.StandByClient || x.ActivityType == ActivityType.StandByFesa).Count(); int OnlyTime = 0; if (countExists == 0) { switch (type) { case ActivityType.Traveling: OnlyTime = activity.Where(x => x.ActivityType == type).Count(); break; case ActivityType.Driving: OnlyTime = activity.Where(x => x.ActivityType == type).Count(); break; } if (OnlyTime == 1) { notify = true; } } else { if (type == ActivityType.Traveling || type == ActivityType.Driving) { notify = false; } else { notify = true; } } #endregion #region LastVersion //int travel = 0, driving = 0; //var notify = false; //foreach (var item in activity) { // var a = item.ActivityType.ToString(); // if (item.ActivityType == ActivityType.Traveling) { // travel++; // } // if (item.ActivityType == ActivityType.Driving) { // driving++; // } //} //if (type == ActivityType.Traveling || type == ActivityType.Driving) { // switch (type) { // case ActivityType.Traveling: // if (travel <= 1) { // notify = true; // } // break; // case ActivityType.Driving: // if (driving <= 1) { // notify = true; // } // break; // } //} else { // notify = true; //} #endregion #endregion #region Contact Ferreyros string id = assignment.Id; client = new RestClient(_identityApi); request = new RestRequest("getusersbyidassignment"); request.AddParameter("id", id); response = client.ExecuteGetTaskAsync(request).GetAwaiter().GetResult(); var contactsFerreyros = JsonConvert.DeserializeObject <IDictionary <string, dynamic> >(response.Content) .FirstOrDefault() .Value; dynamic lead = null; dynamic supervisor = null; foreach (var item in contactsFerreyros) { if (item.UserType == 2) { lead = item; } else if (item.UserType == 1) { supervisor = item; } } #endregion #region Correo Destinatario #region PRODUCCION //var userNames = new List<string>(); //foreach (var item in contactsFerreyros) { // if (item.UserType == 1) { // userNames.Add(item.Email.ToString()); // } //} //foreach (var item in workOrder.TechnicalContacts) { // userNames.Add(item.Email.ToString()); //} #endregion #region TEST var userNames = new List <string>(); userNames = new List <string>(); userNames.Add("*****@*****.**"); userNames.Add("*****@*****.**"); #endregion string logo = "http://imgur.com/XAjtjmj.jpg"; #endregion #region Formato Fecha var timezone = TimeZoneInfo.FindSystemTimeZoneById("Hawaiian Standard Time"); var fecha = DateTime.Now.AddHours(5); var now = TimeZoneInfo.ConvertTime(fecha, timezone); #endregion SendEmailClient mail = new SendEmailClient(); if (type == null) { var subject = string.Format(Constants.Mailsubject.FieldReport, workOrder.Code); var body = string.Format(Constants.MailBodies.FieldReport , now , assignment?.Description , machine?.Model , machine?.SerialNumber , ($"{assignment.Location.Department} {assignment.Location.Province} {assignment.Location.District}") , lead?.Name , lead?.Celullar , lead?.Email , supervisor?.Name , supervisor?.Email , logo); if (userId == lead.Id.Value) { mail.PostSendEmail(userNames, subject, body); } return; } if (notify) { switch (type) { case ActivityType.Traveling: var subject1 = string.Format(Constants.Mailsubject.Traveling, workOrder.Code); string assignedTec1 = string.Empty; foreach (var item in contactsFerreyros) { var isSupervisor = item.UserType == 1 ? "( Supervisor )" : ""; assignedTec1 = assignedTec1 + $"<li> {item.Name} {item.LastName} {isSupervisor}</li>"; } var body1 = string.Format(Constants.MailBodies.Traveling , now , ($"{assignment.Location.Department} {assignment.Location.Province} {assignment.Location.District}") , assignment?.Description , machine?.Model , machine?.SerialNumber , assignedTec1 , lead?.Name , lead?.Celullar , lead?.Email , supervisor?.Name , supervisor?.Email , logo); if (userId == lead.Id.Value) { mail.PostSendEmail(userNames, subject1, body1); } break; case ActivityType.Driving: var subject2 = string.Format(Constants.Mailsubject.Driving, workOrder.Code); string assignedTec2 = string.Empty; foreach (var item in contactsFerreyros) { var isSupervisor = item.UserType == 1 ? "( Supervisor )" : ""; assignedTec2 = assignedTec2 + $"<li> {item.Name} {item.LastName} {isSupervisor}</li>"; } var body2 = string.Format(Constants.MailBodies.Driving , now , ($"{assignment.Location.Department} {assignment.Location.Province} {assignment.Location.District}") , assignment?.Description , machine?.Model , machine?.SerialNumber , assignedTec2 , lead?.Name , lead?.Celullar , lead?.Rpm , lead?.Email , supervisor?.Name , supervisor?.Celullar , supervisor?.Email , logo); if (userId == lead.Id.Value) { mail.PostSendEmail(userNames, subject2, body2); } break; case ActivityType.FieldService: var subject3 = string.Format(Constants.Mailsubject.FieldService, workOrder.Code); var body3 = string.Format(Constants.MailBodies.FieldService , now , ($"{assignment.Location.Department} {assignment.Location.Province} {assignment.Location.District}") , assignment?.Description , machine?.Model , machine?.SerialNumber , lead == null ? "" : lead.Name , lead == null ? "" : lead.Celullar , lead == null ? "" : lead.Rpm , lead == null ? "" : lead.Email , supervisor == null ? "" : supervisor.Name , supervisor == null ? "" : supervisor.Celullar , supervisor == null ? "" : supervisor.Email , logo); if (userId == lead.Id.Value) { mail.PostSendEmail(userNames, subject3, body3); } break; case ActivityType.StandByClient: var subject4 = string.Format(Constants.Mailsubject.StandByClient, workOrder.Code); var body4 = string.Format(Constants.MailBodies.StandByClient , now , assignment?.Description , machine?.Model , machine?.SerialNumber , supervisor?.Name , supervisor?.Email , lead?.Name , lead?.Celullar , lead?.Email , logo); if (userId == lead.Id.Value) { mail.PostSendEmail(userNames, subject4, body4); } break; case ActivityType.StandByFesa: var subject5 = string.Format(Constants.Mailsubject.StandByFesa, workOrder.Code); var body5 = string.Format(Constants.MailBodies.StandByFesa , now , assignment?.Description , machine?.Model , machine?.SerialNumber , supervisor?.Name , supervisor?.Celullar , supervisor?.Email , lead?.Name , lead?.Celullar , lead?.Email , logo); if (userId == lead.Id.Value) { mail.PostSendEmail(userNames, subject5, body5); } break; } } }