Ejemplo n.º 1
0
        public IHttpActionResult PostCCTC_PHONG_BAN(CCTC_PHONG_BAN cCTC_PHONG_BAN)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.CCTC_PHONG_BAN.Add(cCTC_PHONG_BAN);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (CCTC_PHONG_BANExists(cCTC_PHONG_BAN.MA_PHONG_BAN))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = cCTC_PHONG_BAN.MA_PHONG_BAN }, cCTC_PHONG_BAN));
        }
Ejemplo n.º 2
0
        public IHttpActionResult PutCCTC_PHONG_BAN(string id, CCTC_PHONG_BAN cCTC_PHONG_BAN)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != cCTC_PHONG_BAN.MA_PHONG_BAN)
            {
                return(BadRequest());
            }

            db.Entry(cCTC_PHONG_BAN).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CCTC_PHONG_BANExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 3
0
        public ActionResult Import_PhongBan(FormCollection formCollection)
        {
            try
            {
                if (Request != null)
                {
                    HttpPostedFileBase file = Request.Files["UploadedFile"];
                    if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName))
                    {
                        string fileName        = file.FileName;
                        string fileContentType = file.ContentType;
                        byte[] fileBytes       = new byte[file.ContentLength];
                        var    data            = file.InputStream.Read(fileBytes, 0, Convert.ToInt32(file.ContentLength));
                        //var usersList = new List<Users>();
                        using (var package = new ExcelPackage(file.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++)
                            {
                                CCTC_PHONG_BAN phongban = new CCTC_PHONG_BAN();
                                phongban.MA_PHONG_BAN  = workSheet.Cells[rowIterator, 1].Value.ToString();
                                phongban.TEN_PHONG_BAN = workSheet.Cells[rowIterator, 2].Value.ToString();
                                if (workSheet.Cells[rowIterator, 3].Value != null)
                                {
                                    phongban.SDT = workSheet.Cells[rowIterator, 3].Value.ToString();
                                }
                                phongban.MA_CONG_TY = workSheet.Cells[rowIterator, 4].Value.ToString();
                                if (workSheet.Cells[rowIterator, 5].Value != null)
                                {
                                    phongban.GHI_CHU = workSheet.Cells[rowIterator, 5].Value.ToString();
                                }
                                db.CCTC_PHONG_BAN.Add(phongban);

                                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("Index"));
        }
        public IHttpActionResult GetCCTC_PHONG_BAN(string id)
        {
            CCTC_PHONG_BAN cCTC_PHONG_BAN = db.CCTC_PHONG_BAN.Find(id);

            if (cCTC_PHONG_BAN == null)
            {
                return(NotFound());
            }

            return(Ok(cCTC_PHONG_BAN));
        }
        public IHttpActionResult DeleteCCTC_PHONG_BAN(string id)
        {
            CCTC_PHONG_BAN cCTC_PHONG_BAN = db.CCTC_PHONG_BAN.Find(id);

            if (cCTC_PHONG_BAN == null)
            {
                return(NotFound());
            }

            db.CCTC_PHONG_BAN.Remove(cCTC_PHONG_BAN);
            db.SaveChanges();

            return(Ok(cCTC_PHONG_BAN));
        }