Пример #1
0
        public async Task <IActionResult> ImageEdit([FromForm] IFormFile file, [FromForm] ShopEditViewModel model)
        {
            if (file != null && file.Length > 0)
            {
                var imagePath = await ImageUploadHelper.ImageUpload(file, _env);

                ViewData["FileLocation"] = imagePath;
                model.image = imagePath;
            }
            model.statusList = GetShopStatus();

            return(View("Views/Shop/ShopEditView.cshtml", model));
        }
Пример #2
0
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                ShopEditViewModel shopViewModel = new ShopEditViewModel();
                TryUpdateModel(shopViewModel);

                var shopModel = new ShopModel();
                shopModel.ShopId     = shopViewModel.Shop.ShopId;
                shopModel.AddressID  = shopViewModel.Address.AddressID;
                shopModel.Email      = shopViewModel.Shop.Email;
                shopModel.Name       = shopViewModel.Shop.Name;
                shopModel.Phone      = shopViewModel.Shop.Phone;
                shopModel.CategoryID = shopViewModel.Shop.CategoryID;
                shopRepository.UpdateShop(shopModel);

                var addressModel = new AddressModel();
                addressModel.AddressID    = shopViewModel.Address.AddressID;
                addressModel.City         = shopViewModel.Address.City;
                addressModel.Country      = shopViewModel.Address.Country;
                addressModel.County       = shopViewModel.Address.County;
                addressModel.PostCode     = shopViewModel.Address.PostCode;
                addressModel.Street       = shopViewModel.Address.Street;
                addressModel.StreetNumber = shopViewModel.Address.StreetNumber;
                addressRepository.UpdateAddress(addressModel);

                shopPaymentMethodsRepository.DeleteShopPaymentMethods(shopViewModel.Shop.ShopId);

                foreach (var paymentMethodViewModel in shopViewModel.PaymentMethods)
                {
                    if (paymentMethodViewModel.Selected == true)
                    {
                        var shopPaymentMethod = new ShopPaymentMethodModel();
                        shopPaymentMethod.PaymentMethodID = paymentMethodViewModel.PaymentMethod.PaymentMethodID;
                        shopPaymentMethod.ShopID          = shopViewModel.Shop.ShopId;

                        shopPaymentMethodsRepository.InsertShopPaymentMethod(shopPaymentMethod);
                    }
                }

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                HandleErrorInfo error = new HandleErrorInfo(ex, "Shop", "Edit");
                return(View("Error", error));
            }
        }
Пример #3
0
 public ActionResult Edit(ShopEditViewModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var shopModel = db.Shops.FirstOrDefault(e => e.S_ID == model.S_ID);
             if (shopModel != null)
             {
                 shopModel.S_Address       = model.S_Address;
                 shopModel.S_Category      = model.S_Category;
                 shopModel.S_ContactName   = model.S_ContactName;
                 shopModel.S_ContactTel    = model.S_ContactTel;
                 shopModel.S_Name          = model.S_Name;
                 shopModel.S_Remark        = model.S_Remark;
                 shopModel.S_CreateTime    = model.S_CreateTime;
                 shopModel.S_ID            = model.S_ID;
                 shopModel.S_IsHasSetAdmin = model.S_IsHasSetAdmin;
                 if (db.SaveChanges() > 0)
                 {
                     return(RedirectToAction("Index"));
                 }
                 else
                 {
                     ModelState.AddModelError("", "修改失败");
                     return(View());
                 }
             }
             else
             {
                 ModelState.AddModelError("", "该店铺不存在");
                 return(View());
             }
         }
         else
         {
             ModelState.AddModelError("", "请输入的信息有误");
         }
         return(View());
     }
     catch
     {
         ModelState.AddModelError("", "报错信息");
         return(View());
     }
 }
