Exemplo n.º 1
0
        //get AssetType and attribute
        public JsonResult Create(string jsonAssetAttribute, string nameAssetType)
        {
            string error = "false";

            if (!nameAssetType.Equals("null"))
            {
                var listAssetAttributes = new List <AssetTypeAttribute>();
                if (!jsonAssetAttribute.Equals("[]"))
                {
                    listAssetAttributes = JsonConvert.DeserializeObject <List <AssetTypeAttribute> >(jsonAssetAttribute);
                }
                string nameType         = nameAssetType.Substring(1, nameAssetType.Length - 2);
                var    listAllAssetType = _assetTypeService.GetAll().Where(x => x.Name.ToLower().Trim().Equals(nameType.Trim().ToLower())).SingleOrDefault();
                if (listAllAssetType != null)
                {
                    error = "Name Asset Type already exists";
                }
                else
                {
                    AssetType assetType = new AssetType()
                    {
                        Name   = nameType,
                        Active = true
                    };
                    bool checkAdd = _assetTypeService.Add(assetType, listAssetAttributes);
                    if (checkAdd)
                    {
                        SetAlert("Add Asset Type success", "success");
                    }
                    else
                    {
                        SetAlert("Add Asset Type error", "error");
                    }
                }
            }
            return(Json(error));
        }