public async Task <bool> UrunGuncelle(UrunGuncelleViewModel model)
        {
            var result = false;

            try
            {
                var data = await context.Urun.FirstOrDefaultAsync(x => x.IsActive && !x.IsDelete && x.Id == model.Id);

                if (data != null)
                {
                    data.UrunAdi    = model.UrunAdi;
                    data.Stok       = model.Stok;
                    data.BirimFiyat = model.BirimFiyat;
                    if (model.ResimPath != null)
                    {
                        var silinecekResim = HttpContext.Current.Server.MapPath($"~/Taskesti/images/resimler/{model.ResimPath}");
                        if (!string.IsNullOrEmpty(silinecekResim))
                        {
                            if (File.Exists(silinecekResim))
                            {
                                File.Delete(silinecekResim);
                            }
                        }
                        data.UrunResmi = SaveDocument(model.ResimPath);
                    }
                    await context.SaveChangesAsync();

                    result = true;
                    ProjeHub.GetUrunData();
                }
            }
            catch (Exception e)
            {
                var message = e.Message;
                throw;
            }

            return(result);
        }
        public async Task <UrunGuncelleViewModel> GetUrunBilgi(int?id)
        {
            var model = new UrunGuncelleViewModel();

            model.ResimAdi = "DocumentFiles/unnamed.png";
            if (id != null)
            {
                model = await context.Urun.Where(x => x.IsActive && !x.IsDelete && x.Id == id).Select(x =>
                                                                                                      new UrunGuncelleViewModel
                {
                    Id         = x.Id,
                    BirimFiyat = x.BirimFiyat,
                    ResimAdi   = x.UrunResmi,
                    Stok       = x.Stok,
                    UrunAdi    = x.UrunAdi,
                    IsActive   = x.IsActive,
                    IsDelete   = x.IsDelete
                }).FirstOrDefaultAsync();
            }

            return(model);
        }
Beispiel #3
0
        public async Task <ActionResult> UrunGuncelle(UrunGuncelleViewModel model)
        {
            var result = await urunService.UrunGuncelle(model);

            return(Json(result, JsonRequestBehavior.AllowGet));
        }