// POST: api/Module public IEnumerable <string> Post([FromBody] DataModel.Module module) { try { if (ModelState.IsValid) { string idm = Guid.NewGuid().ToString(); var module1 = new DataModel.Module { Id = idm, Name = "UserManagement1" }; BusinessProcess.ModuleManager mm = new BusinessProcess.ModuleManager(); mm.Add(module); return(new string[] { module.Id, module.Name }); //return "Success"; } else { return(new string[] { "Info", "Fail" }); } } catch (Exception err) { return(new string[] { "Info" + err }); } }
public IEnumerable <DataModel.Module> GetAll() { //IEnumerable<DataModel.Module> q = x.Query<DataModel.Module>("SELECT TOP (1000) [idmodule] Id,[module] Name FROM [tmodule]").ToList(); //var items = x.Query("SELECT TOP (1000) [idmodule] Id,[module] Name FROM [tmodule]").ToList(); var q = from item in x.Query("SELECT TOP (1000) [idmodule] Id,[module] Name FROM [tmodule]") select new DataModel.Module { Id = item.Id.ToString(), Name = item.Name }; DataModel.Module[] data = new DataModel.Module[] { new DataModel.Module { Id = "1231", Name = "test" }, new DataModel.Module { Id = "131", Name = "test1" }, new DataModel.Module { Id = "121", Name = "test2" } }; var c = from a in data select new { a.Id, test = "aaa" + a.Name }; return(q); }
//public IHttpActionResult Get() //{ // IList<DataModel.Module> students = null; // BusinessProcess.ModuleManager mm = new BusinessProcess.ModuleManager(); // var x = mm.GetAll(); // foreach(var item in x) // { // students.Add(new DataModel.Module // { // Id = item.Id, // Name = item.Name // }); // } // if (students.Count == 0) // { // return NotFound(); // } // return Ok(students); //} // GET: api/Module/5 public DataModel.Module Get(string id) { DataModel.Module data = new DataModel.Module { Id = id, Name = "module1" }; return(data); }
public void Test_Update_Module_Data() { /*Initialize Data*/ string idm = "41DDD5EB-D8A8-47C7-9243-F0E22D256093"; var module = new DataModel.Module { Id = idm, Name = "User" }; BusinessProcess.ModuleManager mm = new BusinessProcess.ModuleManager(); mm.Update(idm, module); }
public void Test_Delete_Module_Data() { /*Initialize Data*/ string idm = "E43050CB-7443-4745-8229-931EDE7BB885"; var module = new DataModel.Module { Id = idm, Name = "UserManagement1" }; BusinessProcess.ModuleManager mm = new BusinessProcess.ModuleManager(); mm.Delete(module); }
public void Test_Input_Module_Data() { /*Initialize Data*/ string idm = Guid.NewGuid().ToString(); var module = new DataModel.Module { Id = idm, Name = "UserManagement3" }; BusinessProcess.ModuleManager mm = new BusinessProcess.ModuleManager(); mm.Add(module); }
// PUT: api/Module/5 public IEnumerable <string> Put(string id, DataModel.Module module) { try { BusinessProcess.ModuleManager mm = new BusinessProcess.ModuleManager(); mm.Update(id, module); return(new string[] { "Info" }); } catch (Exception err) { return(new string[] { "Info", err.ToString() }); } }
public string Delete(DataModel.Module Items) { try { string id = Items.Id; x.Execute("DELETE FROM [tmodule] WHERE [idmodule] = @Id", new { Id = id }); return("Success"); } catch (Exception err) { return("info : " + err); } }
public int Search(DataModel.Module Items) { try { string id = Items.Id; string module = Items.Name; IEnumerable <DataModel.Module> q = x.Query <DataModel.Module>("SELECT * FROM [tmodule] WHERE [idmodule] = @Id", new { Id = id }).ToList(); return(q.Count()); } catch (Exception err) { return(0); } }
public string Add(DataModel.Module Items) { try { string id = Guid.NewGuid().ToString(); string name = Items.Name; x.Execute("INSERT INTO [tmodule] ([idmodule], [module]) VALUES (@Id ,@Name)", new { Id = id, Name = name }); return("Success"); } catch (Exception err) { return("info : " + err); } }
public string Update(string id, DataModel.Module Items) { try { string module = Items.Name; int c = Search(Items); if (c > 0) { x.Execute(@"UPDATE [tmodule] SET module = @Module WHERE idmodule = @Id", new { Id = id, Module = module }); return("Success"); } else { return("Fail"); } }catch (Exception err) { return("error : " + err); } }
// DELETE: api/Module/5 public IEnumerable <string> Delete([FromBody] DataModel.Module module) { try { if (ModelState.IsValid) { BusinessProcess.ModuleManager mm = new BusinessProcess.ModuleManager(); mm.Delete(module); return(new string[] { module.Id, module.Name }); //return "Success"; } else { return(new string[] { "Info", "Fail" }); } } catch (Exception err) { return(new string[] { "Info" + err }); } }