public IHttpActionResult PutCuaHang(int id, CuaHang cuaHang) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != cuaHang.MaCH) { return(BadRequest()); } db.Entry(cuaHang).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CuaHangExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public static void SetCuaHang(CuaHang cuaHang) { try { string connectionString = String.Format("Server={0};Database={1};Integrated Security={2};", Properties.Resources.ServerName, Properties.Resources.DatabaseName, Properties.Resources.Integrated_Security ); using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand("SET_CUAHANG", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@MACH", cuaHang.MaCuaHang)); cmd.Parameters.Add(new SqlParameter("@TENCH", cuaHang.TenCuaHang)); cmd.Parameters.Add(new SqlParameter("@DIACHI", cuaHang.DiaChiCuaHang)); cmd.ExecuteNonQuery(); } } catch { throw; } }
public ActionResult DeleteConfirmed(int id) { CuaHang cuaHang = db.CuaHangs.Find(id); db.CuaHangs.Remove(cuaHang); db.SaveChanges(); return(RedirectToAction("Index")); }
public static int DeleteCH(CuaHang cuaHang) { SqlParameter[] para = new SqlParameter[] { new SqlParameter(@"MaCH", cuaHang.MaCH) }; return(DataProvider.NonQuery(Config.PROC_DELETE_CH, para)); }
public async Task <ActionResult> DeleteConfirmed(int id) { CuaHang cuaHang = await db.CuaHangs.FindAsync(id); db.CuaHangs.Remove(cuaHang); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "MaCuaHang,TenCuaHang,DiaChi,SoDienThoai")] CuaHang cuaHang) { if (ModelState.IsValid) { db.Entry(cuaHang).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(cuaHang)); }
public ActionResult Create([Bind(Include = "MaCuaHang,TenCuaHang,DiaChi,SoDienThoai")] CuaHang cuaHang) { if (ModelState.IsValid) { db.CuaHangs.Add(cuaHang); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(cuaHang)); }
public IHttpActionResult GetCuaHang(int id) { CuaHang cuaHang = db.CuaHangs.Find(id); if (cuaHang == null) { return(NotFound()); } return(Ok(cuaHang)); }
public static int UpdateCH(CuaHang cuaHang) { SqlParameter[] para = new SqlParameter[] { new SqlParameter(@"MaCH", cuaHang.MaCH), new SqlParameter(@"TenCH", cuaHang.TenCH), new SqlParameter(@"DiaChi", cuaHang.DiaChi), new SqlParameter(@"SDT", cuaHang.SDT), new SqlParameter(@"GhiChu", cuaHang.GhiChu) }; return(DataProvider.NonQuery(Config.PROC_UPDATE_CH, para)); }
public IHttpActionResult PostCuaHang(CuaHang cuaHang) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.CuaHangs.Add(cuaHang); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = cuaHang.MaCH }, cuaHang)); }
public async Task <IActionResult> Create(CuaHang model) { model.CuaHangId = RandomString.GenerateRandomString(_context.CuaHang.Select(a => a.CuaHangId)); if (ModelState.IsValid) { await _context.CuaHang.AddAsync(model); await _context.SaveChangesAsync(); } return(RedirectToAction("Index")); }
public async Task <ActionResult> Edit([Bind(Include = "MSCH,TenCH,MSLH,DiaChi,NvPhuTrach,SDT")] CuaHang cuaHang) { if (ModelState.IsValid) { db.Entry(cuaHang).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.MSLH = new SelectList(db.LoaiHangs, "MSLH", "TenLoaiHang", cuaHang.MSLH); ViewBag.NvPhuTrach = new SelectList(db.NVPhuTraches, "MSNV", "HoTen", cuaHang.NvPhuTrach); return(View(cuaHang)); }
public async Task <ActionResult> CH_Them([Bind(Include = "MSCH,TenCH,MSLH,DiaChi,NvPhuTrach,SDT")] CuaHang cuaHang) { if (ModelState.IsValid) { db.CuaHangs.Add(cuaHang); await db.SaveChangesAsync(); return(RedirectToAction("CuaHang")); } ViewBag.MSLH = new SelectList(db.LoaiHangs, "MSLH", "TenLoaiHang", cuaHang.MSLH); ViewBag.NvPhuTrach = new SelectList(db.NVPhuTraches, "MSNV", "HoTen", cuaHang.NvPhuTrach); return(View(cuaHang)); }
public IHttpActionResult DeleteCuaHang(int id) { CuaHang cuaHang = db.CuaHangs.Find(id); if (cuaHang == null) { return(NotFound()); } db.CuaHangs.Remove(cuaHang); db.SaveChanges(); return(Ok(cuaHang)); }
// GET: CuaHangs/Details/5 public async Task <ActionResult> Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CuaHang cuaHang = await db.CuaHangs.FindAsync(id); if (cuaHang == null) { return(HttpNotFound()); } return(View(cuaHang)); }
public async Task <IActionResult> ShopCreate(CuaHang model) { model.CuaHangId = RandomString.GenerateRandomString(_context.CuaHang.Select(o => o.CuaHangId)); model.TrangThai = "Hoạt động"; var userid = HttpContext.User.FindFirst(ClaimTypes.Sid).Value; var user = await _context.TaiKhoan.Where(o => o.TaiKhoanId == userid).SingleOrDefaultAsync(); user.MaCuaHang = model.CuaHangId; await _context.AddAsync(model); _context.Update(user); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); }
// GET: CuaHangs/Edit/5 public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CuaHang cuaHang = await db.CuaHangs.FindAsync(id); if (cuaHang == null) { return(HttpNotFound()); } ViewBag.MSLH = new SelectList(db.LoaiHangs, "MSLH", "TenLoaiHang", cuaHang.MSLH); ViewBag.NvPhuTrach = new SelectList(db.NVPhuTraches, "MSNV", "HoTen", cuaHang.NvPhuTrach); return(View(cuaHang)); }