public IHttpActionResult PostDM_HANG_SP(DM_NHOM_VTHH dM_NHOM_VTHH) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.DM_NHOM_VTHH.Add(dM_NHOM_VTHH); try { db.SaveChanges(); } catch (DbUpdateException) { if (DM_HANG_SPExists(dM_NHOM_VTHH.MA_NHOM_HANG_CHI_TIET)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = dM_NHOM_VTHH.MA_NHOM_HANG_CHI_TIET }, dM_NHOM_VTHH)); }
public IHttpActionResult PutDM_HANG_SP(string id, DM_NHOM_VTHH dM_NHOM_VTHH) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != dM_NHOM_VTHH.MA_NHOM_HANG_CHI_TIET) { return(BadRequest()); } db.Entry(dM_NHOM_VTHH).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!DM_HANG_SPExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult GetDM_HANG_SP(string id) { DM_NHOM_VTHH dM_HANG_SP = db.DM_NHOM_VTHH.Find(id); if (dM_HANG_SP == null) { return(NotFound()); } return(Ok(dM_HANG_SP)); }
public ActionResult Import_Hangsp(HttpPostedFileBase file) { try { if (Request != null) { HttpPostedFileBase filetonkho = Request.Files["UploadedFile"]; if ((filetonkho != null) && (filetonkho.ContentLength > 0) && !string.IsNullOrEmpty(filetonkho.FileName)) { string fileName = filetonkho.FileName; string fileContentType = filetonkho.ContentType; byte[] fileBytes = new byte[filetonkho.ContentLength]; var data = filetonkho.InputStream.Read(fileBytes, 0, Convert.ToInt32(filetonkho.ContentLength)); //var usersList = new List<Users>(); using (var package = new ExcelPackage(filetonkho.InputStream)) { var currentSheet = package.Workbook.Worksheets; var workSheet = currentSheet.First(); var noOfCol = workSheet.Dimension.End.Column; var noOfRow = workSheet.Dimension.End.Row; for (int rowIterator = 2; rowIterator <= noOfRow; rowIterator++) { DM_NHOM_VTHH hangsp = new DM_NHOM_VTHH(); hangsp.MA_NHOM_HANG_CHI_TIET = workSheet.Cells[rowIterator, 1].Value.ToString(); hangsp.CHUNG_LOAI_HANG = workSheet.Cells[rowIterator, 2].Value.ToString(); hangsp.MA_NHOM_HANG_CHA = workSheet.Cells[rowIterator, 3].Value.ToString(); hangsp.GHI_CHU = workSheet.Cells[rowIterator, 4].Value.ToString(); db.DM_NHOM_VTHH.Add(hangsp); db.SaveChanges(); so_dong_thanh_cong++; dong = rowIterator - 1; } } } } } catch (Exception Ex) { ViewBag.Error = " Đã xảy ra lỗi, Liên hệ ngay với admin. " + Environment.NewLine + " Thông tin chi tiết về lỗi:" + Environment.NewLine + Ex; ViewBag.Information = "Lỗi tại dòng thứ: " + dong; } finally { ViewBag.Message = "Đã import thành công " + so_dong_thanh_cong + " dòng"; } return(View("Import_Hanghoa")); }
public IHttpActionResult DeleteDM_HANG_SP(string id) { DM_NHOM_VTHH dM_HANG_SP = db.DM_NHOM_VTHH.Find(id); if (dM_HANG_SP == null) { return(NotFound()); } db.DM_NHOM_VTHH.Remove(dM_HANG_SP); db.SaveChanges(); return(Ok(dM_HANG_SP)); }