public HttpResponseMessage GetUser(int id) { //User user = db.Users.Find(id); //if (user == null) //{ // return (HttpResponseMessage)Request.CreateResponse(HttpStatusCode.NotFound, new { data = string.Empty, success = false, error = string.Empty }); //} var Users = from User in db.Users join Gender in db.Genders on User.Gender equals Gender.Id into GenderNew from Gender in GenderNew.DefaultIfEmpty() join State in db.States on User.State equals State.Id into StateNew from State in StateNew.DefaultIfEmpty() join Role in db.Roles on User.Role equals Role.Id into RoleNew from Role in RoleNew.DefaultIfEmpty() join Lang in db.Languages on User.Language equals Lang.Id into LangNew from Lang in LangNew.DefaultIfEmpty() join District in db.Districts on User.District equals District.Id into DistrictNew from District in DistrictNew.DefaultIfEmpty() join Village in db.Villages on User.Village equals Village.Id into VillageNew from Village in VillageNew.DefaultIfEmpty() join Grampanchayat in db.Grampanchayats on User.Grampanchayat equals Grampanchayat.Id into GrampanchayatNew from Grampanchayat in GrampanchayatNew.DefaultIfEmpty() where User.Id == id select new { User.Id, User.UserId, User.Name, User.PhoneNumber, User.Age, User.Gender, Gender.GenderName, User.State, State.StateName, User.District, District.DistrictName, User.Village, Village.VillageName, User.Grampanchayat, Grampanchayat.GrampanchayatName, User.Aadhaar, User.Role, Role.RoleName, User.Language, Lang.LanguageName, User.IMEI1, User.IMEI2, User.FCMToken, User.Active, User.ImagePath }; return((HttpResponseMessage)Request.CreateResponse(HttpStatusCode.OK, new { data = new { Users }, success = true, error = string.Empty })); }
// GET: api/Users //public IQueryable<User> GetUsers() //{ // return db.Users; //} // GET: api/Users public HttpResponseMessage GetAllUsers() { try { //int value = 1 / int.Parse("0"); var result = from User in db.Users join Gender in db.Genders on User.Gender equals Gender.Id into GenderNew from Gender in GenderNew.DefaultIfEmpty() join State in db.States on User.State equals State.Id into StateNew from State in StateNew.DefaultIfEmpty() join Role in db.Roles on User.Role equals Role.Id into RoleNew from Role in RoleNew.DefaultIfEmpty() join Lang in db.Languages on User.Language equals Lang.Id into LangNew from Lang in LangNew.DefaultIfEmpty() join District in db.Districts on User.District equals District.Id into DistrictNew from District in DistrictNew.DefaultIfEmpty() join Village in db.Villages on User.Village equals Village.Id into VillageNew from Village in VillageNew.DefaultIfEmpty() join Grampanchayat in db.Grampanchayats on User.Grampanchayat equals Grampanchayat.Id into GrampanchayatNew from Grampanchayat in GrampanchayatNew.DefaultIfEmpty() select new { User.Id, User.UserId, User.Name, User.PhoneNumber, User.Age, User.Gender, Gender.GenderName, User.State, State.StateName, User.District, District.DistrictName, User.Village, Village.VillageName, User.Grampanchayat, Grampanchayat.GrampanchayatName, User.Aadhaar, User.Role, Role.RoleName, User.Language, Lang.LanguageName, User.IMEI1, User.IMEI2, User.FCMToken, User.Active, User.ImagePath }; return((HttpResponseMessage)Request.CreateResponse(HttpStatusCode.OK, new { data = result, success = true, error = string.Empty })); } catch (Exception ex) { long ExceptionId = comObj.SendExcepToDB(ex); Tbl_ExceptionLogging tbl_ExceptionLogging = db.Tbl_ExceptionLogging.Find(ExceptionId); return((HttpResponseMessage)Request.CreateResponse(HttpStatusCode.BadRequest, new { data = new { tbl_ExceptionLogging }, success = false, error = string.Empty })); } }