public IActionResult Details(int orderId)
        {
            Order  order = this.ordersService.GetOrder(orderId);
            UMUser user  = this.usersService.GetUserById(order.UserId);

            OrderDetailsViewModel model = new OrderDetailsViewModel
            {
                Id         = order.Id,
                Address    = this.addressesService.GetAddress(order.DeliveryAddressId),
                CartMovies = this.ordersService.GetOrderMovies(order.Id).Select(x => new CartMovieViewModel
                {
                    Id        = x.MovieId,
                    Name      = this.moviesService.GetMovie(x.MovieId).Name,
                    PosterUrl = this.moviesService.GetMovie(x.MovieId).PosterUrl,
                    Price     = x.Price,
                    Quantity  = x.Quantity
                }).ToList(),
                CartPrice            = order.TotalPrice - order.DeliveryPrice,
                DeliveredDate        = order.DeliveredDate,
                DeliveryPrice        = order.DeliveryPrice,
                DeliveryType         = order.DeliveryType,
                OrderDate            = (DateTime)order.OrderDate,
                OrderStatus          = order.OrderStatus,
                PaymentType          = order.PaymentType,
                ProcesedDate         = order.ProcesedDate,
                RecipientName        = user.FirstName + " " + user.LastName,
                RecipientPhoneNumber = user.PhoneNumber,
                TotalPrice           = order.TotalPrice
            };

            return(this.View(model));
        }
        public IActionResult Summary()
        {
            Order  order = this.ordersService.GetLastOrder(this.User.Identity.Name);
            UMUser user  = this.usersService.GetUser(this.User.Identity.Name);

            if (order.OrderStatus == OrderStatus.Unfinished)
            {
                ViewData["OrderId"] = order.Id;

                return(this.View("Pay"));
            }

            OrderSummaryViewModel model = new OrderSummaryViewModel
            {
                Address       = this.addressesService.GetAddress(order.DeliveryAddressId),
                DeliveryPrice = order.DeliveryPrice,
                DeliveryType  = order.DeliveryType,
                OrderId       = order.Id,
                PaymentType   = order.PaymentType,
                Phone         = user.PhoneNumber,
                FullName      = user.FirstName + " " + user.LastName,
                CartMovies    = this.ordersService.GetOrderMovies(order.Id).Select(x => new CartMovieViewModel
                {
                    Id        = x.MovieId,
                    Price     = x.Price,
                    Quantity  = x.Quantity,
                    Name      = this.moviesService.GetMovie(x.MovieId).Name,
                    PosterUrl = this.moviesService.GetMovie(x.MovieId).PosterUrl
                }).ToList()
            };

            return(this.View(model));
        }
        public void AddMovieToWishList(string username, int movieId)
        {
            UMUser user  = this.db.Users.FirstOrDefault(u => u.UserName == username);
            Movie  movie = this.db.Movies.FirstOrDefault(m => m.Id == movieId);

            if (user == null || movie == null)
            {
                return;
            }

            if (this.db.WishListMovies.Any(x => x.UserId == user.Id && x.MovieId == movie.Id))
            {
                this.RemoveMovieFromWishList(username, movieId);
                return;
            }

            WishListMovie wishListMovie = new WishListMovie();

            wishListMovie.MovieId = movie.Id;
            wishListMovie.UserId  = user.Id;

            if (user.WishList == null)
            {
                user.WishList = new HashSet <WishListMovie>();
            }

            user.WishList.Add(wishListMovie);
            this.db.WishListMovies.Add(wishListMovie);

            this.db.SaveChanges();
        }
        public ICollection <Movie> GetMoviesFromWishList(string username)
        {
            UMUser       user   = this.db.Users.FirstOrDefault(u => u.UserName == username);
            List <Movie> result = new List <Movie>();

            foreach (WishListMovie wishListMovie in this.db.WishListMovies)
            {
                if (wishListMovie.UserId == user.Id)
                {
                    result.Add(this.db.Movies.FirstOrDefault(m => m.Id == wishListMovie.MovieId));
                }
            }

            return(result);
        }
        private async Task LoadSharedKeyAndQrCodeUriAsync(UMUser user)
        {
            // Load the authenticator key & QR code URI to display on the form
            var unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user);

            if (string.IsNullOrEmpty(unformattedKey))
            {
                await _userManager.ResetAuthenticatorKeyAsync(user);

                unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user);
            }

            SharedKey = FormatKey(unformattedKey);

            var email = await _userManager.GetEmailAsync(user);

            AuthenticatorUri = GenerateQrCodeUri(email, unformattedKey);
        }
Exemple #6
0
        public void GetUserShouldReturnUser()
        {
            DbContextOptions <UltimateMoviesDbContext> options = new DbContextOptionsBuilder <UltimateMoviesDbContext>()
                                                                 .UseInMemoryDatabase(databaseName: "Orders_GetUser_Database")
                                                                 .Options;
            UltimateMoviesDbContext db = new UltimateMoviesDbContext(options);

            IOrdersService ordersService = new OrdersService(db);

            db.Users.Add(new UMUser {
                UserName = "******"
            });

            db.SaveChanges();

            UMUser user = ordersService.GetUser("Tester");

            Assert.Equal("Tester", user.UserName);
        }
        public async Task <IActionResult> OnPostConfirmationAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            // Get the information about the user from the external login provider
            var info = await _signInManager.GetExternalLoginInfoAsync();

            if (info == null)
            {
                ErrorMessage = "Error loading external login information during confirmation.";
                return(RedirectToPage("./Login", new { ReturnUrl = returnUrl }));
            }

            if (ModelState.IsValid)
            {
                var user = new UMUser {
                    UserName = Input.Email, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await _userManager.AddLoginAsync(user, info);

                    if (result.Succeeded)
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        _logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider);
                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            LoginProvider = info.LoginProvider;
            ReturnUrl     = returnUrl;
            return(Page());
        }
