public static bool SaveConfigForDay(int day, int idDay, string date, string state, int[] idDiasConfigurados, string[] names, string[] dataTypes, string[] descriptions) { bool resp = false; try { goliazco_FWEntities entity = new goliazco_FWEntities(); if (idDay > 0) { DAYS dayConfig = (from t in entity.DAYS where t.idDay == idDay select t).FirstOrDefault(); if (dayConfig != null) { string[] formats = { "dd/MM/yyyy" }; dayConfig.completeDay = DateTime.ParseExact(date, formats, new CultureInfo("en-US"), DateTimeStyles.None); dayConfig.state = state; int i = 0; if (dayConfig.DAYS_CONFIG != null && dayConfig.DAYS_CONFIG.Count > 0) { for (i = 0; i < idDiasConfigurados.Length; i++) { DAYS_CONFIG diaYaConfigurado = (from t in dayConfig.DAYS_CONFIG where t.idReportNum == idDiasConfigurados[i] select t).FirstOrDefault(); diaYaConfigurado.name = names[i]; diaYaConfigurado.dataType = dataTypes[i]; diaYaConfigurado.description = descriptions[i]; } } if (names.Length > idDiasConfigurados.Length) { for (int j = i; j < names.Length; j++) { DAYS_CONFIG newConfigForDay = new DAYS_CONFIG(); newConfigForDay.name = names[j]; newConfigForDay.dataType = dataTypes[j]; newConfigForDay.description = descriptions[j]; dayConfig.DAYS_CONFIG.Add(newConfigForDay); } } } entity.SaveChanges(); resp = true; } } catch (Exception ex) { throw new Exception(ex.Message); } return(resp); }
/// <summary> /// Allow to delete an attached exercise to a day /// </summary> /// <param name="idExercise">The specific Id of Exercise</param> /// <returns>true or false that it was deleted</returns> public static bool DeleteExercise(int idExercise) { bool resp = false; try { using (goliazco_FWEntities entity = new goliazco_FWEntities()) { DAYS_CONFIG exercise = (from t in entity.DAYS_CONFIG where t.idReportNum == idExercise select t).FirstOrDefault(); entity.DAYS_CONFIG.Remove(exercise); entity.SaveChanges(); resp = true; } } catch (Exception ex) { throw new Exception(ex.Message); } return(resp); }