Beispiel #1
0
 public ActionResult Create(FormCollection collection)
 {
     try
     {
         // TODO: Add insert logic here
         if (collection["Type"] == "1")
         {
             PartTimeEmployee emp = new PartTimeEmployee();
             emp.Name       = collection["Name"];
             emp.StartDate  = DateTime.Parse(collection["StartDate"]);
             emp.HourlyRate = Convert.ToInt32(collection["Salary"]);
             _bl.AddEmployee(emp);
         }
         else
         {
             if (collection["Type"] == "2")
             {
                 FullTimeEmployee emp = new FullTimeEmployee();
                 emp.Name      = collection["Name"];
                 emp.StartDate = DateTime.Parse(collection["StartDate"]);
                 emp.Salary    = Convert.ToInt32(collection["Salary"]);
                 _bl.AddEmployee(emp);
             }
         }
         return(RedirectToAction("Index"));
     }
     catch {
         return(View());
     }
 }
Beispiel #2
0
 private void Guardar_Click(object sender, EventArgs e)
 {
     if (this.Cedula != null && this.Nombre != null && FechaIng != null)
     {
         if (this.isPartTime.Checked = true && this.IsFullTime.Checked != true)
         {
             PartTimeEmployee nuevo = new PartTimeEmployee();
             nuevo.Id         = int.Parse(this.Cedula.Text);
             nuevo.Name       = this.Nombre.Text;
             nuevo.StartDate  = this.FechaIng.Value;
             nuevo.SalXHora   = int.Parse(Salario.Text);
             nuevo.HourlyRate = int.Parse(CantHoras.Text);
             if (edit)
             {
                 _IBL.UpdateEmployee(nuevo);
             }
             else
             {
                 _IBL.AddEmployee(nuevo);
             }
             this.Cedula.Text        = "";
             this.Nombre.Text        = "";
             this.Salario.Text       = "";
             this.CantHoras.Text     = "";
             this.isPartTime.Checked = false;
         }
         else
         {
             if (this.isPartTime.Checked != true && this.IsFullTime.Checked == true)
             {
                 FullTimeEmployee nuevo = new FullTimeEmployee();
                 nuevo.Id        = int.Parse(this.Cedula.Text);
                 nuevo.Name      = this.Nombre.Text;
                 nuevo.StartDate = this.FechaIng.Value;
                 nuevo.Salary    = int.Parse(Salario.Text);
                 if (edit)
                 {
                     _IBL.UpdateEmployee(nuevo);
                 }
                 else
                 {
                     _IBL.AddEmployee(nuevo);
                 }
                 this.Cedula.Text        = "";
                 this.Nombre.Text        = "";
                 this.Salario.Text       = "";
                 this.CantHoras.Text     = "";
                 this.IsFullTime.Checked = false;
             }
         }
     }
 }
Beispiel #3
0
 public void AddEmployee(Employee emp)
 {
     try
     {
         blHandler.AddEmployee(emp);
     }
     catch
     {
         throw new Exception("Problemas al insertar empleado");
     }
     //throw new NotImplementedException();
 }
 // POST api/<controller>
 public void Post([FromBody] Shared.Entities.ApiEmployee emp)//Esto es cualquier cosa
 {
     if (emp.Type == 1)
     {
         Shared.Entities.PartTimeEmployee e = new Shared.Entities.PartTimeEmployee();
         e.Name       = emp.Name;
         e.StartDate  = emp.StartDate;
         e.HourlyRate = emp.Salary;
         _bl.AddEmployee(e);
     }
     else
     {
         if (emp.Type == 2)
         {
             Shared.Entities.FullTimeEmployee e = new Shared.Entities.FullTimeEmployee();
             e.Name      = emp.Name;
             e.StartDate = emp.StartDate;
             e.Salary    = emp.Salary;
             _bl.AddEmployee(e);
         }
     }
 }
