public UpdateDistrictViewModel GetDistrictForUpdateById(short DistrictRowID) { try { UpdateDistrictViewModel model = new UpdateDistrictViewModel(); var entity = db.MasterDistricts.Find(DistrictRowID); if (entity != null) { model.DistrictRowID = entity.DistrictRowID; model.DistrictName = entity.DistrictName; model.StateRowID = entity.StateRowID; model.CountryRowID = entity.CountryRowID; } else { throw new Exception("Invalid Id!"); } return(model); } catch (Exception) { throw; } }
public void UpdateDistrict(UpdateDistrictViewModel model) { try { if (model != null && model.DistrictRowID > 0) { db.MasterDistricts.Single(b => b.DistrictRowID == model.DistrictRowID).DistrictName = model.DistrictName; db.MasterDistricts.Single(b => b.DistrictRowID == model.DistrictRowID).StateRowID = model.StateRowID; db.MasterDistricts.Single(b => b.DistrictRowID == model.DistrictRowID).CountryRowID = model.CountryRowID; } else { throw new Exception("District could not be blank!"); } } catch (Exception) { throw; } }