public IHttpActionResult GetVillageContact(int id) { VillageContact villageContact = db.VillageContacts.Find(id); if (villageContact == null) { return(NotFound()); } return(Ok(villageContact)); }
public HttpResponseMessage PutVillageContact(int id, VillageContact villageContact) { if (!ModelState.IsValid) { return((HttpResponseMessage)Request.CreateResponse(HttpStatusCode.BadRequest, new { data = new { string.Empty }, success = false, error = string.Empty })); } if (id != villageContact.Id) { return((HttpResponseMessage)Request.CreateResponse(HttpStatusCode.BadRequest, new { data = new { string.Empty }, success = false, error = string.Empty })); } //db.Entry(villageContact).State = EntityState.Modified; try { VillageContact VillageContactData = db.VillageContacts.Where(a => a.Id == villageContact.Id).FirstOrDefault(); VillageContactData.ContactName = villageContact.ContactName; VillageContactData.ContactNo = villageContact.ContactNo; VillageContactData.StateId = villageContact.StateId; VillageContactData.DistrictId = villageContact.DistrictId; VillageContactData.GrampanchayatId = villageContact.GrampanchayatId; VillageContactData.Designation = villageContact.Designation; VillageContactData.VillageId = villageContact.VillageId; VillageContactData.Active = villageContact.Active; if (villageContact.Active == true) { VillageContactData.UpdatedBy = villageContact.UpdatedBy; VillageContactData.UpdatedOn = villageContact.UpdatedOn; } else if (villageContact.Active == false) { VillageContactData.ActiveBy = villageContact.ActiveBy; VillageContactData.ActiveOn = villageContact.ActiveOn; } db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!VillageContactExists(id)) { return((HttpResponseMessage)Request.CreateResponse(HttpStatusCode.NotFound, new { data = new { string.Empty }, success = false, error = string.Empty })); } else { throw; } } return((HttpResponseMessage)Request.CreateResponse(HttpStatusCode.OK, new { data = new { villageContact }, success = true, error = string.Empty })); }
public IHttpActionResult DeleteVillageContact(int id) { VillageContact villageContact = db.VillageContacts.Find(id); if (villageContact == null) { return(NotFound()); } db.VillageContacts.Remove(villageContact); db.SaveChanges(); return(Ok(villageContact)); }
public HttpResponseMessage PostVillageContact(VillageContact villageContact) { if (!ModelState.IsValid) { return((HttpResponseMessage)Request.CreateResponse(HttpStatusCode.BadRequest, new { data = new { string.Empty }, success = false, error = string.Empty })); } int PhoneCount = db.VillageContacts.Where(a => a.ContactNo == villageContact.ContactNo).ToList().Count; if (PhoneCount > 0) { return((HttpResponseMessage)Request.CreateResponse(HttpStatusCode.OK, new { data = new { string.Empty }, success = false, error = "Phone Number already Exist" })); } db.VillageContacts.Add(villageContact); db.SaveChanges(); return((HttpResponseMessage)Request.CreateResponse(HttpStatusCode.OK, new { data = new { id = villageContact.Id }, success = true, error = string.Empty })); }