コード例 #1
0
        public IHttpActionResult PutClassType(int id, ClassType classType)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != classType.ClassTypeID)
            {
                return BadRequest();
            }

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }
コード例 #2
0
        public ClassType CreateClassType(ClassType classType)
        {
            db.ClassTypes.Add(classType);
            db.SaveChanges();

            return classType;
        }
コード例 #3
0
        public IHttpActionResult PostClassType(ClassType classType)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.ClassTypes.Add(classType);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = classType.ClassTypeID }, classType);
        }
コード例 #4
0
        public void UpdateClassType(int id, ClassType classType)
        {
            db.Entry(classType).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }
        }
コード例 #5
0
        /// <summary>
        /// Converts this instance of <see cref="ClassTypeDTO"/> to an instance of <see cref="ClassType"/>.
        /// </summary>
        /// <param name="dto"><see cref="ClassTypeDTO"/> to convert.</param>
        public static ClassType ToEntity(this ClassTypeDTO dto)
        {
            if (dto == null) return null;

            var entity = new ClassType();

            entity.ClassTypeID = dto.ClassTypeID;
            entity.Name = dto.Name;
            entity.Code = dto.Code;
            entity.Description = dto.Description;

            dto.OnEntity(entity);

            return entity;
        }
コード例 #6
0
 /// <summary>
 /// Invoked when <see cref="ToEntity"/> operation is about to return.
 /// </summary>
 /// <param name="entity"><see cref="ClassType"/> converted from <see cref="ClassTypeDTO"/>.</param>
 static partial void OnEntity(this ClassTypeDTO dto, ClassType entity);