コード例 #1
0
 public static Customer ConverttoEntity(CustomerModel incustomer)
 {
     Customer customer = null;
        try
        {
        EngineerRepository erepo = new EngineerRepository();
        InstallationRepository irepo = new InstallationRepository();
        customer = new Customer();
        customer.customerid = incustomer.customerid;
        customer.firstname = incustomer.firstname;
        customer.lastname = incustomer.lastname;
        customer.username = incustomer.username;
        customer.password = incustomer.password;
        customer.engineerid = incustomer.engineerid;
        customer.email = incustomer.email;
        customer.Engineer = ConvertEngineer.ConverttoEntity(erepo.GetById(customer.engineerid));
        foreach (var item in incustomer.Installation)
        {
            customer.Installation.Add(ConvertInstallation.ConverttoEntity(irepo.GetById(item)));
        }
        log.Info("CustomerModel wurde konvertiert.");
        }
        catch (Exception exp)
        {
        log.Error("CustomerModel konnte nicht konvertiert werden.");
        throw new DalException("CustomerModel konnte nicht konvertiert werden.", exp);
        }
        return customer;
 }
コード例 #2
0
 public void createCustomer(CustomerModel customer)
 {
     try
     {
         ValidationResults vresult = Validation.ValidateFromAttributes<CustomerModel>(customer);
         if (vresult.IsValid)
         {
             crepo.Add(customer);
             crepo.Save();
             log.Info("Customer saved.");
         }
         else
         {
             log.Warn(vresult.Count + "Validation errors");
             StringBuilder sb = null;
             foreach (var error in vresult)
             {
                 sb = new StringBuilder();
                 sb.Append("Error on property ");
                 sb.Append(error.Target);
                 sb.Append(": ");
                 sb.Append(error.Message);
             }
             log.Warn(sb);
         }
     }
     catch (DalException exp)
     {
         log.Error("Customer konnte nicht gespeichert werden.");
         throw new BLException("Customer konnte nicht gespeichert werden.", exp);
     }
 }
コード例 #3
0
 public static CustomerModel ConvertfromEntity(Customer incustomer)
 {
     CustomerModel customer = null;
        try
        {
        customer = new CustomerModel();
        customer.customerid = incustomer.customerid;
        customer.firstname = incustomer.firstname;
        customer.lastname = incustomer.lastname;
        customer.username = incustomer.username;
        customer.password = incustomer.password;
        customer.engineerid = incustomer.engineerid;
        customer.email = incustomer.email;
        foreach (var item in incustomer.Installation)
        {
            customer.Installation.Add(item.installationid);
        }
        log.Info("Customer wurde konvertiert");
        }
        catch (Exception exp)
        {
        log.Error("Customer konnte nicht konvertiert werden.");
        throw new DalException("Customer konnte nicht konvertiert werden.", exp);
        }
        return customer;
 }
コード例 #4
0
        public void createCustomer(Customer customer)
        {
            try
            {
                log4net.Config.XmlConfigurator.Configure();
                CustomerModel cmodel = new CustomerModel();
                cmodel.firstname = customer.firstname;
                cmodel.lastname = customer.lastname;
                cmodel.email = customer.email;
                cmodel.password = customer.password;
                cmodel.username = customer.username;
                cmodel.engineerid = customer.engineerid;

                IUnityContainer container = new UnityContainer();
                UnityConfigurationSection section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
                section.Configure(container);
                IEngineerBL rservicebl = container.Resolve<IEngineerBL>();
                rservicebl.createCustomer(cmodel);
            }
            catch (Exception exp)
            {
                log.Error("Customer via Soap konnte nicht gespeichert werden.");
                throw new Exception("Customer via Soap konnte nicht gespeichert werden.", exp);
            }
        }
コード例 #5
0
 public void TestcreateCustomer()
 {
     Init();
     EngineerBL ebl = new EngineerBL(mockcrepo, mockerepo,mockirepo);
     CustomerModel mycustomer = new CustomerModel{
         customerid=1, firstname="new", lastname="user", username="******", email="*****@*****.**",
         engineerid=0, Installation=new List<int>{0,1}, password="******"
     };
     ebl.createCustomer(mycustomer);
     Assert.AreEqual(2, mockcrepo.GetAll().Count);
 }
コード例 #6
0
 public void TestcreateCustomer()
 {
     Init();
     CustomerBL cbl = new CustomerBL(mockcrepo, mockirepo);
     CustomerModel customer = new CustomerModel();
     customer.engineerid = 0;
     customer.firstname = "Max";
     customer.lastname = "Mustermann";
     customer.username = "******";
     customer.password = "******";
     customer.email = "*****@*****.**";
     cbl.createCustomer(customer);
     Assert.AreEqual(mockcrepo.GetAll().Count, 2);
 }
コード例 #7
0
 public List<InstallationModel> getInstallations(CustomerModel customer)
 {
     List<InstallationModel> tmp;
     try
     {
         log.Info("Fetching Installation from customer id" + customer.customerid);
         tmp = irepo.GetByCustomerId(customer.customerid);
     }
     catch(DalException exp)
     {
         log.Error("Cannot fetch Installations from customer id " + customer.customerid, exp);
         throw new BLException("Cannot fetch Installations from customer id " + customer.customerid, exp);
     }
     return tmp;
 }