Beispiel #1
0
        public async Task <ActionResult> EditGoods(GoodsModel goods, int[] selectedSizes, HttpPostedFileBase image = null)
        {
            if (ModelState.IsValid)
            {
                if (image != null)
                {
                    goods.ImageData     = new byte[image.ContentLength];
                    goods.ImageMimeType = image.ContentType;
                    image.InputStream.Read(goods.ImageData, 0, image.ContentLength);
                }
                if (goods.GoodsId == 0)
                {
                    await _repository.AddGoodsAsync(goods, selectedSizes);
                }
                else
                {
                    await _repository.SaveGoodsAsync(goods, selectedSizes);
                }
                TempData["message"] = string.Format("Изменения в товаре \"{0}\" были сохранены", goods.Name);
                return(RedirectToAction("ListGoods"));
            }
            else
            {
                ViewBag.Categories   = new SelectList(await this._categoryRepository.GetCategoriesAsync(), "CategoryId", "Name");
                ViewBag.ClothesTypes = new SelectList(await this._typeRepository.GetClothesTypesAsync(), "ClothesTypeId", "Name");
                ViewBag.Sizes        = await this._sizeRepository.GetSizesAsync();

                return(View(goods));
            }
        }