public void UpdateAreaDetail(Area newAreaDetail, string originalAreaCode, string loggedInUser) { try { var areaDetail = GetAreaDetail(originalAreaCode); areaDetail.AreaCode = newAreaDetail.AreaCode; areaDetail.AreaShortName = newAreaDetail.AreaShortName; areaDetail.AreaName = newAreaDetail.AreaName; areaDetail.AddressLine1 = newAreaDetail.AddressLine1; areaDetail.AddressLine2 = newAreaDetail.AddressLine2; areaDetail.AddressLine3 = newAreaDetail.AddressLine3; areaDetail.AddressLine4 = newAreaDetail.AddressLine4; areaDetail.IsCurrent = newAreaDetail.IsCurrent; areaDetail.Postcode = newAreaDetail.Postcode; transaction = CurrentSession.BeginTransaction(); CurrentSession.Save(areaDetail); if (areaDetail.AreaCode != originalAreaCode) { // Update other tables with new areacode /* Columns that are updated automatically by foreign key cascade updates: * L_AreaLinks.areacode * GIS_Postcodes.areacode * L_AreaMapping.ChildLevelGeographyCode * CoreDataSet.AreaCode */ foreach (var coreDataSetArchive in GetCoreDataArchives(originalAreaCode)) { coreDataSetArchive.AreaCode = areaDetail.AreaCode; CurrentSession.Save(coreDataSetArchive); } CurrentSession.GetNamedQuery("Update_AreaMapping") .SetParameter("AreaCode", areaDetail.AreaCode) .SetParameter("OriginalAreaCode", originalAreaCode) .ExecuteUpdate(); // Insert Audit CurrentSession.GetNamedQuery("Insert_FPMAreaAudit") .SetParameter("AreaCode", areaDetail.AreaCode) .SetParameter("AreaName", areaDetail.AreaName) .SetParameter("AreaShortName", areaDetail.AreaShortName) .SetParameter("AreaTypeId", areaDetail.AreaTypeId) .SetParameter("AddressLine1", areaDetail.AddressLine1) .SetParameter("AddressLine2", areaDetail.AddressLine2) .SetParameter("AddressLine3", areaDetail.AddressLine3) .SetParameter("AddressLine4", areaDetail.AddressLine4) .SetParameter("IsCurrent", areaDetail.IsCurrent) .SetParameter("Postcode", areaDetail.Postcode) .SetParameter("ChangedAreaCode", areaDetail.AreaCode == originalAreaCode ? (object)DBNull.Value : areaDetail.AreaCode) .SetParameter("UserName", loggedInUser) .SetParameter("Timestamp", DateTime.Now) .ExecuteUpdate(); } transaction.Commit(); } catch (Exception exception) { HandleException(exception); } }
public ActionResult UpdateArea(AreaDetail model, string originalAreaCode) { var areaDetail = new Area { AreaCode = model.AreaDetails.AreaCode, AreaTypeId = model.AreaDetails.AreaTypeId, AreaName = model.AreaDetails.AreaName, AreaShortName = model.AreaDetails.AreaShortName, AddressLine1 = model.AreaDetails.AddressLine1, AddressLine2 = model.AreaDetails.AddressLine2, AddressLine3 = model.AreaDetails.AddressLine3, AddressLine4 = model.AreaDetails.AddressLine4, Postcode = model.AreaDetails.Postcode, IsCurrent = model.AreaDetails.IsCurrent }; _coreDataRepository.UpdateAreaDetail(areaDetail, originalAreaCode, UserDetails.CurrentUser().Name); return RedirectToAction("SearchAreas", new {areaTypeId = model.SearchAreaTypeId, searchText = model.SearchText}); }