Beispiel #5
0
 public void AddEmployee(Employee emp)
 {
     blHandler.AddEmployee(emp);
 }
 public void SaveEmployee(Shared.Entities.Employee e)
 {
     _bl.AddEmployee(e);
 }
        static void Main(string[] args)
        {
            //log4net.Config.XmlConfigurator.Configure();

            //log4net.Config.XmlConfigurator.Configure(new FileInfo(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\RtdServer.dll.config"));

            //log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            log.Info("========================================");
            log.Info("Comienzo Programa. Fecha : " + System.DateTime.Now.ToString());
            var             section   = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
            IUnityContainer container = new UnityContainer().LoadConfiguration(section);
            //section.Configure(container);
            //Helper.RegisterTypes(container);

            IBLEmployees handler = container.Resolve <IBLEmployees>();
            int          opcion;
            string       nombre;
            char         tipoEmpleado;
            int          numeradorId = 0;
            double       precioHora;
            int          salario;

            do
            {
                Console.WriteLine("---------PRACTICO 01--------");
                Console.WriteLine("-----------------------------");
                Console.WriteLine("-----------------------------");
                Console.WriteLine("-OPCIONES-");
                Console.WriteLine("1-Registrar Empleado-");
                Console.WriteLine("2-Listar Empleados-");
                Console.WriteLine("3-Calcular Salario-");
                Console.WriteLine("4-Eliminar Empleado-");
                Console.WriteLine("5-Salir-");

                Console.WriteLine("INGRESE SU OPCION: ");
                opcion = int.Parse(Console.ReadLine());

                while (opcion < 1 || opcion > 5)    //control de la variable opcion
                {
                    Console.WriteLine("Error, opcion no valida");
                    Console.WriteLine("INGRESE SU OPCION: ");
                    opcion = int.Parse(Console.ReadLine());
                }

                Console.Clear();

                switch (opcion)
                {
                case 1:
                    try
                    {
                        log.Info("Opcion 1 -Registrar Empleado-");
                        //Employee empleado;
                        numeradorId++;

                        Console.WriteLine("Nombre:");
                        nombre = Console.ReadLine();

                        Console.WriteLine("Es PartTime(P) o FullTime(F):");
                        tipoEmpleado = char.Parse(Console.ReadLine());

                        while (tipoEmpleado != 'P' && tipoEmpleado != 'F')        //control de la variable opcion
                        {
                            Console.WriteLine("Error, el tipo de empleado no es valido. Ingrese nuevamente (P)o(F)");
                            tipoEmpleado = char.Parse(Console.ReadLine());
                        }

                        if (tipoEmpleado == 'P')
                        {
                            Console.WriteLine("Precio por hora:");
                            precioHora = double.Parse(Console.ReadLine());
                            PartTimeEmployee empleado = new PartTimeEmployee();
                            empleado.HourlyRate = precioHora;
                            empleado.Name       = nombre;
                            empleado.Id         = numeradorId;
                            empleado.StartDate  = DateTime.Now;
                            handler.AddEmployee(empleado);
                        }
                        else
                        {
                            Console.WriteLine("Precio mensual:");
                            salario = int.Parse(Console.ReadLine());
                            FullTimeEmployee empleado = new FullTimeEmployee();
                            empleado.Salary    = salario;
                            empleado.Name      = nombre;
                            empleado.Id        = numeradorId;
                            empleado.StartDate = DateTime.Now;
                            handler.AddEmployee(empleado);
                        }
                        Console.WriteLine("Empleado registrado correctamente!");
                    }
                    catch (Exception e)
                    {
                        log.Error("Error en el registro del empleado:", e);
                    }
                    log.Info("Fin Opcion 1 - Registrar Empleado-");
                    break;

                case 2:
                    log.Info("Inicio Opcion 2 - Listar Empleados-");
                    List <Employee> empleados = handler.GetAllEmployees();
                    Console.WriteLine("ID       NOMBRE          FECHA DE INGRESO          TIPO");
                    string tipo;

                    foreach (Employee empleado in empleados)
                    {
                        if (empleado is FullTimeEmployee)
                        {
                            tipo = "FullTime";
                        }
                        else
                        {
                            tipo = "PartTime";
                        }
                        Console.WriteLine("{0}     {1}        {2}     {3} ", empleado.Id, empleado.Name, empleado.StartDate, tipo);
                    }
                    log.Info("Fin Opcion 2 - Listar Empleados-");
                    break;

                case 3:
                    try
                    {
                        log.Info("Inicio Opcion 3 - Calculo Horas-");
                        int idCalcular, horas;
                        Console.WriteLine("Ingrese el id del empleado a calcular:");
                        idCalcular = int.Parse(Console.ReadLine());
                        Console.WriteLine("Ingrese la cantidad de horas trabajadas:");
                        horas = int.Parse(Console.ReadLine());
                        Double salarioCalculado = handler.CalcPartTimeEmployeeSalary(idCalcular, horas);
                        Console.WriteLine("El salario correspondiente es: $ {0}", salarioCalculado);
                        //falta agarrar el throw
                    }
                    catch (Exception e)
                    {
                        log.Error("Error en el calculo:", e);
                    }
                    log.Info(" Fin Opcion 3 - Calculo Horas-");
                    break;

                case 4:
                    try
                    {
                        log.Info(" Inicio Opcion 4 - Baja Empleados-");
                        Console.WriteLine("Ingrese el id del empleado a dar de baja:");
                        int id = int.Parse(Console.ReadLine());
                        handler.DeleteEmployee(id);
                        Console.WriteLine("Empleado dado de baja correctamente");
                    }
                    catch (Exception e)
                    {
                        log.Error("Error en Delete Employee:", e);
                    }
                    log.Info(" Fin Opcion 4 - Baja Empleados-");
                    break;
                }
            } while (opcion != 5);
            log.Info("Fin del programa");
            log.Info("========================================");
        }
 public void AddEmployee(Employee emp)
 {
     //throw new NotImplementedException();
     blHandler.AddEmployee(emp);
 }
