예제 #1
0
 public async Task <BaseResponse> Save([FromBody] SaveEntityRequest saveUserRequest)
 => await this.clientFactory.PostAsync <BaseResponse>
 (
     "api/User/Save",
     JsonSerializer.Serialize(saveUserRequest),
     this.configurationOptions.BaseBslUrl
 );
예제 #2
0
 public Task <BaseResponse> Save([FromBody] SaveEntityRequest saveDepartmentRequest)
 => this.clientFactory.PostAsync <BaseResponse>
 (
     "api/Department/Save",
     JsonSerializer.Serialize(saveDepartmentRequest),
     this.configurationOptions.BaseBslUrl
 );
 public Task <BaseResponse> SaveWithoutRules([FromBody] SaveEntityRequest saveStudentRequest)
 => this.clientFactory.PostAsync <BaseResponse>
 (
     "api/Student/SaveWithoutRules",
     JsonSerializer.Serialize(saveStudentRequest),
     this.configurationOptions.BaseBslUrl
 );
예제 #4
0
        public IActionResult SaveWithoutRules([FromBody] SaveEntityRequest saveStudentRequest)
        {
            System.Diagnostics.Stopwatch stopWatch = System.Diagnostics.Stopwatch.StartNew();
            var response = SaveStudentWithoutRules(saveStudentRequest);

            stopWatch.Stop();
            logger.LogWarning("this.SaveStudentWithoutRules: {0}", stopWatch.Elapsed.TotalMilliseconds);
            return(Ok(response));
        }
예제 #5
0
 public Task <BaseResponse> SaveEntity(SaveEntityRequest request, string url)
 => PollyHelpers.ExecutePolicyAsync
 (
     () => this.factory.PostAsync <BaseResponse>
     (
         url,
         JsonSerializer.Serialize(request),
         App.BASE_URL
     )
 );
 public IActionResult Save([FromBody] SaveEntityRequest saveUserRequest)
 {
     this.flowManager.FlowDataCache.Request = saveUserRequest;
     this.flowManager.Start("saveuser");
     return(Ok(this.flowManager.FlowDataCache.Response));
 }
예제 #7
0
        public void SaveStudentRequestWithEnrollmentsWithoutRules2()
        {
            IFlowManager      flowManager      = serviceProvider.GetRequiredService <IFlowManager>();
            ISchoolRepository schoolRepository = serviceProvider.GetRequiredService <ISchoolRepository>();
            var student = flowManager.SchoolRepository.GetAsync <StudentModel, Student>
                          (
                s => s.FullName == "Carson Alexander",
                selectExpandDefinition: new LogicBuilder.Expressions.Utils.Expansions.SelectExpandDefinition
            {
                ExpandedItems = new List <LogicBuilder.Expressions.Utils.Expansions.SelectExpandItem>
                {
                    new LogicBuilder.Expressions.Utils.Expansions.SelectExpandItem {
                        MemberName = "enrollments"
                    }
                }
            }
                          ).Result.Single();

            student.FirstName   = "First";
            student.EntityState = LogicBuilder.Domain.EntityStateType.Modified;
            student.Enrollments.ToList().ForEach(enrollment =>
            {
                enrollment.Grade       = Domain.Entities.Grade.A;
                enrollment.EntityState = LogicBuilder.Domain.EntityStateType.Modified;
            });
            SaveEntityRequest saveStudentRequest = new SaveEntityRequest {
                Entity = student
            };

            System.Diagnostics.Stopwatch stopWatch = System.Diagnostics.Stopwatch.StartNew();
            StudentModel       studentModel        = (StudentModel)saveStudentRequest.Entity;
            SaveEntityResponse saveStudentResponse = new SaveEntityResponse();

            saveStudentResponse.Success = schoolRepository.SaveGraphAsync <StudentModel, Student>(studentModel).Result;

            if (!saveStudentResponse.Success)
            {
                return;
            }

            studentModel = schoolRepository.GetAsync <StudentModel, Student>
                           (
                f => f.ID == studentModel.ID,
                null,
                new LogicBuilder.Expressions.Utils.Expansions.SelectExpandDefinition
            {
                ExpandedItems = new List <LogicBuilder.Expressions.Utils.Expansions.SelectExpandItem>
                {
                    new LogicBuilder.Expressions.Utils.Expansions.SelectExpandItem {
                        MemberName = "enrollments"
                    }
                }
            }
                           ).Result.SingleOrDefault();

            saveStudentResponse.Entity = studentModel;

            int Iteration_Index = 0;

            flowManager.CustomActions.WriteToLog
            (
                string.Format
                (
                    "EnrollmentCount: {0}. Index: {1}",
                    new object[]
            {
                studentModel.Enrollments.Count,
                Iteration_Index
            }
                )
            );

            EnrollmentModel enrollmentModel = null;

            while (Iteration_Index < studentModel.Enrollments.Count)
            {
                enrollmentModel = studentModel.Enrollments.ElementAt(Iteration_Index);
                Iteration_Index = Iteration_Index + 1;
                flowManager.CustomActions.WriteToLog
                (
                    string.Format
                    (
                        "Student Id:{0} is enrolled in {1}.",
                        new object[]
                {
                    studentModel.ID,
                    enrollmentModel.CourseTitle
                }
                    )
                );
            }

            stopWatch.Stop();
            this.output.WriteLine("WithoutRulesUsingExpressiionsInCode = {0}", stopWatch.Elapsed.TotalMilliseconds);
        }