Exemple #8
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            if (ModelState.IsValid)
            {
                var user = new UMUser {
                    UserName = Input.Username, Email = Input.Email, FirstName = Input.FirstName, LastName = Input.LastName
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { userId = user.Id, code = code },
                        protocol: Request.Scheme);

                    await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                      $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    await _signInManager.SignInAsync(user, isPersistent : false);

                    return(LocalRedirect(returnUrl));
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
        public void RemoveMovieFromWishList(string username, int movieId)
        {
            UMUser user  = this.db.Users.FirstOrDefault(u => u.UserName == username);
            Movie  movie = this.db.Movies.FirstOrDefault(m => m.Id == movieId);

            if (user == null || movie == null)
            {
                return;
            }

            if (!this.db.WishListMovies.Any(x => x.UserId == user.Id && x.MovieId == movie.Id))
            {
                return;
            }

            if (user.WishList != null)
            {
                user.WishList.Remove(user.WishList.FirstOrDefault(x => x.MovieId == movie.Id && x.UserId == user.Id));
            }

            this.db.WishListMovies.Remove(this.db.WishListMovies.FirstOrDefault(x => x.MovieId == movie.Id && x.UserId == user.Id));

            this.db.SaveChanges();
        }
Exemple #10
0
        public ActionResult ValidateUser(string email, string password, int isCheck, string loginType)
        {
            bool islogin = false; ///是否登录成功
            //bool isemail = false;///是否邮件验证过
            string message = "";  ///出错原因
            string url     = "";  ///跳转的默认路径

            var jsonData = new
            {
                Islogin = islogin,
                //Isemail = isemail,
                Message = message,
                Url     = url,
            };



            UMUser account = UMUserManager.Instance.Login(email, password, loginType);
            //终端设备IP
            string ipaddress = System.Web.HttpContext.Current.Request.UserHostAddress.ToString().Trim();
            //终端信息
            string terminalInfo = System.Web.HttpContext.Current.Request.UserAgent.ToString().Trim();

            if (account != null)
            {
                if (account.EnableFlag == "N")
                {
                    islogin = false;

                    message = "登录失败。";
                    //isemail = false;
                    jsonData = new
                    {
                        Islogin = islogin,
                        //Isemail = isemail,
                        Message = message,
                        Url     = url,
                    };
                    return(Json(jsonData));
                }
                islogin = true;


                AccountClone             userClone             = new AccountClone();
                List <TmpAccountCompany> tmpAccountCompanyList = new List <TmpAccountCompany>();

                userClone.GID = account.UserID;
                //userClone.CompanyList = tmpAccountCompanyList;
                userClone.UserName   = account.UserName;
                userClone.RealName   = account.Name;
                userClone.ModuleList = null;


                GetTmpAccountCompanyByAccountClone(userClone);
                Session["Account"] = userClone;
                SysCompanyLogManager.Instance.AddSysComLog(SignInAccount.UserName, SysLogType.信息日志, "登录系统", "");


                //插入企业用户行为日志
                UserBehaviorManager.Instance.AddUserBehaviorLog(SignInAccount.GID.ToString(), "系统登录", SignInAccount.SelectCompanyID, "", 'S', ipaddress, terminalInfo);

                //用户退出登录保留登录邮箱(30天内记住我)
                HttpCookie emailCok = System.Web.HttpContext.Current.Request.Cookies["EmailCookie"];
                if (isCheck == 1)
                {
                    emailCok         = new HttpCookie("EmailCookie"); //初使化并设置Cookie的名称
                    emailCok.Expires = DateTime.Now.AddMonths(1);     //设置过期时间
                    emailCok.Values.Add("EmailInfo", Encryption.Instance.Encrypto(email));
                    Response.AppendCookie(emailCok);
                }
                else if (isCheck == 0)
                {
                    if (emailCok != null)
                    {
                        TimeSpan ts = new TimeSpan(-1, 0, 0, 0);
                        emailCok.Expires = DateTime.Now.Add(ts);//删除整个Cookie,只要把过期时间设置为现在
                        Response.AppendCookie(emailCok);
                    }
                }
            }
            else
            {
                jsonData = new
                {
                    Islogin = islogin,
                    // Isemail = isemail,
                    Message = "用户不存在或密码错误!",
                    Url     = url,
                };
                //登录失败
                // UserBehaviorManager.Instance.AddUserBehaviorLog(SignInAccount.GID.ToString(), "系统登录", SignInAccount.SelectCompanyID, "", 'F', ipaddress, terminalInfo);
                return(Json(jsonData));
            }


            url      = "/Home/DashBoard";
            jsonData = new
            {
                Islogin = true,
                //Isemail = true,
                Message = message,
                Url     = url,
            };
            return(Json(jsonData));
        }