Beispiel #9
0
        static void Main(string[] args)
        {
            ILog log = LogManager.GetLogger("Logger");

            using (UnityContainer container = new UnityContainer())
            {
                container.LoadConfiguration();
                IBLEmployees blHandler = container.Resolve <IBLEmployees>();

                Employee         e;
                FullTimeEmployee fte;
                PartTimeEmployee p;

                PrintHelp();
                System.Console.Write(">");
                string line = Console.ReadLine();

                log4net.Config.XmlConfigurator.Configure();

                do
                {
                    string[] parameters = line.Split(new string[] { " " }, StringSplitOptions.None);

                    try
                    {
                        switch (parameters[0])
                        {
                        case "help":
                            PrintHelp();
                            break;

                        case "AddFullTimeEmployee":
                            fte = new FullTimeEmployee();
                            foreach (string s in parameters)
                            {
                                System.Console.WriteLine(s);
                            }
                            fte.Name      = parameters[1];
                            fte.StartDate = Convert.ToDateTime(parameters[2]);
                            fte.Salary    = Int32.Parse(parameters[3]);
                            blHandler.AddEmployee(fte);
                            break;

                        case "AddPartTimeEmployee":
                            p            = new PartTimeEmployee();
                            p.Name       = parameters[1];
                            p.StartDate  = Convert.ToDateTime(parameters[2]);
                            p.HourlyDate = Int32.Parse(parameters[3]);
                            blHandler.AddEmployee(p);
                            break;

                        case "DeleteEmployee":
                            blHandler.DeleteEmployee(Int32.Parse(parameters[1]));
                            break;

                        case "UpdateEmployee":
                            Employee emp = blHandler.GetEmployee(Int32.Parse(parameters[1]));
                            if (emp != null)
                            {
                                emp.Id        = Int32.Parse(parameters[1]);
                                emp.Name      = parameters[2];
                                emp.StartDate = Convert.ToDateTime(parameters[3]);
                                int salary = Int32.Parse(parameters[4]);
                                if (emp is FullTimeEmployee)
                                {
                                    ((FullTimeEmployee)emp).Salary = salary;
                                }
                                else
                                {
                                    ((PartTimeEmployee)emp).HourlyDate = salary;
                                }
                                blHandler.UpdateEmployee(emp);
                            }
                            else
                            {
                                throw new Exception("Error: ID empleado no existe.");
                            }
                            break;

                        case "GetAllEmployees":
                            List <Employee> list = blHandler.GetAllEmployees();
                            foreach (Employee l in list)
                            {
                                System.Console.WriteLine(l.ToString());
                            }
                            break;

                        case "GetEmployee":
                            e = blHandler.GetEmployee(Int32.Parse(parameters[1]));
                            System.Console.WriteLine(e.ToString());
                            break;

                        case "SearchEmployees":
                            list = blHandler.SearchEmployees(parameters[1]);
                            foreach (Employee l in list)
                            {
                                System.Console.WriteLine(l.ToString());
                            }
                            break;

                        case "CalcPartTime":
                            int    id    = Int32.Parse(parameters[1]);
                            int    hours = Int32.Parse(parameters[2]);
                            double mount = blHandler.CalcPartTimeEmployeeSalary(id, hours);
                            System.Console.WriteLine(mount);
                            break;

                        default:
                            Console.WriteLine("Invalid Command!");
                            break;
                        }
                    }
                    catch (EmployeeExc exc)
                    {
                        log.Warn(exc.Message, exc);

                        System.Console.WriteLine(exc.Message);
                    }
                    catch (Exception E)
                    {
                        log.Error("Error no controlado:", E);
                    }



                    System.Console.Write(">");
                    line = System.Console.ReadLine();
                } while (!line.Equals("exit"));
            }
        }
Beispiel #10
0
 public void AddEmployee(Employee emp)
 {
     IB.AddEmployee(emp);
 }