public async Task Should_Save_ACompanyCorrectly()
        {
            using (IDbConnection conn = _sqlExecutor.OpenNewDbConnection())
            {
                var companies = await conn.GetAsyncAll <SUBLICEN>();

                SUBLICEN subl = companies.FirstOrDefault();
                if (subl != null)
                {
                    var code    = subl.CODIGO;
                    var company = await _companyDataService.GetAsyncCompanyDo(code);

                    CompanyViewObject viewObject = company.Value;
                    var dateNow = DateTime.Now.ToString("yyyyMMddHH:mm");
                    viewObject.ULTMODI = dateNow;
                    var id = _companyDataService.GetNewId();
                    viewObject.CODIGO = id;
                    company           = _companyDataService.GetNewCompanyDo(id);
                    company.Value     = viewObject;
                    bool saved = await _companyDataService.SaveAsync(company);

                    var newItem = await _companyDataService.GetAsyncCompanyDo(id);

                    Assert.IsTrue(saved);
                    Assert.AreEqual(id, newItem.Value.CODIGO);
                }
            }
        }
 public override void DisposeEvents()
 {
     UnregisterToolBar(PrimaryKeyValue, _newCommand);
     EventManager.DeleteMailBoxSubscription(_mailBoxName);
     EventManager.DeleteObserverSubSystem(MasterModuleConstants.CompanySubSystemName, this);
     DataObject         = null;
     _currentCompanyDto = null;
     _companyData       = null;
 }
        public async Task Should_Add_CompanyCorrectly()
        {
            using (IDbConnection conn = _sqlExecutor.OpenNewDbConnection())
            {
                var companyId            = _companyDataService.GetNewId();
                var company              = _companyDataService.GetNewCompanyDo(companyId);
                var officeId             = _dataServices.GetOfficeDataServices().GetNewId();
                CompanyViewObject c      = company.Value;
                Random            random = new Random();
                c.NOMBRE         = "Karve" + random.Next() % 1000;
                c.POBLACION      = "Barcelona";
                c.PROVINCIA      = "08";
                c.CP             = "08100";
                c.FAX            = "3489498";
                c.TELEFONO       = "349019";
                c.ULTMODI        = DateTime.Now.ToString("yyyyMMddHH:mm");
                c.NIF            = "Y17267";
                c.RESPDNI        = "Y7376161";
                c.USUARIO        = "CV";
                c.OBS1           = "Great company";
                c.USUARIOWEB_EMP = "karlos";
                c.PWDWEB_EMP     = "Password";
                c.FEC_ALTA       = DateTime.Now;
                c.FEC_BAJA       = DateTime.Now.AddDays(30);
                c.DIRECCION      = "Calle Rocafort 239";
                if (c != null)
                {
                    c.Offices = new List <OfficeViewObject>()
                    {
                        new OfficeViewObject()
                        {
                            Codigo    = officeId,
                            Nombre    = "LaViaZia",
                            DIRECCION = "CalleToma",
                            PROVINCIA = "08",
                            CP        = "08",
                            NACIO     = "34",
                            POBLACION = "Barcelona"
                        }
                    };
                }
                // prepare
                company.Value = c;
                bool value = await _companyDataService.SaveAsync(company);

                Assert.IsTrue(value);
                var companyValue = await _companyDataService.GetAsyncCompanyDo(companyId);

                Assert.NotNull(companyValue);
                Assert.AreEqual(companyValue.Value.NOMBRE, c.NOMBRE);
                Assert.AreEqual(companyValue.Value.TELEFONO, c.TELEFONO);
                Assert.AreEqual(companyValue.Value.NIF, c.NIF);
                Assert.AreEqual(companyValue.Value.CP, c.CP);
            }
        }
Beispiel #4
0
        /// <summary>
        ///  Create a new company object
        /// </summary>
        /// <param name="code">Code of the company.</param>
        /// <returns>Create a new company.</returns>
        public ICompanyData GetNewCompanyDo(string code)
        {
            var dto = new CompanyViewObject
            {
                Code   = code,
                CODIGO = code
            };
            ICompanyData data = new Company
            {
                Value = dto
            };

            return(data);
        }
 public void Should_Throws_WithNullIdCompany()
 {
     using (var conn = _sqlExecutor.OpenNewDbConnection())
     {
         var companyId            = _companyDataService.GetNewId();
         var company              = _companyDataService.GetNewCompanyDo(companyId);
         var officeId             = _dataServices.GetOfficeDataServices().GetNewId();
         CompanyViewObject c      = company.Value;
         Random            random = new Random();
         c.NOMBRE         = null;
         c.CODIGO         = null;
         c.POBLACION      = "Barcelona";
         c.PROVINCIA      = "08";
         c.CP             = "08100";
         c.FAX            = "3489498";
         c.TELEFONO       = "349019";
         c.ULTMODI        = DateTime.Now.ToString("yyyyMMddHH:mm");
         c.NIF            = "Y17267";
         c.RESPDNI        = "Y7376161";
         c.USUARIO        = "CV";
         c.OBS1           = "Great company";
         c.USUARIOWEB_EMP = "karlos";
         c.PWDWEB_EMP     = "Password";
         c.FEC_ALTA       = DateTime.Now;
         c.FEC_BAJA       = DateTime.Now.AddDays(30);
         c.DIRECCION      = "Calle Rocafort 239";
         if (c != null)
         {
             c.Offices = new List <OfficeViewObject>()
             {
                 new OfficeViewObject()
                 {
                     Codigo    = officeId,
                     Nombre    = "LaViaZia",
                     DIRECCION = "CalleToma",
                     PROVINCIA = "08",
                     CP        = "08",
                     NACIO     = "34",
                     POBLACION = "Barcelona"
                 }
             };
         }
         // prepare
         company.Value = c;
         Assert.Throws <Exception>(async() => await _companyDataService.SaveAsync(company));
     }
 }