예제 #8
0
 public Task <BaseResponse> SaveEntity(SaveEntityRequest request, string url = null)
 {
     return(Task.FromResult <BaseResponse>(new SaveEntityResponse {
         Success = true
     }));
 }
예제 #9
0
        private SaveEntityResponse SaveStudentWithoutRules(SaveEntityRequest saveStudentRequest)
        {
            Domain.Entities.StudentModel studentModel        = (StudentModel)saveStudentRequest.Entity;
            SaveEntityResponse           saveStudentResponse = new SaveEntityResponse()
            {
                ErrorMessages = new List <string>()
            };

            #region Validation
            if (string.IsNullOrWhiteSpace(studentModel.FirstName))
            {
                saveStudentResponse.ErrorMessages.Add("First Name is required.");
            }
            if (string.IsNullOrWhiteSpace(studentModel.LastName))
            {
                saveStudentResponse.ErrorMessages.Add("Last Name is required.");
            }
            if (studentModel.EnrollmentDate == default)
            {
                saveStudentResponse.ErrorMessages.Add("Enrollment Date is required.");
            }

            if (saveStudentResponse.ErrorMessages.Any())
            {
                flowManager.CustomActions.WriteToLog("An error occurred saving the request.");
                saveStudentResponse.Success = false;
                return(saveStudentResponse);
            }
            #endregion Validation

            #region Save and retrieve
            saveStudentResponse.Success = schoolRepository.SaveGraphAsync <Domain.Entities.StudentModel, Data.Entities.Student>(studentModel).Result;
            if (!saveStudentResponse.Success)
            {
                return(saveStudentResponse);
            }

            studentModel = schoolRepository.GetAsync <Domain.Entities.StudentModel, Data.Entities.Student>
                           (
                f => f.ID == studentModel.ID,
                null,
                new LogicBuilder.Expressions.Utils.Expansions.SelectExpandDefinition
            {
                ExpandedItems = new List <LogicBuilder.Expressions.Utils.Expansions.SelectExpandItem>
                {
                    new LogicBuilder.Expressions.Utils.Expansions.SelectExpandItem {
                        MemberName = "enrollments"
                    }
                }
            }
                           ).Result.SingleOrDefault();

            saveStudentResponse.Entity = studentModel;
            #endregion Save and retrieve

            #region Log Enrollments
            int Iteration_Index = 0;

            flowManager.CustomActions.WriteToLog
            (
                string.Format
                (
                    "EnrollmentCount: {0}. Index: {1}",
                    new object[]
            {
                studentModel.Enrollments.Count,
                Iteration_Index
            }
                )
            );

            Domain.Entities.EnrollmentModel enrollmentModel = null;
            while (Iteration_Index < studentModel.Enrollments.Count)
            {
                enrollmentModel = studentModel.Enrollments.ElementAt(Iteration_Index);
                Iteration_Index = Iteration_Index + 1;
                flowManager.CustomActions.WriteToLog
                (
                    string.Format
                    (
                        "Student Id:{0} is enrolled in {1}.",
                        new object[]
                {
                    studentModel.ID,
                    enrollmentModel.CourseTitle
                }
                    )
                );
            }
            #endregion Log Enrollments

            return(saveStudentResponse);
        }