public HttpResponseMessage UpdateCampus(Campus campus)
        {
            if (campus != null)
            {
                dbcontext.Entry(campus).State = EntityState.Modified;
            }

            try
            {
                dbcontext.SaveChanges();
            }
            catch (Exception ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex);
            }


            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, campus);

            response.StatusCode = HttpStatusCode.Created;

            response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            return response;
        }
        public HttpResponseMessage CreateCampus(Campus campus)
        {
            var checkName = dbcontext.Campuses.Where(c_name => c_name.CampusName == campus.CampusName).Any();
            if (!checkName)
            {
                dbcontext.Campuses.Add(campus);
                try
                {
                    dbcontext.SaveChanges();
                }
                catch (Exception ex)
                {
                    return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex);
                }

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, campus);

                response.StatusCode = HttpStatusCode.Created;

                response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                return response;
            }
            HttpResponseMessage res = Request.CreateResponse(HttpStatusCode.OK, "Not Found");
            return res;
        }
        public HttpResponseMessage CreateCampus(Campus campus)
        {
            dbcontext.Campuses.Add(campus);
            try
            {
                dbcontext.SaveChanges();
            }
            catch (Exception ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex);
            }

            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, campus);

            response.StatusCode = HttpStatusCode.Created;

            response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            return response;
        }
        private void LoadCampus(HttpPostedFileBase file)
        {
            using (var package = new ExcelPackage(file.InputStream))
            {
                var campusWorkSheet = package.Workbook.Worksheets["campus"];
                var campusWorkSheetnoOfRow = campusWorkSheet.Dimension.End.Row;

                for (int rowIterator = 2; rowIterator <= campusWorkSheetnoOfRow; rowIterator++)
                {
                    Campus campus = new Campus();
                    campus.CampusId = int.Parse(campusWorkSheet.Cells[rowIterator, 1].Value.ToString());
                    campus.CampusName = campusWorkSheet.Cells[rowIterator, 2].Value.ToString();
                    campus.CampusAddress = campusWorkSheet.Cells[rowIterator, 3].Value.ToString();
                    campus.City = campusWorkSheet.Cells[rowIterator, 4].Value.ToString();
                    campus.Province = campusWorkSheet.Cells[rowIterator, 5].Value.ToString();
                    campus.PostalCode = campusWorkSheet.Cells[rowIterator, 6].Value.ToString();
                    campus.Phone = campusWorkSheet.Cells[rowIterator, 7].Value.ToString();
                    dbcontext.Campuses.Add(campus);
                    dbcontext.SaveChanges();
                }
            }
        }