protected override void ClearDraftAfterSave() { DraftBirthDate = null; TenantTemplate = null; _pickedStall = null; base.ClearDraftAfterSave(); }
//internal static void RejectDuplicateName(this IStallsRepo repo, StallDTO newRecord) //{ // var matches = repo.GetAll().Where(_ => _.Name == newRecord.Name); // if (matches.Any()) // throw DuplicateRecordsException.For(matches, nameof(newRecord.Name), newRecord.Name); //} internal static void DontDeleteIfOccupied(this IStallsRepo repo, StallDTO stall, IActiveLeasesRepo activeLses) { var lse = activeLses.GetAll().SingleOrDefault(_ => _.Stall.Id == stall.Id); if (lse != null) { throw Bad.Delete(stall, $"Occupied by {lse}"); } }
public static bool TryPick(MarketStateDbBase marketStateDB, out StallDTO stall) { var win = CreateWindow(); var vm = new StallPickerVM(marketStateDB, win); var res = win.ShowDialog(); stall = vm.PickedStall; return(res == true && stall != null); }
public override SectionDTO CastToRNT(dynamic byf) { var nme = As.Text(byf.label); return(new SectionDTO { Id = As.ID(byf.nid), Name = nme, IsActive = true, StallTemplate = StallDTO.Named(nme + " {0:000}"), }); }
public LeaseColxnRow(SectionDTO sec, AmbulantColxnDTO dto) { Lease = new LeaseDTO { Tenant = TenantModel.Named(dto.ReceivedFrom), Stall = StallDTO.Named($"{sec.Name} Section Ambulant") }; AmbulantDTO = dto; DocumentRef = dto.PRNumber?.ToString(); Ambulant = dto.Amount; Remarks = dto.Remarks; }
public override IDocumentDTO CastByfToDTO(object byfRecord) { var byf = Cast(byfRecord); var nme = byf.Label.Value.Trim(); return(new SectionDTO { Id = (int)byf.Id.Value, Name = nme, StallTemplate = StallDTO.Named(nme + " {0:000}"), IsActive = byf.IsOperational }); }
public void InsertRejectsduplicatestallname() { var moq = new Mock <ISimpleRepo <StallDTO> >(); var sut = new StallsRepo1(moq.Object, null); var stall = StallDTO.Named("sample"); moq.Setup(_ => _.GetAll()) .Returns(new List <StallDTO> { stall }); sut.Invoking(_ => _.Insert(stall)) .Should().Throw <DuplicateRecordsException>(); }
public LeaseDTO GetOccupant(StallDTO stall) { var matches = ActiveLeases.GetAll() .Where(_ => _.Stall.Id == stall.Id); if (!matches.Any()) { return(null); } if (matches.Count() > 1) { throw Bad.Data($"1 occupant for [{stall}] but found [{matches.Count()}]"); } return(matches.Single()); }
public void UpdateAcceptsnonnameedit() { var moq = new Mock <ISimpleRepo <StallDTO> >(); var sut = new StallsRepo1(moq.Object, null); var rec = new StallDTO { Id = 1, Name = "Sample 1" }; moq.Setup(_ => _.GetAll()) .Returns(new List <StallDTO> { rec }); rec.Name = rec.Name + " changed"; sut.Update(rec); }
private static (RentParams Rent, RightsParams Rights) FindStallDefaults(StallDTO stall, ITenantDBsDir dir) { var mkt = dir.MarketState; var match = FindLeaseIn(stall, mkt.ActiveLeases) ?? FindLeaseIn(stall, mkt.InactiveLeases); if (match == null) { stall.Name += " *";//to prevent duplicates match = new LeaseDTO { Rent = new RentParams(), Rights = new RightsParams() }; } return(match.Rent, match.Rights); }
public void CantDeleteifOccupied() { var moq = new Mock <ISimpleRepo <StallDTO> >(); var db = new MockMarketState(); var sut = new StallsRepo1(moq.Object, db); var stall = StallDTO.Named("sample"); db.MoqActiveLeases.Setup(_ => _.GetAll()) .Returns(new List <LeaseDTO> { new LeaseDTO { Stall = stall } }); sut.Invoking(_ => _.Delete(stall)).Should() .Throw <InvalidDeletionException>(); }
public void UpdateAcceptsUniquename() { var moq = new Mock <ISimpleRepo <StallDTO> >(); var sut = new StallsRepo1(moq.Object, null); var rec1 = new StallDTO { Id = 1, Name = "Sample 1" }; var rec2a = new StallDTO { Id = 2, Name = "Sample 2" }; var rec2b = rec2a.ShallowClone <StallDTO>(); moq.Setup(_ => _.GetAll()) .Returns(new List <StallDTO> { rec1, rec2a }); rec2b.Name = rec2a.Name + " changed"; sut.Update(rec2b); }
public void Allowsduplicatenamediffsection() { var moq = new Mock <ISimpleRepo <StallDTO> >(); var sut = new StallsRepo1(moq.Object, null); var rec1_1 = new StallDTO { Id = 1, Name = "Sample 1", Section = new SectionDTO { Id = 1 } }; var rec1_2 = new StallDTO { Id = 2, Name = "Sample 2", Section = new SectionDTO { Id = 1 } }; var rec2_1 = new StallDTO { Id = 3, Name = "Sample 1", Section = new SectionDTO { Id = 2 } }; moq.Setup(_ => _.GetAll()) .Returns(new List <StallDTO> { rec1_1, rec1_2, rec2_1 }); rec2_1.Remarks = "edit"; sut.Update(rec2_1); }
public void UpdateRejectsduplicatestallname() { var moq = new Mock <ISimpleRepo <StallDTO> >(); var sut = new StallsRepo1(moq.Object, null); var rec1 = new StallDTO { Id = 1, Name = "Sample 1" }; var rec2 = new StallDTO { Id = 2, Name = "Sample 2" }; var recX = rec2.ShallowClone <StallDTO>(); moq.Setup(_ => _.GetAll()) .Returns(new List <StallDTO> { rec1, rec2 }); recX.Name = rec1.Name; sut.Invoking(_ => _.Update(recX)) .Should().Throw <DuplicateRecordsException>(); }
public bool IsOccupied(StallDTO stall) => GetOccupant(stall) != null;
public void SetPickedStall(StallDTO stallDTO) => _pickedStall = stallDTO;
private static LeaseDTO FindLeaseIn <T>(StallDTO stall, ISimpleRepo <T> repo) where T : LeaseDTO => repo.GetAll().FindLast(_ => _.Stall.Id == stall.Id);