Ejemplo n.º 1
0
        public void Initialization()
        {
            //Mock up object
            var repository = Substitute.For <IHeadOfficeRepository>();

            h       = new HeadOfficeDomain();
            service = new HeadOfficeDomainService(repository);
            repository.GetById(id1).Returns(headOffice1);
            repository.GetById(id2).Returns(headOffice1);
            headOffices.Add(headOffice1);
            headOffices.Add(headOfficeInsert);
            repository.GetAll().Returns(headOffices);
        }
        public HeadOfficeServiceResponse GetHeadOfficeById(Guid id)
        {
            HeadOfficeServiceResponse response = new HeadOfficeServiceResponse();
            HeadOffice headOffice = _headOfficeRepository.GetById(id);

            if (headOffice == null)
            {
                response.Messages.Add(new Message("Data is not in Database"));
            }
            else
            {
                HeadOfficeDomain headOfficeDomain = new HeadOfficeDomain();
                MergeExtension.Merge(headOfficeDomain, headOffice);
                response.HeadOfficeDomain = headOfficeDomain;
            }
            return(response);
        }
        public HeadOfficeServiceResponse Update(HeadOfficeDomain headOffice)
        {
            HeadOfficeServiceResponse response = new HeadOfficeServiceResponse();

            if (validateIsNotExist(headOffice.Id))
            {
                response.Messages.Add(new Message("Data is not in Database"));
            }
            else
            {
                headOfficeEntity = new HeadOffice();
                MergeExtension.Merge(headOfficeEntity, headOffice);
                _headOfficeRepository.Update(headOfficeEntity);
                _headOfficeRepository.SaveChanges();
            }
            return(response);
        }
        public HeadOfficeServiceResponse GetAllMerk()
        {
            HeadOfficeServiceResponse response    = new HeadOfficeServiceResponse();
            Collection <HeadOffice>   headOffices = _headOfficeRepository.GetAll();

            if (headOffices.Count == 0)
            {
                response.Messages.Add(new Message("Tidak Ada Merk Yang Terdaftar"));
            }
            else
            {
                foreach (var m in headOffices)
                {
                    HeadOfficeDomain headOfficeDomain = new HeadOfficeDomain();
                    MergeExtension.Merge(headOfficeDomain, m);
                    response.HeadOfficeDomains.Add(headOfficeDomain);
                }
            }
            return(response);
        }