Exemplo n.º 1
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));
        }
Exemplo n.º 2
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)));
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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"));
 }
Exemplo n.º 5
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"));
 }
Exemplo n.º 6
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));
        }