在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#语言基础 → mvc4 PetsStore微软实例源码下载

mvc4 PetsStore微软实例源码下载

C#语言基础

下载此实例
  • 开发语言:C#
  • 实例大小:2.47M
  • 下载次数:19
  • 浏览次数:288
  • 发布时间:2014-07-25
  • 实例类别:C#语言基础
  • 发 布 人:xiaoxiaoyu2013
  • 文件格式:.zip
  • 所需积分:2
 相关标签: MVC 实例 c

实例介绍

【实例简介】
【实例截图】

【核心代码】

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PetsStore.EntitiesRepositories;
using PetsStore.Models;
using PetsStore.ViewModelServices;
using PetsStore.ViewModel;

namespace PetsStore.Controllers
{
    [Authorize]
    public class UserManagerController : Controller
    {
        MyMembership myMembership = new MyMembership();
        UserRepository userRepository = new UserRepository();
        CartRepository cartRepository = new CartRepository();
        UserManagerService userManagerService = new UserManagerService();
        ShippingRepository shippingRepository = new ShippingRepository();
        OrderRepository orderRepository = new OrderRepository();
        OrderDetailsRepository orderDetailsRepository = new OrderDetailsRepository();
        TransactionRepository transactionRepository = new TransactionRepository();
        PetRepository petRepository = new PetRepository();
        ReviewRepository reviewRepository = new ReviewRepository();
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult LogOut()
        {
            myMembership.UserLogOut();
            return RedirectToAction("Index", "Home");
        }
        [HttpPost]
        public ActionResult AddCart(Cart cart)
        {
            cart.UserID = userRepository.GetByUserName(HttpContext.User.Identity.Name).ID;
            if (ModelState.IsValid)
            {
                
                if (cartRepository.Insert(cart))
                {
                    return Json(true);
                }
                return Json(false);
            }
            else
            {
                return Json(false);
            }
        }

        public ActionResult MyCarts()
        {
            var username = User.Identity.Name;
            return View(userManagerService.getUserManager_MyCarts(username));
        }
        [HttpPost]
        public ActionResult UpdateQuantity(int CartID, int Quantity)
        {
            var user = userRepository.GetByUserName(HttpContext.User.Identity.Name);
            cartRepository.UpdateCartQuantity(CartID, Quantity);
            var cart = cartRepository.GetByCartID(CartID);
            return Json(new AjaxCart { Quantity = cart.Quantity, Amount = cart.Pet.Price * cart.Quantity, CartAmount = user.Carts.Sum(r => r.Quantity * r.Pet.Price) });
        }
        [HttpPost]
        public ActionResult DeleteCart(int id)
        {
            var user = userRepository.GetByUserName(HttpContext.User.Identity.Name);
            
            if (cartRepository.DeleteCart(id))
            {
                return Json(new AjaxCart { IsSuccess = true, CartAmount = user.Carts.Sum(r => r.Pet.Price * r.Quantity) });
            }
            return Json(new AjaxCart { IsSuccess = false, CartAmount = user.Carts.Sum(r => r.Pet.Price * r.Quantity) });
        }
        [HttpPost]
        public ActionResult ConfirmationOrder(List<int> checkcartid)
        {
            var user = userRepository.GetByUserName(HttpContext.User.Identity.Name);
            UserManager_CreateOrder userManager_CreateOrder = new UserManager_CreateOrder();
            userManager_CreateOrder.User = user;
            userManager_CreateOrder.Shippings = shippingRepository.GetByUserID(user.ID);
            List<OrderDetail> orderdetails = new List<OrderDetail>();
            if(checkcartid!=null)
            {
                foreach (int cartid in checkcartid)
                {
                    var cart = cartRepository.GetByCartID(cartid);
                    var orderdetail = new OrderDetail()
                    {
                        PetID = cart.PetID,
                        Quantity = cart.Quantity,
                        Pet=cart.Pet
                    };
                    orderdetails.Add(orderdetail);
                }
            }
            userManager_CreateOrder.OrderDetails = orderdetails;
            return View(userManager_CreateOrder);
        }
        [HttpPost]
        public ActionResult CreateOrder(int selectShpping, List<int> PetID, string Message,int[] Quantity)
        {
            string orderCode = DateTime.Now.ToString("yyyyMMddhhmmss")   new Random().Next(1000, 9999).ToString();
            int userID = userRepository.GetByUserName(HttpContext.User.Identity.Name).ID;
            Order order = new Order
            {
                DeleteForUser = false,
                Message = Message,
                OrderCode = orderCode,
                GeneratedTime = DateTime.Now,
                OrderStatus = true,
                PaymentStatus = false,
                ShippingStatus = "未发货",
                ShippingID = selectShpping,
                UserID = userID
            };
            if (orderRepository.Insert(order))
            {
                List<OrderDetail> orderdetails = new List<OrderDetail>();
                Order orderfromdata = orderRepository.GetByOrderCode(orderCode);
                int i = 0;
                foreach (int petID in PetID)
                {
                    OrderDetail orderDetail = new OrderDetail
                    {
                        PetID = petID,
                        Quantity = Quantity[i],
                        OrderID = orderfromdata.ID
                    };
                    orderdetails.Add(orderDetail);

                    //冲购物车中删除该宠物
                    Cart cart = cartRepository.GetByPetIDAndUserID(petID, userID);
                    cartRepository.DeleteCart(cart.ID);
                    i  = 1;
                }
                if (orderDetailsRepository.Insert(orderdetails))
                {


                    return RedirectToAction("MyOrders");
                }
                return Content("失败");
            }
            return Content("失败");
        }
        public ActionResult AddressBooks()
        {
            UserManager_AddressBooks usermanager_AddressBooks = userManagerService.GetUserManager_AddressBooks(shippingRepository);
            return View(usermanager_AddressBooks);
        }
        [HttpPost]
        public ActionResult AddressBooks(Shipping shipping)
        {
            if (ModelState.IsValid)
            {
                if (shippingRepository.Insert(shipping))
                {
                    return RedirectToAction("AddressBooks");
                }
                else
                {
                    ModelState.AddModelError("", "失败");
                    return View(userManagerService.GetUserManager_AddressBooks(shippingRepository));
                }
            }
            else
            {
                return View(userManagerService.GetUserManager_AddressBooks(shippingRepository));
            }
        }

