Exemplo n.º 1
0
        public IActionResult GoodNew()
        {
            var model = new GoodWorker {
                Action = "New", GoodModel = new GoodModel()
            };

            model.GoodModel.CreatorID = GetUserID();
            return(View("Good", model));
        }
Exemplo n.º 2
0
        public IActionResult Good(GoodWorker goodWorker)
        {
            ShopEngine.ShopEngineService shopEngine = new ShopEngine.ShopEngineService();
            var    file = Request.Form.Files.FirstOrDefault();
            string path = string.Empty;

            if (file != null && file.Length > 0)
            {
                path = $"images\\{GetUserLogin()}\\".Replace(".", "_").Replace("@", "_");
                if (!string.IsNullOrEmpty(goodWorker.GoodModel.ImagePath))
                {
                    System.IO.File.Delete($"wwwroot\\{goodWorker.GoodModel.ImagePath}");
                }
                var realPath = $"wwwroot\\{path}";
                if (!Directory.Exists(realPath))
                {
                    Directory.CreateDirectory(realPath);
                }
                realPath += file.FileName;
                path     += file.FileName;
                if (!System.IO.File.Exists(realPath))
                {
                    using (var stream = new FileStream(realPath, FileMode.OpenOrCreate))
                        file.CopyToAsync(stream);
                }
            }

            goodWorker.GoodModel.ImagePath = path;

            switch (goodWorker.Action.ToLower())
            {
            case "new":
                shopEngine.AddGood(goodWorker.GoodModel);
                break;

            case "edit":
                shopEngine.UpdateGood(goodWorker.GoodModel);
                break;
            }
            return(RedirectToAction("Index"));
        }