public async Task <IActionResult> Put(EducationalStandardUpdate educationalStandardUpdate) { 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)) })); } EduStandardDataAccess _EduStandardAccess = new EduStandardDataAccess(_configuration); DatabaseResponse response = await _EduStandardAccess.PutAsync(educationalStandardUpdate); if (response.ResponseCode == (int)DbReturnValue.UpdateSuccess) { return(Ok(new OperationResponse { HasSucceeded = true, IsDomainValidationErrors = false, Message = EnumExtensions.GetDescription(DbReturnValue.UpdateSuccess), ReturnedObject = response.Results })); } else { Log.Error(EnumExtensions.GetDescription(DbReturnValue.UpdationFailed)); return(Ok(new OperationResponse { HasSucceeded = false, IsDomainValidationErrors = false, Message = EnumExtensions.GetDescription(DbReturnValue.NotExists), 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 })); } }
public async Task <DatabaseResponse> PutAsync(EducationalStandardUpdate educationalStandardUpdate) { try { SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int), new SqlParameter("@Standard", SqlDbType.NVarChar), new SqlParameter("@Standard_Ar", SqlDbType.NVarChar), new SqlParameter("@Updatedby", SqlDbType.Int), new SqlParameter("@Active", SqlDbType.Bit), new SqlParameter("@Weight", SqlDbType.Int) }; parameters[0].Value = educationalStandardUpdate.Id; parameters[1].Value = educationalStandardUpdate.Standard; parameters[2].Value = educationalStandardUpdate.Standard_Ar; parameters[3].Value = educationalStandardUpdate.UpdatedBy; parameters[4].Value = educationalStandardUpdate.Active; parameters[5].Value = educationalStandardUpdate.Weight; _DataHelper = new DataAccessHelper("spu_lu_Educational_Standard", parameters, _configuration); DataTable dt = new DataTable(); int result = await _DataHelper.RunAsync(dt); List <EducationalStandardModel> eduStandard = new List <EducationalStandardModel>(); if (dt != null && dt.Rows.Count > 0) { eduStandard = (from model in dt.AsEnumerable() select new EducationalStandardModel() { Id = model.Field <int>("Id"), Standard = model.Field <string>("Standard"), Standard_Ar = model.Field <string>("Standard_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 = eduStandard }); } catch (Exception ex) { Log.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); throw; } finally { _DataHelper.Dispose(); } }