Ejemplo n.º 1
0
        public messageModel update(hardwareModel value)
        {
            messageModel result = new messageModel();

            try
            {
                using (var context = new StandardCanEntities())
                {
                    if (String.IsNullOrEmpty(value.user_id))
                    {
                        throw new Exception("Unauthorized Access");
                    }
                    var userId = JwtHelper.GetUserIdFromToken(value.user_id);
                    if (String.IsNullOrEmpty(userId))
                    {
                        throw new Exception("Unauthorized Access");
                    }
                    int ret = context.sp_hardware_update(value.id, value.name, userId);
                }

                result.status  = "S";
                result.message = "";
            }
            catch (Exception ex)
            {
                result.status  = "E";
                result.message = ex.Message.ToString();
            }

            return(result);
        }
Ejemplo n.º 2
0
        public messageModel insert(hardwareModel value)
        {
            messageModel result = new messageModel();

            try
            {
                System.Data.Entity.Core.Objects.ObjectParameter myOutputParamInt = new System.Data.Entity.Core.Objects.ObjectParameter("r_id", typeof(Int32));
                using (var context = new StandardCanEntities())
                {
                    if (String.IsNullOrEmpty(value.user_id))
                    {
                        throw new Exception("Unauthorized Access");
                    }
                    var userId = JwtHelper.GetUserIdFromToken(value.user_id);
                    if (String.IsNullOrEmpty(userId))
                    {
                        throw new Exception("Unauthorized Access");
                    }
                    int ret = context.sp_hardware_insert(value.name, userId, myOutputParamInt);
                }

                if (myOutputParamInt.Value != null)
                {
                    int r_id = Convert.ToInt32(myOutputParamInt.Value);
                    result.status  = "S";
                    result.message = "";
                    result.value   = r_id.ToString();
                }
                else
                {
                    result.status  = "E";
                    result.message = "";
                }
            }
            catch (Exception ex)
            {
                result.status  = "E";
                result.message = ex.Message.ToString();
            }

            return(result);
        }
Ejemplo n.º 3
0
        // POST: api/hardware
        public HttpResponseMessage Post([FromBody] hardwareModel value)
        {
            if (value == null)
            {
                return(null);
            }
            JavaScriptSerializer js = new JavaScriptSerializer();

            hardwareService     service  = new hardwareService();
            HttpResponseMessage response = null;
            Object result = null;

            switch (value.method)
            {
            case "search":
                result = service.search(value);
                break;

            case "insert":
                result = service.insert(value);
                break;

            case "update":
                result = service.update(value);
                break;

            case "delete":
                result = service.delete(value);
                break;

            default:
                break;
            }


            string json = js.Serialize(result);

            response         = Request.CreateResponse(HttpStatusCode.OK);
            response.Content = new StringContent(json, System.Text.Encoding.UTF8, "application/json");
            return(response);
        }
Ejemplo n.º 4
0
 public IEnumerable <sp_hardware_search_Result> search(hardwareModel value)
 {
     try
     {
         if (String.IsNullOrEmpty(value.user_id))
         {
             throw new Exception("Unauthorized Access");
         }
         var userId = JwtHelper.GetUserIdFromToken(value.user_id);
         if (String.IsNullOrEmpty(userId))
         {
             throw new Exception("Unauthorized Access");
         }
         StandardCanEntities context = new StandardCanEntities();
         IEnumerable <sp_hardware_search_Result> result = context.sp_hardware_search(value.name).AsEnumerable();
         return(result);
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }