public object InsertAttr([FromBody] AssetAttribute data) { var msg = new JMessage() { Error = false }; try { var query = _context.AssetAttributes.FirstOrDefault(x => x.AttrCode == data.AttrCode); if (query == null) { data.CreatedBy = ESEIM.AppContext.UserName; data.CreatedTime = DateTime.Now; _context.AssetAttributes.Add(data); _context.SaveChanges(); msg.Title = "Thêm thuộc tính thành công!"; } else { msg.Error = true; msg.Title = "Mã thuộc tính đã tồn tại!"; } } catch (Exception ex) { msg.Error = true; msg.Title = "Có lỗi xảy ra khi xóa thuộc tính!"; } return(Json(msg)); }
public object UpdateAttr([FromBody] AssetAttribute data) { var msg = new JMessage() { Error = false }; try { data.UpdatedBy = ESEIM.AppContext.UserName; data.UpdatedTime = DateTime.Now; _context.AssetAttributes.Update(data); _context.SaveChanges(); msg.Title = "Cập nhật thông tin thành công"; return(Json(msg)); } catch (Exception ex) { msg.Error = true; msg.Title = "Có lỗi xảy ra khi xóa!"; msg.Object = ex; throw; } }
public object UpdateAttr([FromBody] AssetAttribute data) { var msg = new JMessage() { Error = false }; try { data.UpdatedBy = ESEIM.AppContext.UserName; data.UpdatedTime = DateTime.Now; _context.AssetAttributes.Update(data); _context.SaveChanges(); msg.Title = String.Format(CommonUtil.ResourceValue("COM_MSG_UPDATE_SUCCESS"), CommonUtil.ResourceValue(""));//"Cập nhật thông tin thành công"; return(Json(msg)); } catch (Exception ex) { msg.Error = true; msg.Title = String.Format(CommonUtil.ResourceValue("COM_MSG_UPDATE_FAILED"), CommonUtil.ResourceValue(""));//"Có lỗi xảy ra khi xóa!"; msg.Object = ex; throw; } }
public void LoadFromXml(XmlAttributeCollection childNodeAttributes) { PropertyInfo[] props = this.GetType().GetAllProperties(); foreach (PropertyInfo propertyInfo in props) { AssetAttribute attr = propertyInfo.GetCustomAttribute <AssetAttribute>(); if (attr != null) { if (childNodeAttributes.GetNamedItem(attr.XMLName)?.Value != null) { string temp = childNodeAttributes.GetNamedItem(attr.XMLName)?.Value; if (temp != null) { DataboundValue temp2 = DataboundAssetExtensions.GetDBValue(temp, propertyInfo.PropertyType.GenericTypeArguments.First()); propertyInfo.SetValue(this, temp2); } } } else { string name = propertyInfo.Name; string temp = childNodeAttributes.GetNamedItem(name)?.Value; if (temp != null) { DataboundValue temp2 = DataboundAssetExtensions.GetDBValue(temp, propertyInfo.PropertyType.GenericTypeArguments.First()); propertyInfo.SetValue(this, temp2); } } } }
public object InsertAttr([FromBody] AssetAttribute data) { var msg = new JMessage() { Error = false }; try { var query = _context.AssetAttributes.FirstOrDefault(x => x.AttrCode == data.AttrCode); if (query == null) { data.CreatedBy = ESEIM.AppContext.UserName; data.CreatedTime = DateTime.Now; _context.AssetAttributes.Add(data); _context.SaveChanges(); msg.Title = String.Format(CommonUtil.ResourceValue("COM_MSG_ADD_SUCCESS"), CommonUtil.ResourceValue("ASSET_CURD_TAB_ATTRIBUTE"));//"Thêm thuộc tính thành công!"; } else { msg.Error = true; msg.Title = String.Format(CommonUtil.ResourceValue("COM_MSG_EXITS"), CommonUtil.ResourceValue("ASSET_CURD_TAB_ATTRIBUTE_CURD_LBL_ATTR_CODE"));//"Mã thuộc tính đã tồn tại!"; } } catch (Exception ex) { msg.Error = true; msg.Title = String.Format(CommonUtil.ResourceValue("COM_MSG_DELETE_FAIL"), CommonUtil.ResourceValue("ASSET_CURD_TAB_ATTRIBUTE"));// "Có lỗi xảy ra khi xóa thuộc tính!"; } return(Json(msg)); }
public async Task <IActionResult> Add(string assetId, [FromBody] AssetAttribute attribute) { attribute = Mapper.Map <AssetAttribute>(await _assetAttributeService.AddAsync(assetId, attribute)); return(Created ( uri: $"api/v2/asset-attributes/{assetId}/{attribute.Key}", value: attribute )); }
public async Task <IAssetAttribute> AddAsync(string assetId, string key, string value) { var attribute = new AssetAttribute { Key = key, Value = value }; return(await AddAsync(assetId, attribute)); }
public static AssetAttribute ToEntity(this AssetAttributeModel model) { var entity = new AssetAttribute() { Id = model.Id, Name = model.Name, Description = model.Description, Sort = model.Sort, DataType = (int)model.DataType }; return(entity); }
public static AssetAttributeModel ToModel(this AssetAttribute entity) { var model = new AssetAttributeModel() { Id = entity.Id, Name = entity.Name, Description = entity.Description, Sort = entity.Sort }; if (entity.DataType.HasValue) { model.DataType = (AssetDataType)entity.DataType; } return(model); }
public static IAssetAttributesKeyValue ToApiModel(this AssetAttribute src) { return(new KeyValue { Key = src.Key, Value = src.Value }); }
public async Task <IActionResult> Update(string assetId, [FromBody] AssetAttribute attribute) { await _assetAttributeService.UpdateAsync(assetId, attribute); return(NoContent()); }
public static DataboundAsset CreateFromXml(XmlAttributeCollection childNodeAttributes, Type type, DataboundAsset parentAsset, BaseScreen baseScreen) { DataboundAsset asset = (DataboundAsset)Activator.CreateInstance(type); var assetType = asset.GetType(); PropertyInfo[] tprops = assetType.GetProperties(); PropertyInfo[] props = tprops.Where(propertyInfo => propertyInfo.GetMethod.ReturnType.AssemblyQualifiedName.Contains("DataboundValue")).ToArray(); List <string> childNodeNames = new List <string>(); foreach (object childNodeAttribute in childNodeAttributes) { childNodeNames.Add(((XmlAttribute)childNodeAttribute).Name); } Dictionary <string, PropertyInfo> prps = new Dictionary <string, PropertyInfo>(); foreach (PropertyInfo propertyInfo in props) { AssetAttribute attr = propertyInfo.GetCustomAttribute <AssetAttribute>(); string name = propertyInfo.Name; if (attr != null) { name = attr.XMLName; } prps.Add(name, propertyInfo); } Breeze.VirtualizedDataContext embeddedDataContext = new VirtualizedDataContext(); foreach (string s in childNodeNames) { if (prps.ContainsKey(s)) { PropertyInfo p = prps[s]; string temp = childNodeAttributes.GetNamedItem(s)?.Value; if (temp != null) { DataboundValue temp3 = (DataboundValue)DataboundAssetExtensions.GetDBerValue(temp, p.PropertyType.GenericTypeArguments.First()); p.SetValue(asset, temp3); } } else { if (s.StartsWith("x_")) { string propName = s.Substring(2); string temp = childNodeAttributes.GetNamedItem(s)?.Value; string propType = temp.Split('|').First(); string value = temp.Split('|').Last(); Type deftype = Type.GetType(propType) ?? Type.GetType("System." + propType); if (temp != null) { DataboundValue temp3 = (DataboundValue)DataboundAssetExtensions.GetDBerValue(value, deftype); embeddedDataContext.Store.Add(propName, value); } } else { throw new Exception("Could not find prop: " + s); } } } if (embeddedDataContext.Store.Count > 0) { asset.VirtualizedDataContext = embeddedDataContext; asset.VirtualizedDataContext.Screen = baseScreen; } return(asset); }
public static void PropertiesAreEqual(this Assert assert, IAssetAttribute expected, AssetAttribute actual) { Assert.AreEqual(expected.Key, actual.Key); Assert.AreEqual(expected.Value, actual.Value); }