        public ActionResult MyOrders()
        {
            var username = HttpContext.User.Identity.Name;
            var user = userRepository.GetByUserName(username);
            var orders = orderRepository.GetByUserID(user.ID);
            return View(orders);
        }
        
        [HttpPost]
        public ActionResult DeleteOrder(int id)
        {
            if (orderRepository.UserDeleteOrder(id))
            {
                return Json(true);
            }
            else
            {
                return Json(false);
            }
        }

        [HttpPost]
        public ActionResult CancelOrder(int id)
        {
            if (orderRepository.CancelOrder(id))
            {
                return Json(true);
            }
            return Json(false);
        }

        [HttpPost]
        public ActionResult Payment(int id)
        {
            
            if (orderRepository.Payment(id))
            {
                //添加到创建交易记录
                Order order = orderRepository.GetByOrderID(id);
                foreach (var orderDetail in order.OrderDetails)
                {
                    Transaction transaction = new Transaction()
                    {
                        Bid = orderDetail.Pet.Price,
                        PetID = orderDetail.PetID,
                        Quantity = orderDetail.Quantity,
                        TurnoverTime = orderDetail.Order.GeneratedTime,
                        UserID = orderDetail.Order.UserID
                    };
                    transactionRepository.Insert(transaction);
                }
                return Json(true);
            }
            return Json(false);
        }

        [HttpPost]
        public ActionResult ConfirmReceipt(int id)
        {
            if (orderRepository.ConfirmReceipt(id))
                return Json(true);
            return Json(false);
        }

        public ActionResult ShowOrder(int id)
        {
            return View(orderRepository.GetByOrderID(id));
        }

        public ActionResult PostComment(int PetID)
        {
            ViewBag.PetID=PetID;
            return View(petRepository.GetByID(PetID).Reviews);
        }
        [HttpPost]
        public ActionResult PostComment(Review review)
        {
            review.ReviewTime = DateTime.Now;
            review.UserID = userRepository.GetByUserName(HttpContext.User.Identity.Name).ID;
            var petid=review.PetID;
            if (reviewRepository.Insert(review))
            {

                return RedirectToAction("PostComment", new { PetID = review.PetID });
            }
            return View();
        }
    }
}

标签: MVC 实例 c

实例下载地址

mvc4 PetsStore微软实例源码下载

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警