public bool UpdateCounty(CountyDto dto) { var county = this.db.Counties.FirstOrDefault(x => x.DeletedOn.HasValue == false && x.Id == dto.Id); if (county != null) { county.UpdatedOn = DateTime.Now; county.UpdatedBy = dto.UpdatedBy; county.Comment = dto.Comment; county.Name = dto.Name; county.CityId = dto.City.Id; this.db.SaveChanges(); return true; } return false; }
public bool AddCounty(CountyDto dto) { if (!this.db.Counties.Any(x => x.DeletedOn.HasValue == false && x.Name.Trim() == dto.Name.Trim())) { this.db.Counties.Add(new County { CreatedOn = DateTime.Now, UpdatedOn=DateTime.Now, UpdatedBy = dto.UpdatedBy, Comment = dto.Comment, Name = dto.Name, CityId = dto.City.Id }); this.db.SaveChanges(); return true; } return false; }