public int AddNewManageAsset(ManageAssetsModels _manageAssetsModels) { int result = 0; if (_manageAssetsModels.Assets_Id > 0) { using (opsdbEntities _dbContext = new opsdbEntities()) { var q = _dbContext.OPS_ManageAssets.FirstOrDefault(x => x.AssetType == _manageAssetsModels.AssetType); if (q == null) { var query = _dbContext.OPS_ManageAssets.Find(_manageAssetsModels.Assets_Id); if (query != null) { query.AssetType = _manageAssetsModels.AssetType; query.ModifiedBy = HttpContext.Current.User.Identity.Name; query.ModifiedDate = DateTime.Now; _dbContext.SaveChanges(); result = 1; } } else { result = -2; } } } else { using (opsdbEntities _dbContext = new opsdbEntities()) { var q = _dbContext.OPS_ManageAssets.FirstOrDefault(x => x.AssetType == _manageAssetsModels.AssetType); if (q == null) { OPS_ManageAssets _obj = new OPS_ManageAssets(); _obj.AssetType = _manageAssetsModels.AssetType; _obj.CreatedBy = HttpContext.Current.User.Identity.Name; _obj.CreatedDate = DateTime.Now; _dbContext.OPS_ManageAssets.Add(_obj); _dbContext.SaveChanges(); result = 1; } else { result = -2; } } } return(result); }
public JsonResult AddNewManageAsset(ManageAssetsModels _manageAssetsModels) { dynamic result; try { result = _IManageDowntime.AddNewManageAsset(_manageAssetsModels); } catch (Exception ex) { Common.LogError(ex); result = -1; } return(Json(result, JsonRequestBehavior.AllowGet)); }