Ejemplo n.º 1
0
 public ActionResult Create(Album album, HttpPostedFileBase cover)
 {
     if (ModelState.IsValid)
     {
         if (UploadFiles(album, cover))
         {
             context.Albums.Add(album);
             context.SaveChanges();
             string info = "<script>location.href=confirm('添加专辑成功,是否继续添加专辑?')?'" + Url.Action("Create") + "':'" + Url.Action("Index") + "';</script>";
             return(Content(info));
         }
         else
         {
             //重新获得下拉列表数据
             PrepareSelectedItems(album);
             return(View(album));
         }
     }
     else
     {
         //给出版社与分类添加错误提示
         if (album.GenreId == 0)
         {
             ModelState.AddModelError("GenreId", "请选择音乐流派");
         }
         if (album.ArtistId == 0)
         {
             ModelState.AddModelError("ArtistId", "请选择艺术家");
         }
         //重新获得下拉列表数据
         PrepareSelectedItems(album);
         return(View(album));
     }
 }
Ejemplo n.º 2
0
        public ActionResult Create([Bind(Include = "GenreId,Name,Description")] Genre genre)
        {
            if (ModelState.IsValid)
            {
                db.Genres.Add(genre);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(genre));
        }
Ejemplo n.º 3
0
        public ActionResult Create([Bind(Include = "AlbumId,GenreId,ArtistId,Title,Price,AlbumArtUrl")] Album album)
        {
            if (ModelState.IsValid)
            {
                db.Albums.Add(album);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ArtistId = new SelectList(db.Artists, "ArtistId", "Name", album.ArtistId);
            ViewBag.GenreId  = new SelectList(db.Genres, "GenreId", "Name", album.GenreId);
            return(View(album));
        }
Ejemplo n.º 4
0
 //删除一个详情订单
 public ActionResult DeleteOrderDetail(int id)
 {
     try
     {
         OrderDetail od = new OrderDetail {
             OrderDetailId = id
         };
         context.OrderDetails.Attach(od);
         context.OrderDetails.Remove(od);
         context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch (Exception)
     {
         string    message = "数据库在执行删除详细订单操作时,出现异常。";
         Exception ex      = new Exception(message);
         return(View("Error", new HandleErrorInfo(ex, "Order", "DeleteOrderDetail")));
     }
 }
Ejemplo n.º 5
0
 public ActionResult Edit(EditUserModel model)
 {
     if (ModelState.IsValid)
     {
         int id   = ((UserInfo)Session["User"]).Id;
         var user = context.UserInfoes.Find(id);
         user.Email           = model.Email.Trim();
         user.Name            = model.Name.Trim();
         user.Phone           = model.Phone.Trim();
         user.Address         = model.Address.Trim();
         user.Birthday        = model.Birthday;
         user.LoginPwdConfirm = user.LoginPwd;
         user.SecurityCode    = "123";
         context.SaveChanges();
         //更新Session里存储的User对象
         Session["User"]     = user;
         TempData["message"] = "修改个人信息成功";
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View(model));
     }
 }
Ejemplo n.º 6
0
 public ActionResult Register(UserInfo model)
 {
     if (ModelState.IsValid)
     {
         bool flag = false;                //是否未通过
         //验证码是否正确
         if (!model.SecurityCode.ToUpper().Equals(TempData["SecurityCode"]))
         {
             ModelState.AddModelError("SecurityCode", "验证码输入有误");
             flag = true;
         }
         //用户名是否重复
         if (context.UserInfoes.Where(m => m.LoginId == model.LoginId.Trim().ToLower()).Count() > 0)
         {
             ModelState.AddModelError("LoginId", "用户名已存在");
             flag = true;
         }
         if (flag)
         {
             return(View(model));
         }
         model.LoginId  = model.LoginId.Trim().ToLower();
         model.LoginPwd = model.LoginPwd.Trim().ToLower();
         model.Name     = model.Name.Trim();
         context.UserInfoes.Add(model);
         context.SaveChanges();
         return(Content("<script>alert('注册成功,现在跳转到登录页面');location.href='" + Url.Action("Login", "Account") + "';</script>"));
     }
     else
     {
         if (model != null)
         {
             //验证码是否正确
             if (model.SecurityCode != null && !model.SecurityCode.ToUpper().Equals(TempData["SecurityCode"]))
             {
                 ModelState.AddModelError("SecurityCode", "验证码输入有误");
             }
             //用户名是否重复
             if (model.LoginId != null && context.UserInfoes.Where(m => m.LoginId == model.LoginId.Trim().ToLower()).Count() > 0)
             {
                 ModelState.AddModelError("LoginId", "用户名已存在");
             }
         }
         return(View(model));
     }
 }
Ejemplo n.º 7
0
        public ActionResult AddressAndPayment([Bind(Include = "FirstName,LastName,Address,City,State,PostalCode,Phone,Email,AccountNumber,SecurityCode")] Order order)
        {
            if (ModelState.IsValid)
            {
                order.Username  = User.Identity.Name;
                order.OrderDate = DateTime.Now;
                //Save Order
                db.Orders.Add(order);
                db.SaveChanges();
            }
            //Process the order
            var cart = MusicCart.GetMusicCart(this.HttpContext);

            cart.CreateOrder(order);

            return(RedirectToAction("CheckoutComplete", new { id = order.OrderId }));
        }
Ejemplo n.º 8
0
 public ActionResult Pay(Order order)
 {
     if (ModelState.IsValid)
     {
         var cart = ShoppingCart.GetCart(this.HttpContext);
         order.OrderDate = DateTime.Now;
         order.UserId    = (Session["User"] as UserInfo).Id;
         order.Amount    = cart.GetTotal();
         //添加订单
         order = context.Orders.Add(order);
         context.SaveChanges();
         //添加详细订单,删除购物车...
         cart.CreateOrder(order);
         Session.Remove(ShoppingCart.CartSessionKey);
         return(RedirectToAction("Complete", new { id = order.OrderId }));
     }
     else
     {
         return(View(order));
     }
 }