Beispiel #1
0
 public ActionResult Edit(ShopManageViewModel model)
 {
     if (model.FileUpload.Images.Length != 1)
     {
         ModelState.AddModelError("Logo", "上传logo");
     }
     if (string.IsNullOrWhiteSpace(model.Name))
     {
         ModelState.AddModelError("Name", "填写名称");
     }
     if (ModelState.IsValid)
     {
         var shop = db.Shops.FirstOrDefault(s => s.ID == model.ID);
         shop.Name        = model.Name;
         shop.Sort        = model.Sort;
         shop.Logo        = model.FileUpload.Images.FirstOrDefault();
         shop.Code        = model.Code;
         shop.Lat         = model.Lat;
         shop.Lng         = model.Lng;
         shop.OwnerID     = model.OwnerID;
         shop.PhoneNumber = model.PhoneNumber;
         shop.Province    = model.Province;
         shop.Remark      = model.Remark;
         shop.TradingArea = model.TradingArea;
         shop.Address     = model.Address;
         shop.City        = model.City;
         shop.District    = model.District;
         shop.Images      = string.Join(",", model.ImagesFileUpload.Images);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(model));
 }
Beispiel #2
0
        public ActionResult Create()
        {
            Sidebar();
            var shop = new ShopManageViewModel()
            {
                FileUpload = new FileUpload()
                {
                    Max  = 1,
                    Name = "LogoFileUpload",
                    Type = FileType.Image
                },
                ImagesFileUpload = new FileUpload()
                {
                    Max  = 9,
                    Name = "ImagesFileUpload",
                    Type = FileType.Image
                },
            };

            return(View(shop));
        }
Beispiel #3
0
        public ActionResult Edit(int id)
        {
            Sidebar();
            var shop  = db.Shops.FirstOrDefault(s => s.ID == id);
            var model = new ShopManageViewModel()
            {
                Code        = shop.Code,
                Sort        = shop.Sort,
                Logo        = shop.Logo,
                Name        = shop.Name,
                Lat         = shop.Lat,
                Lng         = shop.Lng,
                OwnerID     = shop.OwnerID,
                PhoneNumber = shop.PhoneNumber,
                Province    = shop.Province,
                Remark      = shop.Remark,
                TradingArea = shop.TradingArea,
                Address     = shop.Address,
                City        = shop.City,
                District    = shop.District,
                Images      = shop.Images,
                ID          = shop.ID,
                FileUpload  = new FileUpload()
                {
                    Max    = 1,
                    Images = new string[] { shop.Logo },
                    Type   = FileType.Image,
                    Name   = "LogoFileUpload",
                },
                ImagesFileUpload = new FileUpload()
                {
                    Max    = 9,
                    Images = shop.Images.SplitToArray <string>().ToArray(),
                    Type   = FileType.Image,
                    Name   = "ImagesFileUpload",
                },
            };

            return(View(model));
        }
Beispiel #4
0
 public ActionResult Create(ShopManageViewModel model)
 {
     if (model.FileUpload.Images.Length != 1)
     {
         ModelState.AddModelError("Logo", "上传logo");
     }
     if (string.IsNullOrWhiteSpace(model.Name))
     {
         ModelState.AddModelError("Name", "填写名称");
     }
     if (ModelState.IsValid)
     {
         var shop = new Shop()
         {
             Code        = model.Code,
             Sort        = model.Sort,
             Logo        = model.FileUpload.Images.FirstOrDefault(),
             Name        = model.Name,
             Address     = model.Address,
             City        = model.City,
             District    = model.District,
             Images      = string.Join(",", model.ImagesFileUpload.Images),
             Lat         = model.Lat,
             Lng         = model.Lng,
             OwnerID     = model.OwnerID,
             PhoneNumber = model.PhoneNumber,
             Province    = model.Province,
             Remark      = model.Remark,
             TradingArea = model.TradingArea
         };
         db.Shops.Add(shop);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(model));
 }