public FunctionResult_Models GetEntriesCSV(Options_Models Options) { using (var db = new BaseEntities()) { var FunctRes = new FunctionResult_Models(true); var Query = db.Schedules.Where(s => s.AppId == Options.AppId); //Filter Validity var query = Query.AsEnumerable(); var Excludes = ScheduleExclusionFields.ToList(); //Hide these 2 Excludes.Add("SchedulesId"); if (query.Count() == 0) { return(new FunctionResult_Models(false) { message = "No Entries Found!" }); } FunctRes.DataHeaders = ExcludeHeaders(query.FirstOrDefault(), Excludes); FunctRes.DataAsDictionary = query.OrderByDescending(s => s.CreatedOn).ThenByDescending(s => s.AppId).Select(s => ExcludeHeaders(s.GetType().GetProperties().Where(p => p.GetMethod.IsVirtual == false).ToDictionary(prop => prop.Name, prop => prop.GetValue(s, null)), Excludes, true). ToDictionary(prop => prop.Key, prop => prop.Value)).ToList(); return(FunctRes); } }
public FunctionResult_Models GetEntries(Options_Models Options) { using (var db = new BaseEntities()) { var FunctRes = new FunctionResult_Models(true); var Query = db.Schedules.Where(s => s.AppId == Options.AppId); Query = Options.isPast.ToUpper() == "True".ToUpper() ? Query.Where(s => s.EventDate < DateTime.UtcNow): Query.Where(s => s.EventDate >= DateTime.UtcNow); Query = Options.ValidOnly.ToUpper() == "Valid".ToUpper() ? Query.Where(s => (bool)s.IsValid == true) : Options.ValidOnly.ToUpper() == "Invalid".ToUpper() ? Query.Where(s => (bool)s.IsValid == false) : Query; Query = Options.isSent.ToUpper() == "True".ToUpper() ? Query.Where(s => (bool)s.IsSent == true) : Options.isSent.ToUpper() == "False".ToUpper() ? Query.Where(s => (bool)s.IsSent == false) : Query; //Other Filters? var query = Query.OrderByDescending(s => s.AppId).Skip((Options.Page - 1) * Options.PageSize).Take(Options.PageSize).AsEnumerable(); //var SAS = GetSASToken(); var count = query.Count(); FunctRes.TotalCount = Query.Count(); if (count == 0) { return(new FunctionResult_Models(false) { message = "No Entries Found!" }); } FunctRes.DataHeaders = ExcludeHeaders(query.FirstOrDefault(), ScheduleExclusionFields.ToList()); FunctRes.DataAsDictionary = ConvertEntriesToDictionary(query, ScheduleExclusionFields.ToList()); return(FunctRes); } }
//public FunctionResult_Models SubmitSchedule(Parameters_Models param) //{ // using (var db = new BaseEntities()) // { // //try // //{ // var FunctRes = new FunctionResult_Models(true); // FunctRes.IsSendSMS = false; // FunctRes.Schedule.IsValid = true; // var CleanedMessage = CleanMessage(param); // var CreatedOn = param.createdon != null && param.createdon != "" ? DateTime.Parse(param.createdon.ToString()).ToUniversalTime() : System.DateTime.UtcNow;//jfield.ContainsKey("createdOn") ? JsonConvert.DeserializeObject<DateTime>(StandardContest.Models.Helpers.SerializerHelper(jfield["createdOn"].ToString())) : System.DateTime.UtcNow; // //ReturnFail only when message is totally not savable // //Validation before matchfields // var ValidationResult_Modelss = PreMatchFieldValidations(CreatedOn); // if (!ValidationResult_Modelss.IsSuccessful) // { // FunctRes.Schedule.IsValid = false; // FunctRes.IsSendSMS = false; // FunctRes.ListOfReasonsForPossibleFailures.Add(ValidationResult_Modelss.ReasonForFailure); // FunctRes.ListOfResponsesForPossibleFailures.Add(ValidationResult_Modelss.ResponseForFailure); // } // #region SpecificRegexMatching // Regex regex = new Regex(ValidationRegexFull, RegexOptions.IgnoreCase); // var MatchedMessage = regex.Match(CleanedMessage.Trim()); // // Set Fields which dont require validation // FunctRes.Schedule.CreatedOn = CreatedOn; // //FunctRes.Schedule.MobileNo = param.MobileNo; // if (MatchedMessage.Success) // { // //Matched fields will now have a space infront of them because the space is now inside the regex of each field. // var MatchedResultList = MatchedMessage.Groups.Cast<Group>().Select(match => match.Value).Skip(1).ToList().Select(s => s.Trim()).ToList(); // var FieldsL = FieldNames.Split(',').ToList(); // for (int k = 0; k < FieldsL.Count; k++) // { // if (FieldsL[k] == "EventDate") // { // DateTime dt; // DateTime.TryParse(MatchedResultList[k], out dt); // FunctRes.Schedule.EventDate = dt; // } // else // { // //MatchedFields.Add(FieldsL[k], MatchedResultList[k]); // var prop = FunctRes.Schedule.GetType().GetProperty(FieldsL[k]); // prop.SetValue(FunctRes.Schedule, MatchedResultList[k]); // } // } // //Edit Schedule Logics // FunctRes.Schedule = EditSchedule(FunctRes.Schedule); // //Validate LOGIC using MatchedFields // ValidationResult_Modelss = null; // if (!ValidationResult_Modelss.IsSuccessful) // { // FunctRes.Schedule.IsValid = false; // FunctRes.ListOfReasonsForPossibleFailures.Add(ValidationResult_Modelss.ReasonForFailure); // FunctRes.ListOfResponsesForPossibleFailures.Add(ValidationResult_Modelss.ResponseForFailure); // } // FunctRes.IsSavable = true; // } // else // { // //If Invalid, for loop form regex on the fly to determine which field have error(use Key) RegexKeyPairValue, // var FieldsL = FieldNames.Split(',').ToList(); // var BuildingRegex = ""; // for (int k = 0; k < FieldsL.Count; k++) // { // var CurrentFieldRegex = @System.Configuration.ConfigurationManager.AppSettings["ValidationRegex" + FieldsL[k]]; // if (BuildingRegex == "") // { // BuildingRegex = "(" + CurrentFieldRegex.Remove(CurrentFieldRegex.Length - 1).Remove(0, 1) + ")"; // } // else // { // //check if optional field to omit space // //example of UOB regex ^(?: (?i)uob)?$ // if (ValidationRegexOptionalFields.Contains(FieldsL[k]) /*CurrentFieldRegex.StartsWith("^(?:") && CurrentFieldRegex.EndsWith(")?$")*/) // { // //if optional field, then the space is already within the field itself // BuildingRegex = BuildingRegex + "(" + CurrentFieldRegex.Remove(CurrentFieldRegex.Length - 1).Remove(0, 1) + ")"; // } // else // { // BuildingRegex = BuildingRegex + "(" + " " + CurrentFieldRegex.Remove(CurrentFieldRegex.Length - 1).Remove(0, 1) + ")"; // } // } // var TestingRegex = k == FieldsL.Count - 1 ? "^" + BuildingRegex + "$" : "^" + BuildingRegex + "( ?)"; // Regex InvalidedRegex = new Regex(TestingRegex, RegexOptions.IgnoreCase); // var MatchNowOrNot = InvalidedRegex.Match(CleanedMessage.Trim()); // if (!MatchNowOrNot.Success) // { // //Validation has failed at this field, therefore we assume this field to be the one causing the error. // FunctRes.ListOfReasonsForPossibleFailures.Add(FieldsL[k] + " Is Not Valid!"); // } // } // FunctRes.Schedule.IsValid = false; // FunctRes.IsSavable = false; // //FunctRes.ListOfResponsesForPossibleFailures.Add(ErrorMessageGeneric); // } // #endregion // //Validation has completed, if IsValid survives, add it as true // // CompleteReturnObject.Add("SuccessMessage", WarningList.Count > 0 ? "Matching has not been completed succesfully. " : "Matched Successfully. Please Submit."); // //Decide whether to save Schedulefields based on validity // string AppId; // FunctRes.Schedule.Reason = FunctRes.ListOfReasonsForPossibleFailures.Count == 0 ? "" : FunctRes.ListOfReasonsForPossibleFailures[0].ToString(); // //FunctRes.Schedule.Response = FunctRes.ListOfResponsesForPossibleFailures.Count == 0 ? ValidMessage : FunctRes.ListOfResponsesForPossibleFailures[0].ToString(); // FunctRes.Schedule = SaveSchedule(FunctRes.Schedule, FunctRes.IsSavable); // AppId = FunctRes.Schedule.AppId; // FunctRes.message = "Successfully Saved with Schedule ID : " + AppId; // return FunctRes; // //Call Custom Logic Loop of After_Submit // //} // //catch (Exception ex) // //{ // // return new ReturnFail() { message = ex.ToString(), SendSMS = false }; // //} // } //} #endregion //#region Online public FunctionResult_Models InsertSchedule(Schedules Schedule) { try { bool __lockWasTaken = false; //lock object try { Monitor.Enter(Globals.balanceLock, ref __lockWasTaken); //Validation before matchfields var ValidationResult_Modelss = PreMatchFieldValidations(DateTime.Now); if (!ValidationResult_Modelss.IsSuccessful) { return(new FunctionResult_Models(false) { message = ValidationResult_Modelss.ReasonForFailure }); } var FunctRes = new FunctionResult_Models(true); FunctRes.Schedule.IsValid = true; var regex = new Regex(""); var Match = regex.Match(""); regex = new Regex(ValidationRegexMobileNo, RegexOptions.IgnoreCase); Match = regex.Match(Schedule.MobileNo.Trim()); if (string.IsNullOrEmpty(Schedule.AppId)) { FunctRes.Schedule.IsValid = false; FunctRes.ListOfReasonsForPossibleFailures.Add("App Id is Invalid!"); } if (!Match.Success) { FunctRes.Schedule.IsValid = false; FunctRes.ListOfReasonsForPossibleFailures.Add("Mobile is Invalid!"); } if (Schedule.EventDate.Equals(DateTime.MinValue)) { FunctRes.Schedule.IsValid = false; FunctRes.ListOfReasonsForPossibleFailures.Add("Event Date is Invalid!"); } FunctRes.Schedule.Reason = FunctRes.ListOfReasonsForPossibleFailures.Count == 0 ? "" : FunctRes.ListOfReasonsForPossibleFailures[0].ToString(); FunctRes.Schedule.Response = FunctRes.ListOfResponsesForPossibleFailures.Count == 0 ? "" : FunctRes.ListOfResponsesForPossibleFailures[0].ToString(); FunctRes.Schedule.MobileNo = Schedule.MobileNo; FunctRes.Schedule.EventDate = Schedule.EventDate; FunctRes.Schedule.Custom1 = Schedule.Custom1; FunctRes.Schedule.Custom2 = Schedule.Custom2; FunctRes.Schedule.Custom3 = Schedule.Custom3; FunctRes.Schedule.AppId = Schedule.AppId; //Validation Success //Run Additional logics , duplication etc. using (var db = new BaseEntities()) { //Validate LOGIC using MatchedFields //ValidationResult_Models = ValidationLogics(FunctRes.Schedule, "WEB"); //if (!ValidationResult_Modelss.IsSuccessful) //{ // return new FunctionResult_Models(false) { message = ValidationResult_Modelss.ReasonForFailure }; //} //Should make sure Schedule is savable before sending to AZS //string fl; //var fileresult = SendBlobToAzureStorage(Pfile, Schedule.FileName, out fl); //if (!fileresult.Valid) //{ // return fileresult; //} //FunctRes.Schedule.FileLink = fl; //FunctRes.Schedule.Response = ValidMessageOnline; //Save Schedule after passing all checks FunctRes.Schedule = SaveSchedule(FunctRes.Schedule, true); FunctRes.message = ValidMessageOnline.Replace("{mobileNo}", FunctRes.Schedule.MobileNo); // "Successfully saved with ID : " + FunctRes.Schedule.AppId.ToString(); return(FunctRes); } } finally { if (__lockWasTaken) { System.Threading.Monitor.Exit(Globals.balanceLock); } } } catch (Exception ex) { return(new FunctionResult_Models(false) { message = ex.ToString() }); } }