public string CreateNewCarSegment(CarSegmentEntity cse) { var segmentAlreadyExistsInCountry = CarSegmentEntityCheck.DoesSegmentExistForCountry(DataContext, cse.CarSegmentName, cse.CountryId); if (segmentAlreadyExistsInCountry) { return(CarSegmentEntityCheck.SegmentAlreadyExistsForCountry); } var countryCode = DataContext.COUNTRies.Single(d => d.CountryId == cse.CountryId).country1; var newCarSegmentEnitiy = new CAR_SEGMENT { IsActive = true, car_segment1 = cse.CarSegmentName, country = countryCode, }; DataContext.CAR_SEGMENTs.InsertOnSubmit(newCarSegmentEnitiy); var returned = SubmitDbChanges(); return(returned); }
protected void btnSavePopup_Click(object sender, EventArgs e) { var cse = new CarSegmentEntity { Id = int.Parse(hfCarSegmentId.Value), CarSegmentName = tbCarSegment.Text, Active = cbActive.Checked }; SaveDataToDataBase(cse); }
public string UpdateCarSegment(CarSegmentEntity cse) { var carSegmentDbEntry = DataContext.CAR_SEGMENTs.Single(d => d.car_segment_id == cse.Id); var segmentAlreadyExistsInCountry = CarSegmentEntityCheck.DoesSegmentExistForCountry(DataContext, cse.CarSegmentName, carSegmentDbEntry.COUNTRy1.CountryId, cse.Id); if (segmentAlreadyExistsInCountry) { return(CarSegmentEntityCheck.SegmentAlreadyExistsForCountry); } carSegmentDbEntry.car_segment1 = cse.CarSegmentName; carSegmentDbEntry.IsActive = cse.Active; var returned = SubmitDbChanges(); return(returned); }
private void SaveDataToDataBase(CarSegmentEntity cse) { string message; if (cse.Id == 0) { cse.CountryId = int.Parse(ddlCountry.SelectedValue); using (var dataAccess = new MappingDeleteAndCreate()) { message = dataAccess.CreateNewCarSegment(cse); } } else { using (var dataAccess = new MappingSingleUpdate()) { message = dataAccess.UpdateCarSegment(cse); } } ProcessDatabaseReply(message, UpdateCarSegmentSuccess, AdminMappingEnum.CarSegment, lblMessage); }