Ejemplo n.º 1
0
        public async Task <IActionResult> SignUp([FromBody] PortalSignUpModel model)
        {
            try
            {
                FileLoger.CriticalInfo($"Register Clicked");
                FileLoger.CriticalInfo(model.SerializeToJson());

                if (!ModelState.IsValid)
                {
                    return(Json(new Response <string> {
                        Message = ModelState.GetModelError()
                    }));
                }

                FileLoger.CriticalInfo($"ModelState IsValid");

                if (model.UserAttachmentIds.Count() < 3)
                {
                    return(Json(new Response <string> {
                        Message = Strings.MustUploadAttachments
                    }));
                }

                FileLoger.CriticalInfo($"Attachment IsValid");

                model.MemberRoleId = int.Parse(_configuration["CustomSettings:MemberRoleId"]);
                var save = await _userSrv.SignUp(model);

                if (!save.IsSuccessful)
                {
                    return(Json(save));
                }

                FileLoger.CriticalInfo($"SignUp Success");

                var menuRep = _userSrv.GetAvailableActions(save.Result.UserId, null, _configuration["CustomSettings:UrlPrefix"]);
                if (menuRep == null)
                {
                    return(Json(new Response <string> {
                        IsSuccessful = false, Message = Strings.ThereIsNoViewForUser
                    }));
                }

                await CreateCookie(save.Result, true);

                FileLoger.CriticalInfo($"Register Success");

                return(Json(new { IsSuccessful = true, Result = Url.Action(menuRep.DefaultUserAction.Action, menuRep.DefaultUserAction.Controller, new { }) }));
            }
            catch (Exception e)
            {
                FileLoger.CriticalInfo($"Message: {e.Message} {Environment.NewLine} InnerMessage: {e.InnerException?.Message} ");

                FileLoger.CriticalError(e);
                return(Json(new Response <string> {
                    Message = Strings.Error
                }));
            }
        }