Beispiel #1
0
 protected override void ClearDraftAfterSave()
 {
     DraftBirthDate = null;
     TenantTemplate = null;
     _pickedStall   = null;
     base.ClearDraftAfterSave();
 }
Beispiel #2
0
        //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}");
            }
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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}"),
            });
        }
Beispiel #5
0
 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;
 }
Beispiel #6
0
        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
            });
        }
Beispiel #7
0
        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>();
        }
Beispiel #8
0
        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());
        }
Beispiel #9
0
        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);
        }
Beispiel #10
0
        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);
        }
Beispiel #11
0
        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>();
        }
Beispiel #12
0
        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);
        }
Beispiel #13
0
        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);
        }
Beispiel #14
0
        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>();
        }
Beispiel #15
0
 public bool IsOccupied(StallDTO stall) => GetOccupant(stall) != null;
Beispiel #16
0
 public void SetPickedStall(StallDTO stallDTO) => _pickedStall        = stallDTO;
Beispiel #17
0
 private static LeaseDTO FindLeaseIn <T>(StallDTO stall, ISimpleRepo <T> repo)
     where T : LeaseDTO
 => repo.GetAll().FindLast(_ => _.Stall.Id == stall.Id);