public async Task <IActionResult> Put(int id, [FromBody] UpdateCopyrightMaster copyright) { 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)) })); } CopyrightDataAccess _copyrightAccess = new CopyrightDataAccess(_iconfiguration); DatabaseResponse response = await _copyrightAccess.UpdateCopyright(copyright, id); 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> UpdateCopyright(UpdateCopyrightMaster Copyright, int id) { try { SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int), new SqlParameter("@Title", SqlDbType.NVarChar), new SqlParameter("@Description", SqlDbType.Text), new SqlParameter("@Title_Ar", SqlDbType.NVarChar), new SqlParameter("@Description_Ar", SqlDbType.NVarChar), new SqlParameter("@UpdatedBy", SqlDbType.Int), new SqlParameter("@Active", SqlDbType.Bit), new SqlParameter("@Media", SqlDbType.NVarChar), new SqlParameter("@Protected", SqlDbType.Bit), new SqlParameter("@IsResourceProtect", SqlDbType.Bit), new SqlParameter("@Weight", SqlDbType.Int) }; parameters[0].Value = id; parameters[1].Value = Copyright.Title; parameters[2].Value = Copyright.Description; parameters[3].Value = Copyright.Title_Ar; parameters[4].Value = Copyright.Description_Ar; parameters[5].Value = Copyright.UpdatedBy; parameters[6].Value = Copyright.Active; parameters[7].Value = Copyright.Media; parameters[8].Value = Copyright.Protected; parameters[9].Value = Copyright.IsResourceProtect; parameters[10].Value = Copyright.Weight; _DataHelper = new DataAccessHelper("UpdateCopyright", parameters, _configuration); DataTable dt = new DataTable(); int result = await _DataHelper.RunAsync(dt); List <CopyrightMaster> copyrights = new List <CopyrightMaster>(); if (dt != null && dt.Rows.Count > 0) { copyrights = (from model in dt.AsEnumerable() select new CopyrightMaster() { Id = model.Field <int>("Id"), Title = model.Field <string>("Title"), Description = model.Field <string>("Description"), Title_Ar = model.Field <string>("Title_Ar"), Description_Ar = model.Field <string>("Description_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"), Media = model.Field <string>("Media"), Protected = model.Field <bool>("Protected"), IsResourceProtect = model.Field <bool>("IsResourceProtect"), Weight = model.Field <int>("Weight") }).ToList(); } return(new DatabaseResponse { ResponseCode = result, Results = copyrights }); } catch (Exception ex) { Log.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); throw; } finally { _DataHelper.Dispose(); } }