async Task <bool> IBaseRepository <T> .DeleteAsync(int id, CancellationToken ct, bool F) { var toRemove = _context.Set <T>().Find(id); ExtractAttributes <T> extract = new ExtractAttributes <T>(); if (F == false && extract.ToString().Contains("ApplicationUser")) { _context.Set <T>().Remove(toRemove); await _context.SaveChangesAsync(ct); return(true); } if (extract.ToString().Contains("ElementDesign") || extract.ToString().Contains("Skin")) { _context.Set <T>().Remove(toRemove); await _context.SaveChangesAsync(ct); return(true); } if (HasSoftDelete()) { PropertyInfo propertyInfoIsDeleted = toRemove.GetType().GetProperty("Active"); PropertyInfo propertyInfoDeletedAt = toRemove.GetType().GetProperty("UpdatedAt"); propertyInfoIsDeleted.SetValue(toRemove, false, null); propertyInfoDeletedAt.SetValue(toRemove, DateTime.Now, null); _context.Set <T>().Update(toRemove); await _context.SaveChangesAsync(ct); return(true); } else { _context.Set <T>().Remove(toRemove); await _context.SaveChangesAsync(ct); return(true); } }
IQueryable <T> IBaseRepository <T> .GetAllAsync(CancellationToken ct) { ExtractAttributes <T> extract = new ExtractAttributes <T>(); bool SiC = false; ICollection <string> ArrAtt = null; extract.ExtAttRelated(ref ArrAtt); if (ArrAtt.Count > 0) { var q = from b in _context.Set <T>() select b; return(IncludeAllContext(q, ct).AsQueryable()); } else { var q = from b in _context.Set <T>() select b; return(q.AsQueryable()); } }
private static IDictionary <string, Repository> EnumerateFiles(DirectoryInfo spotlightDirectory) { Dictionary <string, Repository> list = new Dictionary <string, Repository>(); IList <FileInfo> files = GetFilesRecursive(spotlightDirectory); foreach (FileInfo info in files) { Repository image = ExtractAttributes.ExtractFromFile(info); if (image.IsJpeg) { if (image.HasMinimumDimension(ImageConfiguration.MinimumDimension)) { if (!list.ContainsKey(image.Key)) { list.Add(image.Key, image); } } } } return(list); }
/// <summary> /// Adds a new entity /// </summary> /// <param name="input">A ViewModel instance</param> /// <param name="ct">CancellationToken</param> /// <returns>Returns status 201 or status 500 if exception</returns> public virtual async Task <IActionResult> Post([FromBody] V input, CancellationToken ct = default(CancellationToken)) { if (input == null) { return(BadRequest()); } try { ExtractAttributes <V> extract = new ExtractAttributes <V>(); List <SingleError> LstReg = new List <SingleError>(); if (extract.ErrorCatch(input, ref LstReg) == false) { return(StatusCode(400, new GenericError { Code = "400", Message = "Error de entidad", Errors = LstReg })); } W output = this.ConverterOutput(input); return(StatusCode(201, await _manager.AddAsync(output, ct))); } catch (CodeException ex) { return(StatusCode(500, new GenericError { Code = ex.Code, Message = ex.Message })); } catch (Exception ex) { return(StatusCode(500, new GenericError { Code = "ServerError", Message = ex.Message })); } }
public static IQueryable <T> ApplyFilters <T>(this IQueryable <T> query, IFilter filter) where T : class { var reflectionFilterData = filter.GetType(); var properties = reflectionFilterData.GetProperties(); ExtractAttributes <T> extract = new ExtractAttributes <T>(); foreach (var prop in properties) { var propValue = prop.GetValue(filter); if (propValue == null) { continue; } var methodName = "FilterBy" + prop.Name; MethodInfo methodInfo = reflectionFilterData.GetMethod(methodName); if (methodInfo != null) { object[] parameters = new object[] { query }; query = (System.Linq.IQueryable <T>)methodInfo.Invoke(filter, parameters); } else { if (extract.ToString().Contains("CountryChannelSizeST")) { var ArrDts = properties[4].GetValue(filter); if (ArrDts != null) { var defaultFilter = string.Format("{0} = \"{1}\"", properties[4].Name, properties[4].GetValue(filter)); query = query.Where(defaultFilter); return(query); } } if (extract.ToString().Contains("SuccessPictureST")) { if (prop.Name == "ApplicationUserId") // StatusId { var defaultFilter = string.Format("{0} = \"{1}\"" + " || {2} = \"{3}\"", prop.Name, propValue, "StatusId", "3"); query = query.Where(defaultFilter); } else if (prop.Name == "InitialDate" || prop.Name == "Validity") { DateTime dteGba = Convert.ToDateTime(propValue); string strMes = Convert.ToString(dteGba.Month); string strdia = Convert.ToString(dteGba.Day); char dto = Convert.ToChar("0"); strMes = strMes.PadLeft(2, dto); strdia = strdia.PadLeft(2, dto); if (prop.Name == "InitialDate") { var defaultFilter = string.Format("{0} >= \"{1}\"", prop.Name, dteGba.Year + "-" + strMes + "-" + strdia + " 00:00"); query = query.Where(defaultFilter); } else { var defaultFilter = string.Format("{0} <= \"{1}\"", prop.Name, dteGba.Year + "-" + strMes + "-" + strdia + " 00:00"); query = query.Where(defaultFilter); } } else { if (prop.PropertyType.FullName.Contains("System.DateTime")) { DateTime dteGba = Convert.ToDateTime(propValue); string strMes = Convert.ToString(dteGba.Month); string strdia = Convert.ToString(dteGba.Day); char dto = Convert.ToChar("0"); strMes = strMes.PadLeft(2, dto); strdia = strdia.PadLeft(2, dto); var defaultFilter = string.Format("{0} = \"{1}\"", prop.Name, dteGba.Year + "-" + strMes + "-" + strdia + " 00:00"); query = query.Where(defaultFilter); } else { if (properties[2].Name == prop.Name) { if (properties[2].GetValue(filter) != null) { var defaultFilter1 = string.Format("{0} = \"{1}\"", prop.Name, propValue); query = query.Where(defaultFilter1); } } if (properties[3].Name == prop.Name) { if (properties[3].GetValue(filter) != null) { var defaultFilter1 = string.Format("{0} = \"{1}\"", prop.Name, propValue); query = query.Where(defaultFilter1); } } if (properties[4].Name == prop.Name) { if (properties[4].GetValue(filter) != null) { var defaultFilter1 = string.Format("{0} = \"{1}\"", prop.Name, propValue); query = query.Where(defaultFilter1); } } else { if (prop.Name == "UserName") { } else { var defaultFilter1 = string.Format("{0} = \"{1}\"", prop.Name, propValue); query = query.Where(defaultFilter1); } } } } } else { var defaultFilter = string.Format("{0} = \"{1}\"", prop.Name, propValue); query = query.Where(defaultFilter); } } } if (extract.ToString().Contains("SuccessPictureSTL") || extract.ToString().Contains("SuccessPictureST")) { var ArrDts = properties[11].GetValue(filter); if (ArrDts != null) { var defaultFilter = string.Format("{0} = \"{1}\"" + " || {2} = \"{3}\"", properties[11].Name, properties[11].GetValue(filter), "StatusId", "3"); query = query.Where(defaultFilter); return(query); } } return(query); }