public messageModel update(activityModel 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_masactivity_update(value.id, value.name, value.desc, userId); } result.status = "S"; result.message = ""; } catch (Exception ex) { result.status = "E"; result.message = ex.Message.ToString(); } return(result); }
public messageModel insert(activityModel 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_masactivity_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/activity public HttpResponseMessage Post([FromBody] activityModel value) { if (value == null) { return(null); } JavaScriptSerializer js = new JavaScriptSerializer(); activityService service = new activityService(); 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_masactivity_search_Result> search(activityModel 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_masactivity_search_Result> result = context.sp_masactivity_search(value.name).AsEnumerable(); return(result); } catch (Exception ex) { throw new Exception(ex.Message); } }