Example #1
0
        public async Task <ÜrünResponse> UpdateAsync(int id, Ürün Ürün)
        {
            var existingÜrün = await _ÜrünRepository.FindByIdAsync(id);

            if (existingÜrün == null)
            {
                return(new ÜrünResponse("Ürün not found."));
            }

            var existingCategory = await _categoryRepository.FindByIdAsync(Ürün.CategoryId);

            if (existingCategory == null)
            {
                return(new ÜrünResponse("Invalid category."));
            }

            existingÜrün.Name       = Ürün.Name;
            existingÜrün.Birim      = Ürün.Birim;
            existingÜrün.Stok       = Ürün.Stok;
            existingÜrün.CategoryId = Ürün.CategoryId;

            try
            {
                _ÜrünRepository.Update(existingÜrün);
                await _unitOfWork.CompleteAsync();

                return(new ÜrünResponse(existingÜrün));
            }
            catch (Exception ex)
            {
                // Do some logging stuff
                return(new ÜrünResponse($"An error occurred when updating the Ürün: {ex.Message}"));
            }
        }
Example #2
0
        public async Task <ÜrünResponse> SaveAsync(Ürün Ürün)
        {
            try
            {
                /*
                 * Notice here we have to check if the category ID is valid before adding the Ürün, to avoid errors.
                 * You can create a method into the CategoryService class to return the category and inject the service here if you prefer, but
                 * it doesn't matter given the API scope.
                 */
                var existingCategory = await _categoryRepository.FindByIdAsync(Ürün.CategoryId);

                if (existingCategory == null)
                {
                    return(new ÜrünResponse("Invalid category."));
                }

                await _ÜrünRepository.AddAsync(Ürün);

                await _unitOfWork.CompleteAsync();

                return(new ÜrünResponse(Ürün));
            }
            catch (Exception ex)
            {
                // Do some logging stuff
                return(new ÜrünResponse($"An error occurred when saving the Ürün: {ex.Message}"));
            }
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Ürün ürün = db.Ürün.Find(id);

            db.Ürün.Remove(ürün);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult Details([Bind(Include = "ÜrünId,Ücret,Mevcut,Satıldı,KategoriId,Açıklama,ÜrünAdı,alınacak")] Ürün ür, int?idci)
        {
            if (ModelState.IsValid)
            {
                return(RedirectToAction("Index", "Sepet", new { id = idci, adet = ür.alınacak }));
            }

            return(View(ür));
        }
        public ActionResult Index([Bind(Include = "ÜrünId,Ücret,Mevcut,Satıldı,KategoriId,Açıklama,ÜrünAdı")] Ürün ür)
        {
            var ürün = db.Ürün.Include(ü => ü.Kategori).Where(a => a.KategoriId == ür.KategoriId);
            var kats = new SelectList(db.Kategori.Select(a => a.KategoriAdı));

            ViewBag.KategoriId  = new SelectList(db.Kategori, "KategoriId", "KategoriAdı");
            ViewBag.kategoriler = db.Kategori.Select(a => a.KategoriAdı);

            return(View(ürün));
        }
 public ActionResult Edit([Bind(Include = "ÜrünId,Ücret,Mevcut,Satıldı,KategoriId,Açıklama,ÜrünAdı")] Ürün ürün)
 {
     if (ModelState.IsValid)
     {
         db.Entry(ürün).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.KategoriId = new SelectList(db.Kategori, "KategoriId", "KategoriAdı", ürün.KategoriId);
     return(View(ürün));
 }
        // GET: Ürün/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Ürün ürün = db.Ürün.Find(id);

            if (ürün == null)
            {
                return(HttpNotFound());
            }
            return(View(ürün));
        }
        public ActionResult Create([Bind(Include = "ÜrünId,Ücret,Mevcut,Satıldı,KategoriId,Açıklama,ÜrünAdı")] Ürün ürün)
        {
            if (ModelState.IsValid)
            {
                // ürün.ÜrünId = null;
                db.Ürün.Add(ürün);

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.KategoriId = new SelectList(db.Kategori, "KategoriId", "KategoriAdı", ürün.KategoriId);
            return(View(ürün));
        }
        // GET: Ürün/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Ürün ürün = db.Ürün.Find(id);

            if (ürün == null)
            {
                return(HttpNotFound());
            }
            ViewBag.KategoriId = new SelectList(db.Kategori, "KategoriId", "KategoriAdı", ürün.KategoriId);
            return(View(ürün));
        }
        public ActionResult Details(int?id)
        {
            ViewBag.id = id;

            int x = 1;

            ViewBag.adet = x;
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Ürün ürün = db.Ürün.Find(id);

            if (ürün == null)
            {
                return(HttpNotFound());
            }
            return(View(ürün));
        }
Example #11
0
 public void Remove(Ürün Ürün)
 {
     _context.Ürünler.Remove(Ürün);
 }
Example #12
0
 public void Update(Ürün Ürün)
 {
     _context.Ürünler.Update(Ürün);
 }
Example #13
0
 public async Task AddAsync(Ürün Ürün)
 {
     await _context.Ürünler.AddAsync(Ürün);
 }