Ejemplo n.º 1
0
        public async Task <IHttpActionResult> putUser(int id, DTOusertype dtousertype)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != dtousertype.UserType_ID)
            {
                return(BadRequest());
            }

            var putUsertype = db.usertypes.Single(e => e.UserType_ID == id);

            db.Entry(EntityMapper.updateEntity(putUsertype, dtousertype)).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!userExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 2
0
        public async Task <DTOusertype> Postusertype(DTOusertype newDTO)
        {
            usertype newProd = EntityMapper.updateEntity(null, newDTO);

            db.usertypes.Add(newProd);
            await db.SaveChangesAsync();

            return(newDTO);
        }
Ejemplo n.º 3
0
        public async Task <IHttpActionResult> Putusertype(int ID, DTOusertype editedDTO)
        {
            usertype toUpdate = db.usertypes.Find(ID);

            toUpdate = EntityMapper.updateEntity(toUpdate, editedDTO);
            db.Entry(toUpdate).State = EntityState.Modified;
            await db.SaveChangesAsync();

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 4
0
        public async Task <IHttpActionResult> getUserType(int id)
        {
            DTOusertype toReturn = new DTOusertype(await db.usertypes.FindAsync(id));

            if (toReturn == null)
            {
                return(NotFound());
            }
            return(CreatedAtRoute("DefaultApi", new { id = toReturn.UserType_ID }, toReturn));
        }
Ejemplo n.º 5
0
        public async Task <IHttpActionResult> postUserType(DTOusertype dtoUsertype)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.usertypes.Add(EntityMapper.updateEntity(null, dtoUsertype));
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = dtoUsertype.UserType_ID }, dtoUsertype));
        }
Ejemplo n.º 6
0
        public static usertype updateEntity(usertype entityObjct, DTOusertype dto)
        {
            if (entityObjct == null)
            {
                entityObjct = new usertype();
            }

            entityObjct.UserType_ID         = dto.UserType_ID;
            entityObjct.UserTypeDescription = dto.UserTypeDescription;

            return(entityObjct);
        }
Ejemplo n.º 7
0
        public async Task <IHttpActionResult> deleteUserType(int id)
        {
            var userTypeToDel = db.usertypes.SingleOrDefault(x => x.UserType_ID == id);

            if (userTypeToDel == null)
            {
                return(NotFound());
            }

            DTOusertype temp = new DTOusertype(userTypeToDel);

            db.usertypes.Remove(userTypeToDel);
            await db.SaveChangesAsync();

            return(Ok(temp));
        }