Beispiel #1
0
        public ActionResult AddGood(AddGoodModel model)
        {
            if (ModelState.IsValid)
            {
                Good good = new Good
                {
                    GoodName     = model.GoodName,
                    Manufacturer = model.Manufacturer,
                    Category     = model.Category,
                    Price        = model.Price,
                    GoodCount    = model.GoodCount,
                    Photo        = model.Photo
                };

                using (var db = new ISHOpDB())
                {
                    db.Goods.Add(good);
                    try
                    {
                        db.SaveChanges();
                        return(RedirectToAction("Index", "Admin"));
                    }
                    catch { }
                }
            }
            return(View(model));
        }
        public async Task <IActionResult> AddGood(AddGoodModel model)
        {
            Instrument instrument = await GetReadyToAddInstrument(model);

            await ctx.Instruments.AddAsync(instrument);

            await ctx.SaveChangesAsync();

            return(Ok());
        }
        private async Task <string> SaveAndGetLocalFilePathIfNewerPhoto(AddGoodModel model)
        {
            bool ValidateImage(AddGoodModel model) => model.ImageBytes != null && model.ImageType != null;

            var localFilePath =
                ValidateImage(model)
                ? await fileSavingService.SaveFileAsync(model.ImageBytes, model.ImageType, "images")
                : null;

            return(localFilePath);
        }
        private async Task <Instrument> GetReadyToAddInstrument(AddGoodModel model)
        {
            var localFilePath = await SaveAndGetLocalFilePathIfNewerPhoto(model);

            var instrument = new Instrument
            {
                Description = model.Description,
                Quantity    = model.Quantity,
                Price       = model.Price,
                TypeName    = model.TypeName,
                Title       = model.Title,
                Image       = localFilePath
            };

            return(instrument);
        }
Beispiel #5
0
        public ActionResult AddGood()
        {
            AddGoodModel model = new AddGoodModel();

            return(View(model));
        }