예제 #1
0
        public ActionResult Create(StudentModel model)
        {
            if (!ModelState.IsValid)
            {
                return(ReturnJson(false));
            }

            if (model.PhotoFile != null)
            {
                var PhotoPath = HttpContext.Server.MapPath("~/Files/Stud");
                if (!Directory.Exists(PhotoPath))
                {
                    Directory.CreateDirectory(PhotoPath);
                }
                var PhotoFileName = Path.Combine(PhotoPath, model.PhotoFile.FileName);
                if (System.IO.File.Exists(PhotoFileName))
                {
                    System.IO.File.Delete(PhotoFileName);
                }
                model.PhotoFile.SaveAs(PhotoFileName);
                model.Info.Photo = model.PhotoFile.FileName;
            }

            return(ReturnJson(StudentBiz.AddNew(model.Info)));
        }
예제 #2
0
        // PUT api/default1/5
        public HttpResponseMessage Put(int id, StudentInfo info)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            var _info = StudentBiz.GetInfo(id);

            if (id != _info.Sn)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            _info.Name   = info.Name;
            _info.Hight  = info.Hight;
            _info.Weight = info.Weight;
            _info.Memo   = info.Memo;

            var result = StudentBiz.Update(_info);

            if (!result)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
예제 #3
0
        public ActionResult Edit(StudentModel model)
        {
            if (!ModelState.IsValid)
            {
                return(ReturnJson(false));
            }
            var info = StudentBiz.GetInfo(model.Info.Sn);

            info.Sn       = model.Info.Sn;
            info.Name     = model.Info.Name;
            info.ClassId  = model.Info.ClassId;
            info.Hight    = model.Info.Hight;
            info.Weight   = model.Info.Weight;
            info.Birthday = model.Info.Birthday;
            if (model.PhotoFile != null)
            {
                var PhotoPath = HttpContext.Server.MapPath("~/Files/Stud");
                if (!Directory.Exists(PhotoPath))
                {
                    Directory.CreateDirectory(PhotoPath);
                }
                var PhotoFileName = Path.Combine(PhotoPath, model.PhotoFile.FileName);
                if (System.IO.File.Exists(PhotoFileName))
                {
                    System.IO.File.Delete(PhotoFileName);
                }
                model.PhotoFile.SaveAs(PhotoFileName);
                info.Photo = model.PhotoFile.FileName;
            }
            info.Memo = model.Info.Memo;
            return(ReturnJson(StudentBiz.Update(info)));
        }
예제 #4
0
        // GET api/default1/5
        public StudentInfo Get(int id)
        {
            var info = StudentBiz.GetInfo(id);

            if (info == null)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
            }
            return(info);
        }
예제 #5
0
 public ActionResult Details(int?Sn)
 {
     if (Sn != null)
     {
         StudentModel model = new StudentModel();
         model.Info = StudentBiz.GetInfo((int)Sn);
         return(View(model));
     }
     return(RedirectToAction("Index"));
 }
예제 #6
0
 public ActionResult Edit(int?id)
 {
     if (id != null)
     {
         var model = new StudentModel();
         model.Info = StudentBiz.GetInfo((int)id);
         bindEdit(model);
         return(PartialView(model));
     }
     return(Content("error"));
 }
예제 #7
0
 public ActionResult Delete(int id)
 {
     if (StudentBiz.Del(id))
     {
         return(new HttpStatusCodeResult(System.Net.HttpStatusCode.OK));
     }
     else
     {
         return(new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest));
     }
 }
예제 #8
0
 public ActionResult Delete(int Sn)
 {
     if (StudentBiz.Del(Sn))
     {
         return(RedirectToAction("Index"));
     }
     else
     {
         return(JavaScript("alert('刪除失敗');"));
     }
 }
