public ActionResult Insert(Auditory auditory, bool toPlanned, string rules, int applicationUserId) { foreach (var ruleId in rules.Split('|')) { if (!string.IsNullOrEmpty(ruleId)) { auditory.AddRule(Convert.ToInt64(ruleId)); } } var res = auditory.Insert(applicationUserId, auditory.CompanyId); if (res.Success && toPlanned && auditory.Type != 1) { var resPlanned = Auditory.SetQuestionaries(auditory.Id, applicationUserId); if (!resPlanned.Success) { res.SetFail(resPlanned.MessageError); } } return(res); }
public ActionResult Update(Auditory auditory, bool toPlanned, string rules, Auditory oldAuditory, int applicationUserId) { foreach (var ruleId in rules.Split('|')) { if (!string.IsNullOrEmpty(ruleId)) { auditory.AddRule(Convert.ToInt64(ruleId)); } } string differences = auditory.Differences(oldAuditory); var res = auditory.Update(applicationUserId, auditory.CompanyId, differences); // Cuando pasa a planificada hay que generar los cuestionarios y enviar los mails if (res.Success && toPlanned && auditory.Type != 1) { // Generar custionarios var resPlanned = Auditory.SetQuestionaries(auditory.Id, applicationUserId); if (!resPlanned.Success) { res.SetFail(resPlanned.MessageError); } // enviar mails var planning = AuditoryPlanning.ByAuditory(auditory.Id, auditory.CompanyId); if (auditory.Type == 2) { foreach (var pl in planning.Where(p => p.SendMail == true)) { res = SendPanningMail(pl, auditory.Description); } } } if (!res.Success) { return(res); } var setReportStart = false; /*if (auditory.Type == 1 && auditory.ReportStart != null) * { * setReportStart = true; * } * * if(auditory.Status == 1 && auditory.ReportStart != null) * { * setReportStart = true; * }*/ if (setReportStart) { /* CREATE PROCEDURE [dbo].[Auditory_SetReportStart] * @AuditoryId bigint, * @CompanyId int, * @ReportStart datetime */ using (var cmd = new SqlCommand("Auditory_SetReportStart")) { using (var cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["cns"].ConnectionString)) { cmd.Connection = cnn; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(DataParameter.Input("@AuditoryId", auditory.Id)); cmd.Parameters.Add(DataParameter.Input("@CompanyId", auditory.CompanyId)); cmd.Parameters.Add(DataParameter.Input("@ReportStart", auditory.ReportStart)); try { cmd.Connection.Open(); cmd.ExecuteNonQuery(); } finally { if (cmd.Connection.State != ConnectionState.Closed) { cmd.Connection.Close(); } } } } } return(res); }