Exemple #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());
        }
Exemple #2
0
        public HttpResponseMessage Post(AppModel app)
        {
            var savedApp = _appService.CreateApp(app);

            var response = Request.CreateResponse(HttpStatusCode.Created, savedApp);

            string link = Url.Link(RouteNames.DefaultApi, new { controller = "apps", id = 1 });

            response.Headers.Location = new Uri(link);

            return(response);
        }
Exemple #3
0
        public async Task <ActionResult> New(AppModel model)
        {
            if (!model.IsValid())
            {
                SetPleaseTryAgain(model);
                return(View(model));
            }

            model.CreatedBy = User.Identity.GetId();
            model.Email     = User.Identity.GetEmail();
            model.Id        = Guid.NewGuid().ToNoDashString();

            var isCreated = await _appService.CreateApp(model);

            if (isCreated)
            {
                return(Redirect(string.Format("/app/detail/{0}", model.Id)));
            }

            SetPleaseTryAgain(model);
            return(View(model));
        }