public ActionResult Create(HttpPostedFileBase file, [Bind(Include = "ma_dv,ten_dv,gia,don_vi,ton_kho")] tblDichVu tblDichVu) { if (ModelState.IsValid) { String anh = "/Content/Images/DichVu/default.png"; if (file != null) { string pic = System.IO.Path.GetFileName(file.FileName); String path = System.IO.Path.Combine( Server.MapPath("~/Content/Images/DichVu"), pic); // file is uploaded file.SaveAs(path); anh = "/Content/Images/DichVu/" + pic; // save the image path path to the database or you can send image // directly to database // in-case if you want to store byte[] ie. for DB using (MemoryStream ms = new MemoryStream()) { file.InputStream.CopyTo(ms); byte[] array = ms.GetBuffer(); } } tblDichVu.anh = anh; db.tblDichVus.Add(tblDichVu); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tblDichVu)); }
public ActionResult SuaDichVu(String ma_hd, String edit_id, String edit_so_luong) { if (ma_hd == null || edit_id == null || edit_so_luong == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tblDichVuDaDat dsdv = db.tblDichVuDaDats.Find(Int32.Parse(edit_id)); int sol = Int32.Parse(edit_so_luong); tblDichVu dv = db.tblDichVus.Find(dsdv.ma_dv); int del = (int)(sol - dsdv.so_luong); if (del > dv.ton_kho) { return(RedirectToAction("GoiDichVu", "HoaDon", new { id = ma_hd })); } else { dsdv.so_luong = sol; dv.ton_kho -= del; db.Entry(dsdv).State = EntityState.Modified; db.Entry(dv).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("GoiDichVu", "HoaDon", new { id = ma_hd })); }
public JsonResult SaveDataServiceNotImage(ServiceViewModel service) { bool status = false; string message = string.Empty; if (service.ID == 0) { tblDichVu dichVu = new tblDichVu(); dichVu.ma_dv = service.ID; dichVu.gia = service.Price; dichVu.ten_dv = service.Name; dichVu.ton_kho = service.Quantity; dichVu.trang_thai = true; dichVu.da_duoc_xoa = false; dichVu.don_vi = service.Type; dichVu.anh = null; db.tblDichVus.Add(dichVu); try { db.SaveChanges(); status = true; } catch (Exception ex) { status = false; message = ex.Message; } } else { //Đang cập nhật dữ liệu var entity = db.tblDichVus.Find(service.ID); entity.ten_dv = service.Name; entity.ton_kho = service.Quantity; entity.gia = service.Price; entity.don_vi = service.Type; //entity.CreatedDate = DateTime.Now; try { db.SaveChanges(); status = true; } catch (Exception ex) { status = false; message = ex.Message; } } return(Json(new { status = status, message = message })); }
public ActionResult DeleteConfirmed(int id) { try { tblDichVu tblDichVu = db.tblDichVus.Find(id); db.tblDichVus.Remove(tblDichVu); db.SaveChanges(); } catch { } return(RedirectToAction("Index")); }
// GET: DichVu/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tblDichVu tblDichVu = db.tblDichVus.Find(id); if (tblDichVu == null) { return(HttpNotFound()); } return(View(tblDichVu)); }
public ActionResult XoaDichVu(string ma_hd, string del_id) { int soluong = 0; tblDichVuDaDat dichVuDaDat = db.tblDichVuDaDats.Find(Int32.Parse(del_id)); soluong = (int)dichVuDaDat.so_luong; tblDichVu dichVu = db.tblDichVus.Where(x => x.ma_dv == dichVuDaDat.ma_dv).SingleOrDefault(); dichVu.ton_kho = dichVu.ton_kho + soluong; db.tblDichVuDaDats.Remove(dichVuDaDat); db.SaveChanges(); return(RedirectToAction("GoiDichVu", "HoaDon", new { id = ma_hd })); }
public ActionResult XacNhanGoiDichVu(string ma_hd, string ma_dv, string so_luong) { if (ma_hd == null || ma_dv == null || so_luong == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } int mahd = Int32.Parse(ma_hd); int madv = Int32.Parse(ma_dv); int soluong = Int32.Parse(so_luong); var danhSach = db.tblDichVuDaDats.Where(t => t.ma_hd == mahd).ToList(); try { bool check = false; foreach (var item in danhSach) { if (item.ma_dv == madv) { item.so_luong += soluong; check = true; break; } } if (!check) { tblDichVuDaDat dv = new tblDichVuDaDat(); dv.ma_hd = Int32.Parse(ma_hd); dv.ma_dv = Int32.Parse(ma_dv); dv.so_luong = Int32.Parse(so_luong); db.tblDichVuDaDats.Add(dv); } tblDichVu dichvu = db.tblDichVus.Find(madv); dichvu.ton_kho -= soluong; db.SaveChanges(); } catch { } return(RedirectToAction("GoiDichVu", "HoaDon", new { id = ma_hd })); }