public ActionResult AddEditStation(long?stationId, string copyInd) { var viewModel = new AddEditStationViewModel(); if (stationId.HasValue) { var drStation = CRCDataAccess.GetStation(stationId.Value); drStation.MapTo(viewModel); viewModel.EnabledInd = !(drStation["DisabledDate"] is DateTime); viewModel.CopyInd = copyInd.Equals("Y", StringComparison.OrdinalIgnoreCase) ? "Y" : "N"; using (var dtStationAffiliates = CRCDataAccess.GetStationAffiliates(stationId.Value)) { viewModel.AffiliateIds = dtStationAffiliates.AsEnumerable().Select(row => (long)row["AffiliateId"]); } } else { //Set default values when adding a new station viewModel.EnabledInd = true; viewModel.MemberStatusId = InfLookupHelper.ReverseLookup("MemberStatus", "MemberStatusName", "Full"); viewModel.MinorityStatusId = InfLookupHelper.ReverseLookup("MinorityStatus", "MinorityStatusName", "None"); viewModel.StatusDate = DateTime.UtcNow.AddHours(InfDate.GetUtcOffSet); //viewModel.TimeZoneId = InfLookupHelper.ReverseLookup("TimeZone", "TimeZoneCode", "Eastern Standard Time"); viewModel.MaxNumberOfUsers = 4; } return(View(viewModel)); }
public ActionResult AddEditStation(AddEditStationViewModel viewModel) { if (!CRCDataAccess.ValidateCallLettersIsUnique(viewModel.CopyInd.Equals("Y", StringComparison.OrdinalIgnoreCase) ? null : viewModel.StationId, viewModel.CallLetters, viewModel.BandId)) { ModelState.AddModelError("CallLetters", "Call Letters: " + viewModel.CallLetters + " already exists."); } if (ModelState.IsValid) { long stationId; stationId = CRCDataAccess.SaveStation( viewModel.CopyInd.Equals("Y", StringComparison.OrdinalIgnoreCase) ? null : viewModel.StationId, viewModel.CallLetters, viewModel.BandId, viewModel.Frequency, viewModel.RepeaterStatusId, viewModel.FlagshipStationId, viewModel.MemberStatusId, viewModel.MinorityStatusId, viewModel.StatusDate, viewModel.LicenseeTypeId, viewModel.LicenseeName, viewModel.AddressLine1, viewModel.AddressLine2, viewModel.City, viewModel.StateId, viewModel.County, viewModel.Country, viewModel.ZipCode, viewModel.Phone, viewModel.Fax, viewModel.Email, viewModel.WebPage, viewModel.TsaCume, viewModel.Tsaaqh, viewModel.MetroMarketId, viewModel.MetroMarketRank, viewModel.DmaMarketId, viewModel.DmaMarketRank, viewModel.TimeZoneId, viewModel.HoursFromFlagship, viewModel.MaxNumberOfUsers, viewModel.EnabledInd ? (DateTime?)null : DateTime.UtcNow, viewModel.EnabledInd ? (long?)null : CRCUser.UserId, CRCUser.UserId); CRCDataAccess.DeleteStationAffiliates(stationId); if (viewModel.AffiliateIds != null) { foreach (long affiliateId in viewModel.AffiliateIds) { CRCDataAccess.SaveStationAffiliate(0, stationId, affiliateId, CRCUser.UserId); } } return(RedirectToAction("StationDetail", new { stationId = stationId })); /* if (viewModel.StationId.HasValue) * { * return RedirectToAction("StationDetail", new { stationId=viewModel.StationId}); * } * return RedirectToAction("Index"); */ } else { return(View(viewModel)); } }