/// <summary> /// Delete an entity. /// </summary> /// <param name="model"></param> public void Delete(AssetCategoryViewModel model) { var entity = model.ToEntity(); this._AssetCategorysRepository.Delete(entity); #region Commit Changes this._unitOfWork.Commit(); #endregion }
/// <summary> /// Throw an exception if name is exist. /// </summary> /// <param name="model">AssetCategory view model</param> public void ThrowExceptionIfExist(AssetCategoryViewModel model) { ConditionFilter <AssetCategory, long> condition = new ConditionFilter <AssetCategory, long> { Query = (entity => entity.Name == model.Name && entity.Id != model.Id) }; var existEntity = this._AssetCategorysRepository.Get(condition).FirstOrDefault(); if (existEntity != null) { throw new ItemAlreadyExistException(); } }
/// <summary> /// Update an entity. /// </summary> /// <param name="model"></param> /// <returns></returns> public AssetCategoryViewModel Update(AssetCategoryViewModel model) { this.ThrowExceptionIfExist(model); var entity = model.ToEntity(); entity = this._AssetCategorysRepository.Update(entity); #region Commit Changes this._unitOfWork.Commit(); #endregion model = entity.ToModel(); return(model); }
public async Task <IEnumerable <dynamic> > GetAssetCategoryByParams(AssetCategoryViewModel avm) { string sql = "dbo.EAppListAssetCategory"; using (var conn = util.MasterCon()) { try { return(await(conn.QueryAsync <dynamic>(sql, new { avm.LanguageId, avm.Status }, commandType: CommandType.StoredProcedure))); } catch (Exception ex) { throw new CustomException("Unable to Load Data, Please Contact Support!!!", "Error", true, ex); } } }
public async Task <IActionResult> Update([FromBody] AssetCategoryViewModel svm) { try { CurrentUser cUser = new CurrentUser(HttpContext, _configuration); var result = await AssetCategoryRepo.SaveOrUpdate(svm); await auditLogService.LogActivity(cUser.UserId, cUser.HostIP, cUser.SessionId, "AssetCategory", "Asset Category Modified"); return(Ok(result)); } catch (CustomException cex) { var returnObj = new EmaintenanceMessage(cex.Message, cex.Type, cex.IsException, cex.Exception?.ToString()); return(StatusCode(StatusCodes.Status500InternalServerError, returnObj)); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, new EmaintenanceMessage(ex.Message))); } }
public async Task <IEnumerable <dynamic> > SaveOrUpdate([FromBody] AssetCategoryViewModel avm) { string sql = "dbo.EAppSaveAssetCategory"; using (var conn = util.MasterCon()) { try { return(await(conn.QueryAsync <dynamic>(sql, new { avm.AssetCategoryId, avm.LanguageId, avm.AssetCategoryCode, avm.AssetCategoryName, avm.Descriptions, avm.Active, avm.UserId }, commandType: CommandType.StoredProcedure))); } catch (SqlException sqlException) { if (sqlException.Number == 2601 || sqlException.Number == 2627) { throw new CustomException("Duplicate", "Asset Type Code already Exists.", "Error", true, sqlException); } else { throw new CustomException("Due to some Technical Reason, Unable to Save or Update", "Error", true, sqlException); } } catch (Exception ex) { throw new CustomException("Unable to Save Or Update, Please Contact Support!!!", "Error", true, ex); } } }