Example #1
0
 /// <summary>
 ///    将byte[]转换成string(指定Encoding)
 /// </summary>
 /// <param name="bytes">要转换的字节</param>
 /// <param name="encoding">转换的编码,默认为Encoding.Default</param>
 /// <returns>转换后的字符串</returns>
 public static string ToString(this byte[] bytes, Encoding encoding = null)
 {
     if (EnumerableExtension.IsNullOrEmpty(bytes))
     {
         return(null);
     }
     return(encoding != null?encoding.GetString(bytes) : Encoding.Default.GetString(bytes));
 }
Example #2
0
        public async Task <IActionResult> DeleteAsync([FromBody] List <AdminConfigBaseModel> subjectRequestsData)
        {
            this.RecordEvent("Subject - HTTP Delete call to delete subjects.", RequestType.Initiated);
            this.logger.LogInformation("Call to delete subject details.");

            try
            {
                if (EnumerableExtension.IsNullOrEmpty(subjectRequestsData))
                {
                    this.RecordEvent("No subject details data passed in request", RequestType.Failed);
                    this.logger.LogInformation("No subject details data passed in delete request");
                    return(this.BadRequest("Delete request data should not be null"));
                }

                IEnumerable <Subject> subjectCollection = new List <Subject>();
                subjectCollection = subjectRequestsData
                                    .Select(subject => new Subject
                {
                    Id = subject.Id,
                });

                this.unitOfWork.SubjectRepository.DeleteSubjects(subjectCollection);
                await this.unitOfWork.SaveChangesAsync();

                this.RecordEvent("Subject - HTTP Delete call succeeded.", RequestType.Succeeded);

                return(this.Ok(true));
            }
            catch (DbUpdateException ex)
            {
                var errorCode = ((SqlException)ex.InnerException).Number;
                return(this.StatusCode(errorCode));
            }
            catch (Exception ex)
            {
                this.RecordEvent("Subject - HTTP Delete call failed for saving subject data", RequestType.Failed);
                this.logger.LogError(ex, "Error while deleting subject details");
                throw;
            }
        }
        public async Task <IActionResult> DeleteAsync([FromBody] List <AdminConfigBaseModel> gradeRequestsData)
        {
            this.RecordEvent("Grade - HTTP Delete call to delete grades is initiated.", RequestType.Initiated);
            this.logger.LogInformation("Call to delete grade details.");
            try
            {
                if (EnumerableExtension.IsNullOrEmpty(gradeRequestsData))
                {
                    this.RecordEvent("Grade - No grade details data passed in request", RequestType.Failed);
                    this.logger.LogInformation("No grade details data passed in delete request");
                    return(this.BadRequest("Delete request data should not be null"));
                }

                var grades = gradeRequestsData
                             .Select(grade => new Grade
                {
                    Id = grade.Id,
                });

                this.unitOfWork.GradeRepository.DeleteGrades(grades);
                await this.unitOfWork.SaveChangesAsync();

                this.RecordEvent("Grade - HTTP Delete call succeeded.", RequestType.Succeeded);
                return(this.Ok(true));
            }
            catch (DbUpdateException ex)
            {
                var errorCode = ((SqlException)ex.InnerException).Number;
                return(this.StatusCode(errorCode));
            }
            catch (Exception ex)
            {
                this.RecordEvent("Grade - HTTP Delete call failed for grade data", RequestType.Failed);
                this.logger.LogError(ex, "Error while deleting grade details");
                throw;
            }
        }