public IList <CustomFieldDto> GetEditCustomFields(Guid assetId, string company) { IList <CustomFieldDto> cfList = new List <CustomFieldDto>(); var @entity = _assetManager.GetAssetCustomFields(assetId, company).ToList(); if (@entity == null) { throw new UserFriendlyException("No se pudo encontrar el Artículo, fue borrado o no existe."); } int index = 0; foreach (var item in @entity) { CustomFieldDto cfItem = new CustomFieldDto(); cfItem.Id = item.Id; cfItem.Name = item.Name; cfItem.AssetId = item.AssetId; cfItem.SetValue(item.CustomFieldType, item.Value); cfItem.AssetId = item.AssetId; //cfItem.Asset = item.Asset; cfItem.Index = index; cfItem.Update = 1; cfItem.Saved = 1; cfItem.Delete = 0; cfItem.ErrorCode = 0; cfItem.ErrorDescription = ""; cfItem.CompanyName = company; cfList.Add(cfItem); index++; } return(cfList); }
public ActionResult AddAndRenderListCustomFields(IList <string> jsonCustomFieldsList, Guid assetId, string name, object value, int type) { try { IEnumerable <CustomFieldDto> customList = new JavaScriptSerializer().Deserialize <IList <CustomFieldDto> >(jsonCustomFieldsList[0]); if (string.IsNullOrEmpty(name)) { return(Json(new { Error = -1, Message = "Por Favor indique el nombre del campo." })); } object valueParse = ((IEnumerable <string>)value).FirstOrDefault(); if (string.IsNullOrEmpty(Convert.ToString(valueParse))) { return(Json(new { Error = -1, Message = "Por Favor ingrese un valor al campo." })); } CustomFieldDto custom = new CustomFieldDto(); custom.Name = name; custom.SetValue((CustomFieldType)type, valueParse); custom.Saved = 0; custom.Update = 1; custom.Delete = 0; custom.ErrorDescription = ""; custom.ErrorCode = 0; custom.Id = Guid.Empty; IList <CustomFieldDto> newList = new List <CustomFieldDto>(); int index = 0; foreach (var item in customList) { item.Index = index; newList.Add(item); index++; } custom.Index = index; newList.Add(custom); return(PartialView("_customFieldsPartial", newList)); } catch (Exception e) { return(Json(new { Error = -1, Message = "Error al Agregar/Modificar el campo customizable" })); } }