Beispiel #6
0
        public void Should_Build_QueryFromQueryStoreWithParam()
        {
            var dto = new CompanyViewObject
            {
                CP        = "1892829",
                PROVINCIA = "282982",
                Code      = "282998"
            };
            var store = _storeFactory.GetQueryStore();

            store.Clear();
            store.AddParam(QueryType.QueryCity, dto.CP);
            store.AddParam(QueryType.QueryProvince, dto.PROVINCIA);
            store.AddParam(QueryType.QueryCompanyOffices,
                           dto.Code);
            var q = store.BuildQuery();
        }
Beispiel #7
0
        /// <summary>
        ///  Retrieve the company data object given the company identifier.
        /// </summary>
        /// <param name="id">Identifier of the company</param>
        /// <returns>Data of the company</returns>
        public async Task <ICompanyData> GetAsyncCompanyDo(string id)
        {
            CompanyViewObject dto = await _loader.LoadValueAsync(id).ConfigureAwait(true);

            ICompanyData data = new Company();

            data.Value = dto;
            // initialize the dto for the province and the city.
            var prov = new ObservableCollection <ProvinceViewObject>();
            var city = new ObservableCollection <CityViewObject>();

            prov.Add(dto.Province);
            city.Add(dto.City);
            data.ProvinciaDto = new ObservableCollection <ProvinceViewObject>();
            data.CityDto      = city;
            data.ProvinciaDto = prov;
            return(data);
        }
Beispiel #8
0
        public void Should_Build_QueryFromQueryStoreWithNullParameters2()
        {
            CompanyViewObject viewObject = new CompanyViewObject
            {
                CP        = null,
                PROVINCIA = null,
                Code      = "282998"
            };
            IQueryStore store = _storeFactory.GetQueryStore();

            store.Clear();
            store.AddParam(QueryType.QueryCity, viewObject.CP);
            store.AddParam(QueryType.QueryProvince, viewObject.PROVINCIA);
            store.AddParam(QueryType.QueryCompanyOffices,
                           viewObject.Code);
            var q = store.BuildQuery();

            Assert.AreEqual(q, Query3);
        }
 public void Init(string primaryKey, DataPayLoad payload, bool isInsert)
 {
     if (payload.HasDataObject)
     {
         Logger.Info("CompanyInfoViewModel has received payload type " + payload.PayloadType.ToString());
         var companyData = payload.DataObject as ICompanyData;
         if (companyData != null)
         {
             _companyData       = companyData;
             _currentCompanyDto = _companyData.Value;
             DataObject         = _currentCompanyDto;
             CompanyHelper      = companyData;
             // When the view model receive a message broadcast to its child view models.
             //EventManager.SendMessage(UpperBarCompanyViewModel.Name, payload);
             Logger.Info("CompanyInfoViewModel has activated the client subsystem as current with directive " +
                         payload.PayloadType.ToString());
             ActiveSubSystem();
         }
     }
 }
Beispiel #10
0
        protected override async Task <DataPayLoad> HandleSaveOrUpdate(DataPayLoad payLoad)
        {
            Contract.Requires(payLoad != null, "The payload at company data shall be not null");
            Contract.Requires(payLoad.DataObject != null, "Payload shall have data object");
            CompanyViewObject viewObject = payLoad.DataObject as CompanyViewObject;
            ICompanyData      data       = _companyDataServices.GetNewCompanyDo(viewObject.Code);

            data.Value = viewObject;
            bool result = await _companyDataServices.SaveAsync(data);

            // FIXME: where it is used current payload. shall enforce dry.
            if (result)
            {
                payLoad.Sender               = ToolBarModule.NAME;
                payLoad.PayloadType          = DataPayLoad.Type.UpdateView;
                CurrentPayload               = new DataPayLoad();
                CurrentPayload.PayloadType   = DataPayLoad.Type.UpdateView;
                CurrentPayload.Sender        = ToolBarModule.NAME;
                CurrentPayload.HasDataObject = true;
                CurrentPayload.Subsystem     = payLoad.Subsystem;
                CurrentPayload.DataObject    = data;
            }
            return(payLoad);
        }