public void AddServicio(Servicio servicio)
        {
            _Context.Entry(servicio.Empleado).State = EntityState.Unchanged;
            _Context.Entry(servicio.Vehiculo).State = EntityState.Unchanged;

            foreach (var detalle in servicio.DetalleGastosServicios)
            {
                _Context.Entry(detalle.GastosDeServicio).State = System.Data.Entity.EntityState.Unchanged;
            }

            _Context.Servicios.Add(servicio);
            _Context.SaveChanges();
        }
        public void UpdateServicio(Servicio servicio)
        {
            var servicioDB = GetFromServicioById(servicio.Id);

            if (servicioDB.IdEmpleado != servicio.IdEmpleado)
            {
                servicioDB.IdEmpleado = servicio.IdEmpleado;
                servicioDB.Empleado = servicio.Empleado;

                _Context.Entry(servicioDB.Empleado).State = System.Data.Entity.EntityState.Unchanged;
            }

            if (servicioDB.IdVehiculo != servicio.IdVehiculo)
            {
                servicioDB.IdVehiculo = servicio.IdVehiculo;
                servicioDB.Vehiculo = servicio.Vehiculo;

                _Context.Entry(servicioDB.Vehiculo).State = System.Data.Entity.EntityState.Unchanged;
            }

            var nuevos = servicio.DetalleGastosServicios.Except(servicioDB.DetalleGastosServicios).ToList();
            var eliminados = servicioDB.DetalleGastosServicios.Except(servicio.DetalleGastosServicios).ToList();
            var modificados = servicio.DetalleGastosServicios.Intersect(servicioDB.DetalleGastosServicios).ToList();

            eliminados.ForEach(e => servicioDB.DetalleGastosServicios.Remove(e));

            nuevos.ForEach(n =>
            {
                _Context.Entry(n.GastosDeServicio).State = EntityState.Unchanged;
                servicioDB.DetalleGastosServicios.Add(n);
            });

            foreach (var item in modificados)
            {
                var itemDb = servicioDB.DetalleGastosServicios.SingleOrDefault(i => i.IdGastosServicio.Equals(item.IdGastosServicio));

                itemDb.Cantidad = item.Cantidad;
                itemDb.Observaciones = item.Observaciones;

                _Context.Entry(itemDb.GastosDeServicio).State = EntityState.Unchanged;
                _Context.Entry(itemDb).State = EntityState.Modified;
            }

            _Context.Entry(servicioDB).State = EntityState.Modified;
            _Context.SaveChanges();
        }
        private void BindServicio(Servicio servicio)
        {
            hfIdPedido.Value = servicio.Id.ToString();
            if (servicio.GuiaRemision != null)
            {
                //txtEmpleado.Text = servicio.Empleado.Nombres;
                txtEstado.Text = servicio.Estado;
            }
            txtFecha.Text = servicio.FechaTraslado.ToShortTimeString();

            servicio.TotalGastosServicio = servicio.DetalleGastosServicios.Sum(i => i.Total);

            lvDetallePedido.DataSource = servicio.DetalleGastosServicios;
            lvDetallePedido.DataBind();

            if (servicio.DetalleGastosServicios.Count > 0)
            {
                //parsear a label
                var lblTotal = lvDetallePedido.FindControl("lblTotal") as Label;
                lblTotal.Text = servicio.TotalGastosServicio.ToString();
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            var idServicio = Request.QueryString["id"];
            var opc = Request.QueryString["opc"];

            if (!Page.IsPostBack)
            {
                if (idServicio != null && opc.Equals("editar"))
                {
                    ViewState["opc"] = "editar";

                    var id = Int32.Parse(idServicio);

                    var servicio = ServicioService.GetFromServicioById(id);

                    // trabajar con cache nombre a recuperar e insertar
                    Cache.Insert("servicio", servicio);

                    //refactorizado
                    BindServicio(servicio);
                }
                else if (opc != null && opc.Equals("nuevo"))
                {
                    ViewState["opc"] = "nuevo";

                    var servicio = new Servicio();

                    BindServicio(servicio);

                    Cache.Insert("servicio", servicio);
                }
            }
        }
Esempio n. 5
0
 public void UpdateServicio(Servicio servicio)
 {
     ServicioRepository.UpdateServicio(servicio);
 }
Esempio n. 6
0
 public void AddServicio(Servicio servicio)
 {
     ServicioRepository.AddServicio(servicio);
 }