Exemple #1
0
        public IHttpActionResult PutCATALOG(int id, CATALOG cATALOG)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != cATALOG.CATA_ID)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #2
0
        public IHttpActionResult PutYEAR(int id, YEAR yEAR)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != yEAR.YEAR_ID)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult Create([FromBody] ClassModel model)
        {
            var objClass = new Class();

            objClass.Name = model.Name;
            DbSet.Classes.Add(objClass);
            DbSet.SaveChanges();
            return(Ok());
        }
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Student s = db.Student.Find(id);

            db.Student.Remove(s);
            db.SaveChanges();
            return(RedirectToAction("Index", "Students"));
        }
        public IHttpActionResult Create([FromBody] AddStudentViewModel model)
        {
            //if (!CheckRole("Admin"))
            //    return ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.Forbidden, ""));
            if (model == null)
            {
                model = new AddStudentViewModel();
                Validate(model);
            }
            //Validate
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var objectClass = DbSet.Classes.Find(model.ClassId);

            if (objectClass == null)
            {
                return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.NotFound, "CLASS_IS_NOT_FOUND")));
            }
            //Check duplicate student
            var checkDuplicate = DbSet.Students.Any(c => c.Code == model.Code);

            if (checkDuplicate)
            {
                return(Conflict());
            }
            var student = new Student();

            student.Code    = model.Code;
            student.Name    = model.Name;
            student.ClassId = model.ClassId;
            DbSet.Students.Add(student);
            DbSet.SaveChanges();
            return(Ok());
        }