예제 #1
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);
        }