public messageModel delete(cartypeModel 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_cartype_delete(value.id, userId); } result.status = "S"; result.message = ""; } catch (Exception ex) { result.status = "E"; result.message = ex.Message.ToString(); } return(result); }
public messageModel insert(cartypeModel 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_cartype_insert(value.name, value.desc, 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); }
// POST api/<controller> public HttpResponseMessage Post([FromBody] cartypeModel value) { if (value == null) { return(null); } JavaScriptSerializer js = new JavaScriptSerializer(); cartypeService service = new cartypeService(); 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); }
public IEnumerable <sp_cartype_search_Result> search(cartypeModel 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_cartype_search_Result> result = context.sp_cartype_search(value.name).AsEnumerable(); return(result); } catch (Exception ex) { throw new Exception(ex.Message); } }