/// <summary>
 /// 创建云购期数
 /// </summary>
 /// <param name="id">云购商品id</param>
 /// <returns></returns>
 public ActionResult CreateIssues(int id)
 {
     try
     {
         YGoodsIssue ygi    = db.YGoodsIssue.FirstOrDefault(s => s.YGoodsId == id);
         YGoods      ygoods = db.YGoods.FirstOrDefault(s => s.ID == id);
         //如果存在则返回已存在通知
         if (ygi != null)
         {
             return(RedirectToAction("CreateIssuesResult", new { type = "2" }));
         }
         else
         {
             //如果商品不存在不保存云购商品期数数据
             if (ygoods != null)
             {
                 int sum  = Convert.ToInt32(ygoods.Price);
                 var mark = ygoods.Mark;
                 if (mark == YGoodsEnumType.One)
                 {
                     sum = Convert.ToInt32(ygoods.Price);
                 }
                 else if (mark == YGoodsEnumType.Five)
                 {
                     sum = Convert.ToInt32(ygoods.Price) / 5;
                 }
                 else if (mark == YGoodsEnumType.Ten)
                 {
                     sum = Convert.ToInt32(ygoods.Price) / 10;
                 }
                 else if (mark == YGoodsEnumType.Hundred)
                 {
                     sum = Convert.ToInt32(ygoods.Price) / 100;
                 }
                 var model = new YGoodsIssue
                 {
                     YGoodsId      = id,
                     AlreadyNumber = 0,
                     AnnounceTime  = "",
                     IssueNumber   = 1,
                     LuckCode      = "",
                     State         = "进行中",
                     SumNumber     = sum,
                     SurplusNumber = Convert.ToInt32(ygoods.Price)
                 };
                 db.YGoodsIssue.Add(model);
                 db.SaveChanges();
                 return(RedirectToAction("CreateIssuesResult", new { type = "0" }));
             }
             else
             {
                 return(RedirectToAction("CreateIssuesResult", new { type = "3" }));
             }
         }
     }
     catch (Exception)
     {
         return(RedirectToAction("CreateIssuesResult", new { type = "1" }));
     }
 }
        // GET: YGoods/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            YGoods model  = db.YGoods.Find(id);
            var    models = new YGoodsView
            {
                ID        = model.ID,
                Info      = model.Info,
                Type      = model.Type,
                GoodsName = model.GoodsName,
                //MainImage = model.MainImage,
                Price = model.Price,
                //SamllImage = model.SamllImage,
                Stock = model.Stock,
                Mark  = model.Mark
            };

            models.MainImage.Images  = model.MainImage?.Split(',') ?? new string[0];
            models.SamllImage.Images = model.SamllImage?.Split(',') ?? new string[0];
            ViewBag.Type             = new SelectList(db.YGoodsType.OrderBy(s => s.ID), "ID", "Name", models.Type);
            if (model == null)
            {
                return(HttpNotFound());
            }
            return(View(models));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            YGoods yGoods = db.YGoods.Find(id);

            db.YGoods.Remove(yGoods);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        // GET: YGoods/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            YGoods yGoods = db.YGoods.Find(id);

            if (yGoods == null)
            {
                return(HttpNotFound());
            }
            return(View(yGoods));
        }
 public ActionResult Create(YGoodsView yGoods)
 {
     if (ModelState.IsValid)
     {
         var model = new YGoods
         {
             GoodsName  = yGoods.GoodsName,
             Type       = yGoods.Type,
             Stock      = yGoods.Stock,
             SamllImage = string.Join(",", yGoods.SamllImage.Images),
             Info       = yGoods.Info,
             MainImage  = string.Join(",", yGoods.MainImage.Images),
             Price      = yGoods.Price,
             Mark       = yGoods.Mark
         };
         db.YGoods.Add(model);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(yGoods));
 }