예제 #9
0
        public ActionResult Index()
        {
            var model = new StudentListModel();
            var list  = StudentBiz.QueryData(" ", " ");

            int currentPageIndex = 0;

            model.List = new MvcPaging.PagedList <StudentInfo>(list, currentPageIndex, 2);

            bindList(model);

            return(View(model));
        }
예제 #10
0
        public ActionResult ClassStud(string id)
        {
            //var defItem = new SelectListItem { Text = "請選擇", Value = "" };

            var list = StudentBiz.ClassData(id).Select(s => new SelectListItem
            {
                Value = s.Sn.ToString(),
                Text  = s.Name
            }).ToList();

            //list.Insert(0, defItem);

            return(Json(list, JsonRequestBehavior.AllowGet));
        }
예제 #11
0
        // POST api/default1
        public HttpResponseMessage Post(StudentInfo info)
        {
            if (ModelState.IsValid)
            {
                var result = StudentBiz.AddNew(info);

                if (result)
                {
                    HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, info);
                    response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = info.Sn }));
                    return(response);
                }
            }

            return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
        }
예제 #12
0
        // DELETE api/default1/5
        public HttpResponseMessage Delete(int id)
        {
            var info = StudentBiz.GetInfo(id);

            if (info.Sn == 0)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            bool result = StudentBiz.Del(id);

            if (!result)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "delete error"));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, info));
        }
예제 #13
0
        public ActionResult Index(int?page)
        {
            StudentListModel model = new StudentListModel();

            var list = StudentBiz.GetAll();

            int currentPageIndex = page.HasValue ? page.Value - 1 : 0;
            int pageSize         = 2;

            while (currentPageIndex > 0 &&
                   list.Count <= currentPageIndex * pageSize)
            {
                currentPageIndex--;
            }

            model.List = new MvcPaging.PagedList <StudentInfo>(list, currentPageIndex, pageSize);

            bindList(model);

            return(View(model));
        }
예제 #14
0
        void bind(MyTestModel model)
        {
            model.Select1 = StudentBiz.GetAll().Select(s => new SelectListItem
            {
                Value = s.Sn.ToString(),
                Text  = s.Name
            });

            model.Select2 = StudentBiz.GetAll().Select(s => new SelectListItem
            {
                Value = s.Sn.ToString(),
                Text  = s.Name
            });

            //班級
            model.ClassSelect = ClassMBiz.GetAll().Select(s => new SelectListItem
            {
                Value = s.Id.ToString(),
                Text  = s.Name
            });

            if (!string.IsNullOrWhiteSpace(model.ClassId))
            {
                var list = StudentBiz.ClassData(model.ClassId).Select(s => new SelectListItem
                {
                    Value = s.Sn.ToString(),
                    Text  = s.Name
                });

                model.StudentSelect = list;
            }
            else
            {
                model.StudentSelect = new List <SelectListItem>();
            }
        }
예제 #15
0
        public ActionResult Index(StudentListModel model, string sortCol, bool?sortDesc, int?page)
        {
            model.Name    = string.IsNullOrWhiteSpace(model.Name) ? "" : model.Name;
            model.ClassId = string.IsNullOrWhiteSpace(model.ClassId) ? "" : model.ClassId;
            var list = StudentBiz.QueryData(model.ClassId, model.Name);

            if (!string.IsNullOrWhiteSpace(sortCol))
            {
                ListSort <StudentInfo> .GetList(list, sortCol, sortDesc.Value);
            }

            int currentPageIndex = page.HasValue ? page.Value - 1 : 0;
            int pageSize         = 2;

            while (currentPageIndex > 0 &&
                   list.Count <= currentPageIndex * pageSize)
            {
                currentPageIndex--;
            }

            model.List = new MvcPaging.PagedList <StudentInfo>(list, currentPageIndex, pageSize);

            return(PartialView("List", model.List));
        }
예제 #16
0
 // GET api/default1
 public IEnumerable <StudentInfo> Get()
 {
     return(StudentBiz.GetAll());
 }