public IHttpActionResult Post(int maTieuDe, int soLuong) { if (maTieuDe < 0 || soLuong < 0) { return(NotFound()); } var tieuDe = db.TieuDes.Find(maTieuDe); /* * var list = new List<Dia>(); * for (int i = 0; i < soLuong; i++) * { * var model = new Dia * { * MaTieuDe = tieuDe.MaTieuDe, * TinhTrangThue = TinhTrangThueCollection.CoSan * }; * list.Add(model); * } */ var model = new Dia { MaTieuDe = tieuDe.MaTieuDe, TinhTrangThue = TinhTrangThueCollection.CoSan }; var result = db.Dias.Add(model); db.SaveChanges(); return(Json(result)); }
public IHttpActionResult PostThueDia(int maKhachHang, int maDia) { string err = null; var dia = db.Dias.Find(maDia); var tieuDe = db.TieuDes.Find(dia.MaTieuDe); var soNgayChoThueMoiDia = db.DanhMucs.Find(tieuDe.MaDanhMuc).ThoiGianThue; var kh = db.KhachHangs.Where(x => x.MaKhachHang == maKhachHang).FirstOrDefault(); if (dia == null || kh == null) { err = "Lỗi"; return(Json(err)); } var model = new DsChoThue { MaKhachHang = maKhachHang, MaDia = maDia, NgayThue = DateTime.Now, NgayPhaiTra = DateTime.Now.AddDays(soNgayChoThueMoiDia), NgayThucTra = new DateTime(1753, 1, 1), Dia = dia, KhachHang = kh }; db.DsChoThue.Add(model); dia.TinhTrangThue = Models.Enums.TinhTrangThueCollection.DangThue; db.Entry(dia).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(Json(model)); }
public IHttpActionResult Post(KhachHang kh) { var model = new KhachHang { Ten = kh.Ten, DiaChi = kh.DiaChi, SoDienThoai = kh.SoDienThoai, }; db.KhachHangs.Add(kh); db.SaveChanges(); return(Ok()); }
public IHttpActionResult PostThanhToan(DsChoThue entity) { string err = null; if (entity == null) { err = "Không tìm thấy dữ liệu"; return(Json(err)); } var model = db.DsChoThue.Where(x => x.MaKhachHang == entity.MaKhachHang && x.MaDia == x.MaDia && x.NgayThue.CompareTo(entity.NgayThue) == 0).FirstOrDefault(); model.DaThanhToanPhiTre = true; db.Entry(model).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(Ok()); }
public IHttpActionResult PostDanhMuc(DanhMuc danhMuc) { if (!ModelState.IsValid) { return(BadRequest()); } db.DanhMucs.Add(danhMuc); db.SaveChanges(); return(Json(danhMuc)); }
public IHttpActionResult Post(int maKh, int maTieuDe) { string err = ""; var tieuDe = db.TieuDes.Find(maTieuDe); var kh = db.KhachHangs.Find(maKh); if (tieuDe == null || kh == null) { err = "Không tìm thấy dữ liệu"; return(Json(err)); } if (maTieuDe < 0 || maKh < 0) { return(NotFound()); } int thuTu; try { thuTu = db.DsDatHang.Where(x => x.MaTieuDe == maTieuDe).Max(x => x.ThuTu) + 1; }catch (Exception) { thuTu = 1; } var model = new DsDatHang { MaKhachHang = maKh, MaTieuDe = maTieuDe, ThuTu = thuTu, TinhTrang = TinhTrangDatHangCollection.DangCho }; try { model = db.DsDatHang.Add(model); db.SaveChanges(); } catch (Exception) { model = null; return(Json(model)); } return(Json(model)); }
public IHttpActionResult Post(TieuDe t) { db.TieuDes.Add(t); db.SaveChanges(); return(Ok()); }