public async Task <DatabaseResponse> PostAsync(EducationalUseCreate educationalUseCreate) { try { SqlParameter[] parameters = { new SqlParameter("@EducationalUse", SqlDbType.NVarChar), new SqlParameter("@EducationalUse_Ar", SqlDbType.NVarChar), new SqlParameter("@CreatedBy", SqlDbType.Int), new SqlParameter("@Weight", SqlDbType.Int) }; parameters[0].Value = educationalUseCreate.Name; parameters[1].Value = educationalUseCreate.Name_Ar; parameters[2].Value = educationalUseCreate.CreatedBy; parameters[3].Value = educationalUseCreate.Weight; _DataHelper = new DataAccessHelper("spi_lu_Educational_Use", parameters, _configuration); DataTable dt = new DataTable(); int result = await _DataHelper.RunAsync(dt); List <EducationalUseModel> educationalUseModel = new List <EducationalUseModel>(); if (dt != null && dt.Rows.Count > 0) { educationalUseModel = (from model in dt.AsEnumerable() select new EducationalUseModel() { Id = model.Field <int>("Id"), Name = model.Field <string>("EducationalUse"), Name_Ar = model.Field <string>("EducationalUse_Ar"), CreatedBy = model.Field <string>("CreatedBy"), CreatedOn = model.Field <DateTime>("CreatedOn"), UpdatedOn = model.Field <DateTime>("UpdatedOn"), UpdatedBy = model.Field <string>("UpdatedBy"), Active = model.Field <bool?>("Active"), Weight = model.Field <int>("Weight") }).ToList(); } return(new DatabaseResponse { ResponseCode = result, Results = educationalUseModel }); } catch (Exception ex) { Log.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); throw; } finally { _DataHelper.Dispose(); } }
public async Task <IActionResult> Post(EducationalUseCreate educationalUseCreate) { try { if (!ModelState.IsValid) { return(Ok(new OperationResponse { HasSucceeded = false, IsDomainValidationErrors = true, StatusCode = ((int)ResponseStatus.BadRequest).ToString(), Message = string.Join("; ", ModelState.Values .SelectMany(x => x.Errors) .Select(x => x.ErrorMessage)) })); } EducationalUseDataAccess _EducationalUseAccess = new EducationalUseDataAccess(_iconfiguration); DatabaseResponse response = await _EducationalUseAccess.PostAsync(educationalUseCreate); if (response.ResponseCode == (int)DbReturnValue.CreateSuccess) { return(Ok(new OperationResponse { HasSucceeded = true, IsDomainValidationErrors = false, Message = EnumExtensions.GetDescription(DbReturnValue.CreateSuccess), ReturnedObject = response.Results })); } else { Log.Error(EnumExtensions.GetDescription(DbReturnValue.CreationFailed)); return(Ok(new OperationResponse { HasSucceeded = false, IsDomainValidationErrors = false, Message = EnumExtensions.GetDescription(DbReturnValue.RecordExists), ReturnedObject = response.Results })); } } catch (Exception ex) { Log.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); return(Ok(new OperationResponse { HasSucceeded = false, Message = StatusMessages.ServerError, StatusCode = ((int)ResponseStatus.ServerError).ToString(), IsDomainValidationErrors = false })); } }