Example #1
0
        public async Task <IActionResult> Edit(int id, [Bind("CatagoryId,CatagoryName")] Catagory catagory)
        {
            if (id != catagory.CatagoryId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(catagory);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CatagoryExists(catagory.CatagoryId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(catagory));
        }
Example #2
0
        public async Task <IActionResult> Edit(int id, [Bind("ItemsId,CatagoryId,ItemsName,Description,Quantity,Price,Image,Model,Color")] Items items)
        {
            if (id != items.ItemsId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(items);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ItemsExists(items.ItemsId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CatagoryId"] = new SelectList(_context.Catagory, "CatagoryId", "CatagoryId", items.CatagoryId);
            return(View(items));
        }
        public async Task <IActionResult> Edit(int id, Phone phone)
        {
            if (id != phone.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    phone.CurrentDate = DateTime.Now;

                    _context.Update(phone);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PhoneExists(phone.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(await Connection("Edit", phone));
            }
            return(View(phone));
        }
        public async Task <IActionResult> Edit(int id, Product product)
        {
            if (id != product.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(product);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductExists(product.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(await Connection("Edit", product));
            }
            return(View(product));
        }
Example #5
0
        public async Task <IActionResult> Edit(int id, [Bind("PurchaseId,VenderId,ItemsId,Pquanity,PricePerUnit,TotalPrice,Date")] Purchase purchase)
        {
            if (id != purchase.PurchaseId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(purchase);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PurchaseExists(purchase.PurchaseId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ItemsId"]  = new SelectList(_context.Items, "ItemsId", "ItemsId", purchase.ItemsId);
            ViewData["VenderId"] = new SelectList(_context.Vender, "Vid", "Vid", purchase.VenderId);
            return(View(purchase));
        }
Example #6
0
        public async Task <IActionResult> Edit(int id, [Bind("OrderId,User,Address,ContactPhone,PhoneId")] Order order)
        {
            if (id != order.OrderId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(order);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!OrderExists(order.OrderId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PhoneId"] = new SelectList(_context.Phones, "Id", "Id", order.PhoneId);
            return(View(order));
        }
Example #7
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Company,Price")] Phone phone)
        {
            if (id != phone.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(phone);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PhoneExists(phone.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(phone));
        }
        public async Task <IActionResult> Edit(int id, [Bind("SalesId,CustomerId,ItemsId,Quantity,PricePerUnit,TotalPrice,TrDate")] Sales sales)
        {
            if (id != sales.SalesId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(sales);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SalesExists(sales.SalesId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CustomerId"] = new SelectList(_context.Customer, "CustomerId", "CustomerId", sales.CustomerId);
            ViewData["ItemsId"]    = new SelectList(_context.Items, "ItemsId", "ItemsId", sales.ItemsId);
            return(View(sales));
        }
Example #9
0
        public async Task <IActionResult> Edit(int id, [Bind("Id_oceny,Ocena,Ocena_slownie,Id_student")] Student_Oceny student_Oceny)
        {
            if (id != student_Oceny.Id_oceny)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(student_Oceny);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!Student_OcenyExists(student_Oceny.Id_oceny))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Id_student"] = new SelectList(_context.Students, "Id_student", "Id_student", student_Oceny.Id_student);
            return(View(student_Oceny));
        }
Example #10
0
        public IActionResult UpdateRow(Phone phone)
        {
            var id = phone.Id;
            var ph = db.Phones.FirstOrDefault(p => p.Id == id);

            if (phone.Name == null)
            {
            }
            else
            {
                ph.Name = phone.Name;
            }
            if (phone.Company == null)
            {
            }
            else
            {
                ph.Company = phone.Company;
            }
            if (phone.Price == 0)
            {
            }
            else
            {
                ph.Price = phone.Price;
            }
            db.Update(ph);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #11
0
        public async Task <IActionResult> Edit(int id, [Bind("Vid,Vname,Vmobile")] Vender vender)
        {
            if (id != vender.Vid)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(vender);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!VenderExists(vender.Vid))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(vender));
        }
Example #12
0
        public async Task <IActionResult> Edit(int id, [Bind("UserId,UserName,Password,UserRole")] UserProfile userProfile)
        {
            if (id != userProfile.UserId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(userProfile);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserProfileExists(userProfile.UserId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(userProfile));
        }
        public async Task <IActionResult> Edit(int id, [Bind("CustomerId,CustomerName,CustomerNo")] Customer customer)
        {
            if (id != customer.CustomerId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(customer);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CustomerExists(customer.CustomerId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
Example #14
0
        public async Task <IActionResult> Edit(int maHang, Hang hang)
        {
            if (maHang != hang.MaHang)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                _mb.Update(hang);
                await _mb.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(hang));
        }
Example #15
0
        public async Task <ActionResult <Mobile> > Put(Mobile mobile)
        {
            if (mobile == null)
            {
                return(BadRequest());
            }
            if (!db.Mobiles.Any(x => x.Id == mobile.Id))
            {
                return(NotFound());
            }

            db.Update(mobile);
            await db.SaveChangesAsync();

            return(Ok(mobile));
        }
        public async Task <IActionResult> Duyet(int maDH)
        {
            if (ModelState.IsValid)
            {
                var donHangFromMb = await _mb.DonHang.Include(dh => dh.KhachHang).Where(m => m.MaDH == maDH).FirstOrDefaultAsync();

                HoaDon hoaDon = new HoaDon()
                {
                    MaDH      = donHangFromMb.MaDH,
                    MaKH      = donHangFromMb.MaKH,
                    NgayLapHD = DateTime.Now,
                    TenKH     = donHangFromMb.KhachHang.TenKH,
                    SoDT      = donHangFromMb.KhachHang.SoDienThoai,
                    GioiTinh  = donHangFromMb.KhachHang.GioiTinh,
                    DiaChi    = donHangFromMb.KhachHang.DiaChi
                };

                _mb.Add(hoaDon);
                _mb.SaveChanges();
                var chiTiet = _mb.ChiTietDonHang.Where(ct => ct.MaDH == maDH).ToList();
                foreach (var chiTietDonHang in chiTiet)
                {
                    int soLuong = Convert.ToInt32(Request.Form[chiTietDonHang.MaDT.ToString()]);
                    if (soLuong != 0)
                    {
                        ChiTietHoaDon ct = new ChiTietHoaDon()
                        {
                            MaHD    = hoaDon.MaHD,
                            MaDT    = chiTietDonHang.MaDT,
                            SoLuong = soLuong,
                            TongGia = chiTietDonHang.TongGia / chiTietDonHang.SoLuong * soLuong,
                        };
                        _mb.Add(ct);
                    }
                    hoaDon.TongThanhToan = hoaDon.TongThanhToan + chiTietDonHang.TongGia / chiTietDonHang.SoLuong * soLuong;
                    _mb.Update(hoaDon);
                    _mb.SaveChanges();
                }
                ;

                return(RedirectToAction("Duyet", "HoaDons", new { hoaDon.MaHD }));
            }
            return(RedirectToAction(nameof(Index)));
        }
Example #17
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Company,Price,ImageFile")] Phone phone)
        {
            if (id != phone.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (phone.ImageFile != null)
                    {
                        string folderPath = Path.Combine(_webHostEnvironment.WebRootPath, "images", "phone_images");
                        string fileName   = $"{Guid.NewGuid().ToString()}_{phone.ImageFile.FileName}";
                        string filePath   = Path.Combine(folderPath, fileName);

                        using (var stream = new FileStream(filePath, FileMode.Create))
                        {
                            phone.ImageFile.CopyTo(stream);
                        }

                        phone.ImageName = fileName;
                    }
                    _context.Update(phone);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PhoneExists(phone.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(phone));
        }