Exemplo n.º 1
0
        public async Task<HttpResponseMessage> PutUserType(UserType userType)
        {
            JObject result = new JObject();
            if (!ModelState.IsValid)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
            }
            
            db.Entry(userType).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserTypeExists(userType.TypeId))
                {
                    return Request.CreateResponse(HttpStatusCode.NotFound);
                }
                else
                {
                    throw;
                }
            }

            result = Methods.CustomResponseMessage(1, "Update user type successful!");
            return Request.CreateResponse(HttpStatusCode.OK, result);
        }
Exemplo n.º 2
0
        public async Task<HttpResponseMessage> PostUserType(UserType userType)
        {
            JObject result = new JObject();

            if (!ModelState.IsValid)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest,ModelState);
            }

            db.UserTypes.Add(userType);

            //try
            //{
            //    var name = new SqlParameter("@typeName", userType.TypeName);
            //    result = Methods.ExecQueryWithResult("viethung_paybayservice.sp_AddUserType",CommandType.StoredProcedure,ref Methods.err, name);
            //}
            //catch (Exception ex)
            //{
            //    throw;
            //}
           
            await db.SaveChangesAsync();

            //result = JObject.FromObject(userType);
            result = Methods.CustomResponseMessage(1, "Add user type successful!");
            //return CreatedAtRoute("Api", new { id = userType.TypeId }, userType);
            return Request.CreateResponse(HttpStatusCode.OK, result);
        }