public bool checkIsManage(int id) { User user = findAnUser(id); if(user.RoleID == 2) { NetCafeService net_services = new NetCafeService(); List<NetCafe> netcafes = net_services.getAllNetCafe(); foreach(NetCafe net in netcafes) { if (net.SupervisorID == user.UserID) { return true; } } } return false; }
public string getNetCafes(string username, string password) { NetCafeService netService = new NetCafeService(); //JavaScriptSerializer json = new JavaScriptSerializer(); //string output = json.Serialize(service.getPcList(username, password, netCafeId)); //Newtonsoft.Json.Linq.JObject o = new Newtonsoft.Json.Linq.JObject(); //string json = JsonConvert.SerializeObject(service.getPcList(username, password, netCafeId)); List<NetCafe> netcafes = netService.getAllNetCafe(); List<NetCafeJSon> netjsons = new List<NetCafeJSon>(); // string json = JsonConvert.SerializeObject(pcs,Formatting.Indented); foreach (NetCafe net in netcafes) { NetCafeJSon netj = new NetCafeJSon(); netj.id = net.NetCafeID; netj.name = net.NetCafeName; netjsons.Add(netj); } var jsonSerialiser = new JavaScriptSerializer(); var json = jsonSerialiser.Serialize(netjsons); return json; }
public String add() { String name = Request.Params["name"]; String address = Request.Params["address"]; String supervisor = Request.Params["supervisor"]; String status = Request.Params["status"]; String phoneNumber = Request.Params["phoneNumber"]; String description = Request.Params["description"]; double locationX = Double.Parse(Request.Params["locationX"]); double locationY = Double.Parse(Request.Params["locationY"]); //valid du lieu NetCafeService netcafeService = new NetCafeService(); if (netcafeService.isExistWithName(name)) { return "Net cafe with this name is existed!"; } // Check supervisor da quan ly net nao hay chua else if (netcafeService.isExistWithSupervisor(int.Parse(supervisor))) { return "This supervisor has been managed a Netcafe already!"; } IRepository<NetCafe> repository = new NetCafeRepository(); NetCafe netcafe = new NetCafe(); netcafe.NetCafeName = name; netcafe.NetCafeAddress = address; netcafe.SupervisorID = int.Parse(supervisor); netcafe.NetCafeStatus = int.Parse(status); netcafe.NetCafePhoneNumber = phoneNumber; netcafe.NetCafeDescriptions = description; netcafe.LocationX = locationX; netcafe.LocationY = locationY; repository.Add(netcafe); return "true"; }
public String editNetCafe() { String idParam = Request.Params["id"]; String name = Request.Params["name"]; String address = Request.Params["address"]; String supervisor = Request.Params["supervisor"]; String status = Request.Params["status"]; String phoneNumber = Request.Params["phoneNumber"]; String description = Request.Params["description"]; IRepository<NetCafe> repository = new NetCafeRepository(); int id = int.Parse(idParam); NetCafe netcafe = repository.findById(id); netcafe.NetCafeName = name; netcafe.NetCafeAddress = address; netcafe.SupervisorID = int.Parse(supervisor); netcafe.NetCafeStatus = int.Parse(status); netcafe.NetCafePhoneNumber = phoneNumber; netcafe.NetCafeDescriptions = description; // kiem tra xem noi dung edit co hop le hay khong NetCafeService netcafeService = new NetCafeService(); if (!netcafeService.checkValidEdition(netcafe)) { return "false"; } repository.Update(netcafe); return "true"; }