Пример #4
0
        // GET: Shop/Edit/5
        public ActionResult Edit(int id)
        {
            Models.ShopModel shopModel = shopRepository.GetShopByID(id);

            var shopViewModel = new ShopEditViewModel();

            shopViewModel.Shop = shopModel;

            var        categories   = categoryRepository.GetAllCategories();
            SelectList categoryList = new SelectList(categories, "CategoryID", "Name");

            ViewData["CategoryList"] = categoryList;

            var address = addressRepository.GetAddressByID(shopModel.AddressID);

            shopViewModel.Address = address;

            var allPaymentMethods = paymentMethodsRepository.GetAllPaymentMethods();

            ViewData["AllPaymentMethods"] = allPaymentMethods;

            var shopPaymentMethods = paymentMethodsRepository.GetAllPaymentMethodsByShopId(shopModel.ShopId);

            List <PaymentMethodViewModel> paymentMethodViewModels = new List <PaymentMethodViewModel>();

            foreach (var paymentMethodModel in allPaymentMethods)
            {
                var paymentMethodViewModel = new PaymentMethodViewModel();
                paymentMethodViewModel.PaymentMethod = paymentMethodModel;

                foreach (var shopPaymentMethod in shopPaymentMethods)
                {
                    if (shopPaymentMethod.PaymentMethodID == paymentMethodModel.PaymentMethodID)
                    {
                        paymentMethodViewModel.Selected = true;
                    }
                }

                paymentMethodViewModels.Add(paymentMethodViewModel);
            }

            shopViewModel.PaymentMethods = paymentMethodViewModels;

            return(View("EditShop", shopViewModel));
        }
Пример #5
0
        public ActionResult Edit(int id)
        {
            var model     = db.Shops.FirstOrDefault(e => e.S_ID == id);
            var editModel = new ShopEditViewModel()
            {
                S_Address       = model.S_Address,
                S_Category      = model.S_Category,
                S_ContactName   = model.S_ContactName,
                S_ContactTel    = model.S_ContactTel,
                S_Name          = model.S_Name,
                S_Remark        = model.S_Remark,
                S_CreateTime    = model.S_CreateTime,
                S_ID            = model.S_ID,
                S_IsHasSetAdmin = model.S_IsHasSetAdmin
            };

            return(View(editModel));
        }
Пример #6
0
        public async Task <IActionResult> ShowEditShop(Guid shopId)
        {
            var editShop = await _context.Shops.FirstOrDefaultAsync(shop => shop.shopId.Equals(shopId));

            if (editShop != null)
            {
                var model = new ShopEditViewModel
                {
                    shopId  = shopId,
                    name    = editShop.name,
                    address = editShop.address,
                    note    = editShop.note,
                    image   = editShop.image
                };
                model.statusList = GetShopStatus();
                return(View("Views/Shop/ShopEditView.cshtml", model));
            }
            return(RedirectToAction("Index"));
        }
Пример #7
0
 public ActionResult Create(ShopEditViewModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var shopModel = new Shops()
             {
                 S_Address       = model.S_Address,
                 S_Category      = model.S_Category,
                 S_ContactName   = model.S_ContactName,
                 S_ContactTel    = model.S_ContactTel,
                 S_Name          = model.S_Name,
                 S_Remark        = model.S_Remark,
                 S_CreateTime    = model.S_CreateTime,
                 S_ID            = model.S_ID,
                 S_IsHasSetAdmin = model.S_IsHasSetAdmin
             };
             db.Shops.Add(shopModel);
             if (db.SaveChanges() > 0)
             {
                 return(RedirectToAction("Index"));
             }
             else
             {
                 ModelState.AddModelError("", "添加失败");
                 return(View());
             }
         }
         else
         {
             ModelState.AddModelError("", "请输入的信息有误");
             return(View());
         }
     }
     catch
     {
         return(View());
     }
 }
Пример #8
0
        public async Task <IActionResult> UpdateShop(Guid shopId, [FromForm] ShopEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                var request = new UpdateShopRequest
                {
                    name    = model.name,
                    address = model.address,
                    note    = model.note,
                    image   = model.image,
                    status  = model.status
                };
                var adminShopService = serviceLocator.GetService <IAdminShopService>();
                await adminShopService.UpdateShop(shopId, request);

                TempData["message"] = $"{request.name} đã được cập nhật";
                return(RedirectToAction("Index"));
            }
            else
            {
                ModelState.AddModelError("", "Nội Dung Nhập Không Phù Hợp");
                return(View("Views/Shop/ShopEditView.cshtml", model));
            }
        }
Пример #9
0
 public ShopEditView(Shop shop)
 {
     InitializeComponent();
     this.shopEditViewModel = new ShopEditViewModel(this, shop);
 }