コード例 #1
0
        public ReturnMSG SaveProduct(Entities.ProductInfo prod)
        {
            Log.Current.WriteLog("Begin");
            ReturnMSG response = UtilEx.TryCatch <ReturnMSG>(() => {
                return(BangGoServerProxy.SaveProduct(prod));
            });

            return(response);
        }
コード例 #2
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser
                {
                    UserName          = model.Username ?? model.Email,
                    Email             = model.Email,
                    Firstname         = model.Firstname,
                    Lastname          = model.Lastname,
                    Gender            = model.Gender,
                    CreateDate        = DateTime.Now,
                    RegisterIPAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"] ?? ""
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await UpdateUserActivityInfo(user);

                    ReturnMSG bloguserresult = blogUserService.CreateUser(user.Id);
                    bloguserresult.GenerateMSG();
                    if (bloguserresult.Condition)
                    {
                        var addToRole = await AddUserRole(user);

                        if (addToRole.Succeeded)
                        {
                            await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);
                        }
                        else
                        {
                            Error(addToRole);
                        }


                        // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                        // Send an email with this link
                        // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                        // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                        // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    Error(result);
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
コード例 #3
0
ファイル: UtilEx.cs プロジェクト: ewin66/CsharpProjects
        public static ReturnMSG TryCatch <T>(Func <T> fuc) where T : ReturnMSG, new()
        {
            ReturnMSG response = new ReturnMSG();

            try
            {
                response = fuc();
            }
            catch (Exception ex)
            {
                response.isok    = false;
                response.Message = ex.InnerException == null ? ex.Message : ex.InnerException.Message;
            }
            return(response);
        }