Esempio n. 1
0
        public async Task <IActionResult> CreateApp([FromBody] CreateAppResource createAppResource)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                //string branchId = await _authService.GetBranchIdFromUserProfile(HttpContext);
                //string userId = await _authService.GetUserIdFromUserProfile(HttpContext);

                Log.Information("From Body {@CreateAppResource}", createAppResource);

                UserProfile userProfile = await _authService.GetUserProfileFromToken(HttpContext);

                MktCustomer customer = new MktCustomer()
                {
                    CardTypeId    = createAppResource.CardType,
                    IDCardNo      = createAppResource.IDCardNo,
                    NewOrOld      = BusinessConstant.CustomerNewType,
                    TitleId       = createAppResource.TitleId,
                    FirstNameThai = createAppResource.FirstNameThai,
                    LastNameThai  = createAppResource.LastNameThai
                };

                MktApplicationExtend appExtend = new MktApplicationExtend()
                {
                    CurrentBy    = userProfile.UserId,
                    CurrentLevel = userProfile.GroupLevelId
                };

                MktApplication app = new MktApplication()
                {
                    AppOwnerId = userProfile.UserId,

                    ApplicationExtend = appExtend,
                    Customer          = customer
                };

                var createdApp = await _appService.CreateApp(app, userProfile);

                string newURI = Url.Link("GetApp", new { appId = createdApp.AppId, toCheckNCB = true });

                var resultApp = new { appId = createdApp.AppId, url = newURI };

                return(Created(newURI, resultApp));
            }
            catch (Exception ex)
            {
                Log.Error("This is {@Exception}", ex);
            }

            return(BadRequest());
        }
Esempio n. 2
0
        private bool SendToCreditChecking(
            MktApplication app, UserProfile userProfile, CheckNCBAppResource checkNCBApp)
        {
            if (app == null)
            {
                return(false);
            }

            bool hasConsentScoreModel = checkNCBApp.Attachments.Any(a =>
                                                                    a.AttachmentType == BusinessConstant.AttachmentTypeConsentModel);

            _appService.SubmitToCreditChecking(app.AppId, app.Customer.Id, hasConsentScoreModel,
                                               checkNCBApp.Attachments, userProfile);

            return(true); // Success
        }
Esempio n. 3
0
        public MktApplication SaveAppBeforeSubmitToCreditChecking(MktApplication app, UserProfile userProfile)
        {
            using (var transaction = _appRepo.BeginTransaction())
            {
                _appRepo.Commit();

                _appRepo.UpdateApplicationCurrentCarId(app.Car.Id, app.AppId, transaction);

                // FastTrack เป็น 0 เพราะยังไม่ได้เลือก [อาชีพ]
                _appRepo.UpdateFastTrack(app.AppId, transaction);

                transaction.Commit();
            }

            return(app);
        }
Esempio n. 4
0
        private MktApplication SaveAppBeforeSubmitToCreditChecking(
            MktApplication app, UserProfile userProfile, CheckNCBAppResource checkNCBApp)
        {
            if (app == null)
            {
                return(null);
            }

            app.LoanType = UpdateLoanTypeBeforeSubmitToCreditChecking(app.AppId, userProfile.UserId, checkNCBApp,
                                                                      app.LoanType);

            app.Car = UpdateCarBeforeSubmitToCreditChecking(app.AppId, userProfile.UserId, checkNCBApp,
                                                            app.Car);

            app.Customer = UpdateCustomerBeforeSubmitToCreditChecking(app.AppId, userProfile.UserId, checkNCBApp,
                                                                      app.Customer);

            MktApplication updatedApp = _appService.SaveAppBeforeSubmitToCreditChecking(app, userProfile);

            return(updatedApp);
        }
Esempio n. 5
0
        public async Task <MktApplication> CreateApp(MktApplication app, UserProfile userProfile)
        {
            using (var transaction = _appRepo.BeginTransaction())
            {
                string appMaxId = _appRepo.GetMaxApplicationIdByUserId(app.AppOwnerId, transaction); // ST12511

                app.AppId                  = appMaxId;
                app.BranchId               = appMaxId.Substring(0, 2);
                app.AppStatus              = BusinessConstant.AppStatusMarketingInitial;
                app.Status                 = BusinessConstant.StatusActive;
                app.CreatedBy              = app.AppOwnerId;
                app.CreatedDate            = DateTime.Now;
                app.AppStatusPreSubmitDate = DateTime.Now;
                app.CurrentAppStatus       = app.AppStatus;
                app.LatestMarketingUserId  = app.AppOwnerId;
                app.LatestUserId           = app.AppOwnerId;

                //app.LastAppLogId = 0;

                app.Customer.Id              = _appRepo.GetMaxCustomerId(transaction);
                app.Customer.Status          = BusinessConstant.StatusActive;
                app.Customer.AppId           = appMaxId;
                app.Customer.MiddleNameThai  = string.Empty;
                app.Customer.AppCustomerType = BusinessConstant.CustomerAppCusTypePersonal;
                app.Customer.CustomerType    = BusinessConstant.CustomerTypePurchase;
                app.Customer.CreatedBy       = app.AppOwnerId;
                app.Customer.CreatedDate     = DateTime.Now;

                app.Customer.SexId = GetCustomerSexFromTitle(app.Customer.TitleId);

                MktAsset asset = new MktAsset {
                    CustomerId     = app.Customer.Id,
                    IsHave         = true,
                    LandSizeRai    = 0,
                    LandSizeWa     = 0,
                    LandAmount     = 0,
                    HouseSizeMeter = 0,
                    HouseAmount    = 0,
                    TotalAmount    = 0,
                    Status         = BusinessConstant.StatusActive,
                    CreateBy       = app.CreatedBy,
                    CreateDate     = DateTime.Now
                };

                app.Customer.Asset = asset;

                app.ApplicationExtend.AppId         = app.AppId;
                app.ApplicationExtend.OwnerBranchId = app.BranchId;

                app.Annotation = new MktAnnotation {
                    AppId         = app.AppId,
                    ApproveFlag   = BusinessConstant.FlagYes,
                    ApproveRemark = string.Empty,
                    Status        = BusinessConstant.StatusActive,
                    CreateBy      = app.AppOwnerId,
                    CreateDate    = DateTime.Now,
                    UpdateBy      = app.AppOwnerId,
                    UpdateDate    = DateTime.Now
                };

                ApplicationLog appLog = new ApplicationLog {
                    AppId = app.AppId,

                    FromUserId       = userProfile.UserId,
                    FromLevelId      = userProfile.GroupLevelId,
                    FromDepartmentID = userProfile.DepartmentId,
                    FromBranchID     = userProfile.BranchId,

                    AppLogDate = DateTime.Now,
                    AppStatus  = BusinessConstant.AppStatusMarketingInitial,

                    Remark     = "Create App from MAM",
                    ActionName = "Create App",
                    Status     = BusinessConstant.StatusActive,

                    CreateBy   = userProfile.UserId,
                    CreateDate = DateTime.Now
                };

                _appRepo.InsertApplicationLog(appLog, transaction);

                app.LastAppLogId = appLog.AppLogId;

                _appRepo.Add(app);

                await _appRepo.CommitAsync();

                transaction.Commit();
            }

            return(app);
        }