Ejemplo n.º 1
0
        public override Seccionesanaliticas EditPersitance(IModelView obj)
        {
            var model = obj as SeccionesanaliticasModel;
            var efobj = _db.Set <Seccionesanaliticas>().Single(f => f.id == model.Id && f.empresa == Empresa);

            foreach (var item in efobj.GetType().GetProperties())
            {
                var yo     = item.Name.FirstToUpper();
                var yoyo   = obj.GetType().GetProperty(item.Name.FirstToUpper());
                var yoyoyo = obj.GetType().GetProperty(item.Name.FirstToUpper()).PropertyType;

                if ((obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false) &&
                    obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.GetGenericTypeDefinition() !=
                    typeof(ICollection <>))
                {
                    item.SetValue(efobj, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsEnum ?? false)
                {
                    item.SetValue(efobj, (int)obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (!obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false)
                {
                    item.SetValue(efobj, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
            }
            return(efobj);
        }
        // PF TODO: This API and ConstantEditorBuilder is badly designed.

        /// <summary>
        /// Creates an editor for a constant.
        /// </summary>
        /// <param name="uiContext">The view in which the editor constant will be displayed.</param>
        /// <param name="portModel">The port that owns the constant, if any.</param>
        /// <param name="constant">The constant.</param>
        /// <param name="onValueChanged">An action to call when the user has finished editing the value.</param>
        /// <param name="modelIsLocked">Whether the node owning the constant, if any, is locked.</param>
        /// <returns>A VisualElement that contains an editor for the constant.</returns>
        public static VisualElement CreateEditorForConstant(
            IModelView uiContext, IPortModel portModel, IConstant constant,
            Action <IChangeEvent, object> onValueChanged, bool modelIsLocked)
        {
            Action <IChangeEvent> myValueChanged = evt =>
            {
                if (evt != null) // Enum editor sends null
                {
                    var p        = evt.GetType().GetProperty("newValue");
                    var newValue = p.GetValue(evt);
                    if (constant is IStringWrapperConstantModel stringWrapperConstantModel)
                    {
                        stringWrapperConstantModel.StringValue = (string)newValue;
                    }
                    else
                    {
                        onValueChanged(evt, newValue);
                    }
                }
            };

            var ext = ExtensionMethodCache <IConstantEditorBuilder> .GetExtensionMethod(
                uiContext.GetType(), constant.GetType(),
                ConstantEditorBuilder.FilterMethods, ConstantEditorBuilder.KeySelector);

            if (ext != null)
            {
                var constantBuilder = new ConstantEditorBuilder(myValueChanged, uiContext.CommandDispatcher, modelIsLocked, portModel);
                return((VisualElement)ext.Invoke(null, new object[] { constantBuilder, constant }));
            }

            Debug.Log($"Could not draw Editor GUI for node of type {constant.Type}");
            return(new Label("<Unknown>"));
        }
Ejemplo n.º 3
0
        public override Criteriosagrupacion CreatePersitance(IModelView obj)
        {
            var viewmodel = obj as CriteriosagrupacionModel;
            var result    = _db.Set <Criteriosagrupacion>().Create();

            foreach (var item in result.GetType().GetProperties())
            {
                if ((obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false) &&
                    (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.GetGenericTypeDefinition() !=
                     typeof(ICollection <>)))
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsEnum ?? false)
                {
                    item.SetValue(result, (int)obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (!obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false)
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
            }

            foreach (var item in viewmodel.Lineas)
            {
                var newItem = _db.Set <CriteriosagrupacionLin>().Create();
                newItem.fkcriteriosagrupacion = viewmodel.Id;
                newItem.id    = item.Id;
                newItem.campo = (int)item.Campo;
                newItem.orden = item.Orden ?? 0;
                result.CriteriosagrupacionLin.Add(newItem);
            }

            return(result);
        }
Ejemplo n.º 4
0
        public override Ficheros EditPersitance(IModelView obj)
        {
            var model  = obj as FicherosGaleriaModel;
            var result = _db.Ficheros.Single(f => f.empresa == Empresa && f.id == model.Id);

            foreach (var item in result.GetType().GetProperties())
            {
                if ((obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false) &&
                    obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.GetGenericTypeDefinition() !=
                    typeof(ICollection <>))
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsEnum ?? false)
                {
                    item.SetValue(result, (int)obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (!obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false)
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
            }

            return(result);
        }
        public override GrupoMateriales CreatePersitance(IModelView obj)
        {
            var viewmodel = obj as GrupoMaterialesModel;
            var result    = _db.Set <GrupoMateriales>().Create();

            foreach (var item in result.GetType().GetProperties())
            {
                if ((obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false) &&
                    (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.GetGenericTypeDefinition() !=
                     typeof(ICollection <>)))
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsEnum ?? false)
                {
                    item.SetValue(result, (int)obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (!obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false)
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
            }

            result.cod               = viewmodel.Cod;
            result.empresa           = Empresa;
            result.descripcion       = viewmodel.Descripcion;
            result.inglesDescripcion = viewmodel.InglesDescripcion;

            return(result);
        }
Ejemplo n.º 6
0
        public override Configuraciongraficas EditPersitance(IModelView obj)
        {
            var viewmodel = obj as ConfiguraciongraficasModel;
            var result    = _db.Configuraciongraficas.Single(f => f.id == viewmodel.Codigo && f.empresa == viewmodel.Empresa);


            foreach (var item in result.GetType().GetProperties())
            {
                if ((obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false) &&
                    obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.GetGenericTypeDefinition() !=
                    typeof(ICollection <>))
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsEnum ?? false)
                {
                    item.SetValue(result, (int)obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (!obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false)
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
            }
            var modeloListado = FListadosModel.Instance.GetModel(Context, viewmodel.Idlistado, Empresa, "");

            Type[] typerArgs = { modeloListado.GetType() };
            var    makeme    = typeof(Serializer <>).MakeGenericType(typerArgs);
            var    method    = makeme.GetMethod("GetXml");
            var    instance  = Activator.CreateInstance(makeme);

            result.filtros = method.Invoke(instance, new object[] { viewmodel.ListadoModel }) as string;
            result.usuario = Context.Id;
            return(result);
        }
Ejemplo n.º 7
0
        public override Proyectos EditPersitance(IModelView obj)
        {
            var viewmodel = obj as ProyectosModel;
            var result    = _db.Proyectos.Where(f => f.empresa == viewmodel.Empresa && f.id == viewmodel.Id && f.referencia == viewmodel.Referencia).Single();

            foreach (var item in result.GetType().GetProperties())
            {
                if ((obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false) &&
                    (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.GetGenericTypeDefinition() !=
                     typeof(ICollection <>)))
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsEnum ?? false)
                {
                    item.SetValue(result, (int)obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (!obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false)
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
            }

            return(result);
        }
        public override Seguimientos CreatePersitance(IModelView obj)
        {
            var viewmodel = obj as SeguimientosModel;
            var result    = _db.Set <Seguimientos>().Create();

            foreach (var item in result.GetType().GetProperties())
            {
                if ((obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false) &&
                    (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.GetGenericTypeDefinition() !=
                     typeof(ICollection <>)))
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsEnum ?? false)
                {
                    item.SetValue(result, (int)obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (!obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false)
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
            }

            return(result);
        }
        public virtual TPersistance EditPersitance(IModelView obj)
        {
            var objext = obj as IModelViewExtension;
            var result = _db.Set <TPersistance>().Find(obj.get(objext.primaryKey.First().Name));

            foreach (var item in result.GetType().GetProperties())
            {
                if ((obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false) &&
                    obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.GetGenericTypeDefinition() !=
                    typeof(ICollection <>))
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsEnum ?? false)
                {
                    item.SetValue(result, (int)obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (!obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false)
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
            }

            return(result);
        }
        public override GrupoMateriales EditPersitance(IModelView obj)
        {
            var viewmodel = obj as GrupoMaterialesModel;
            var result    = _db.GrupoMateriales.Where(f => f.empresa == viewmodel.Empresa && f.cod == viewmodel.Cod).Single();

            //todo asignar
            foreach (var item in result.GetType().GetProperties())
            {
                if ((obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false) &&
                    (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.GetGenericTypeDefinition() !=
                     typeof(ICollection <>)))
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsEnum ?? false)
                {
                    item.SetValue(result, (int)obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (!obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false)
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
            }

            //todo asignar contador y referencia
            result.cod               = viewmodel.Cod;
            result.descripcion       = viewmodel.Descripcion;
            result.inglesDescripcion = viewmodel.InglesDescripcion;

            return(result);
        }
Ejemplo n.º 11
0
 public static void GenerarCarpetaAsociadaYGuardarBD(IModelView model, TipoDocumentos tipo, IContextService context, MarfilEntities db)
 {
     using (var tran = Marfil.Inf.Genericos.Helper.TransactionScopeBuilder.CreateTransactionObject())
         using (var servModel = FService.Instance.GetService(model.GetType(), context, db))
         {
             GenerarCarpetaAsociada(model, tipo, context, db);
             if (servModel.exists(model.GetPrimaryKey()))
             {
                 servModel.edit(model);
             }
         }
 }
        public override Movs EditPersitance(IModelView obj)
        {
            var viewmodel = obj as MovsModel;
            var result    = _db.Movs.Where(f => f.empresa == viewmodel.Empresa && f.id == viewmodel.Id).Include(b => b.MovsLin).ToList().Single();

            //todo asignar
            foreach (var item in result.GetType().GetProperties())
            {
                if ((obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false) &&
                    (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.GetGenericTypeDefinition() !=
                     typeof(ICollection <>)))
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsEnum ?? false)
                {
                    item.SetValue(result, (int)obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (!obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false)
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
            }
            //todo asignar contador y referencia
            result.fechamodificacion     = DateTime.Now;
            result.fkusuariomodificacion = Context.Id;

            result.MovsLin.Clear();

            foreach (var item in viewmodel.Lineas)
            {
                var newItem = _db.Set <MovsLin>().Create();
                newItem.flagidentifier         = item.Flagidentifier;
                newItem.empresa                = result.empresa;
                newItem.fkmovs                 = result.id;
                newItem.id                     = item.Id;
                newItem.orden                  = item.Orden;
                newItem.fkseccionesanaliticas  = item.Fkseccionesanaliticas;
                newItem.fkcuentas              = item.Fkcuentas;
                newItem.codigocomentario       = item.Codigocomentario;
                newItem.comentario             = item.Comentario;
                newItem.importe                = item.Importe;
                newItem.esdebe                 = item.Esdebe;
                newItem.importemonedadocumento = item.Importemonedadocumento;
                newItem.conciliado             = item.Conciliado;

                result.MovsLin.Add(newItem);
            }

            return(result);
        }
        public override Movs CreatePersitance(IModelView obj)
        {
            var viewmodel = obj as MovsModel;
            var result    = _db.Set <Movs>().Create();

            foreach (var item in result.GetType().GetProperties())
            {
                if ((obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false) &&
                    (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.GetGenericTypeDefinition() !=
                     typeof(ICollection <>)))
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsEnum ?? false)
                {
                    item.SetValue(result, (int)obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (!obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false)
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
            }

            result.fechaalta             = DateTime.Now;
            result.fechamodificacion     = result.fechaalta;
            result.fkusuarioalta         = Context.Id;
            result.fkusuariomodificacion = Context.Id;
            result.empresa = Empresa;

            foreach (var item in viewmodel.Lineas)
            {
                var newItem = _db.Set <MovsLin>().Create();
                newItem.empresa                = Empresa;
                newItem.fkmovs                 = result.id;
                newItem.id                     = item.Id;
                newItem.importe                = item.Importe;
                newItem.flagidentifier         = Guid.NewGuid();
                newItem.fkcuentas              = item.Fkcuentas;
                newItem.fkseccionesanaliticas  = item.Fkseccionesanaliticas;
                newItem.flagidentifier         = item.Flagidentifier;
                newItem.orden                  = item.Orden;
                newItem.codigocomentario       = item.Codigocomentario;
                newItem.comentario             = item.Comentario;
                newItem.esdebe                 = item.Esdebe;
                newItem.importemonedadocumento = item.Importemonedadocumento;
                newItem.conciliado             = item.Conciliado;
                result.MovsLin.Add(newItem);
            }

            return(result);
        }
        public override Familiasproductos EditPersitance(IModelView obj)
        {
            var viewmodel = obj as FamiliasproductosModel;
            var result    = _db.Familiasproductos.Single(f => f.id == viewmodel.Id && f.empresa == viewmodel.Empresa);

            var fkunidadesmedida = result.fkunidadesmedida;
            var tipofamilia      = viewmodel.Tipofamilia;

            foreach (var item in result.GetType().GetProperties())
            {
                if (obj.GetType().GetProperty(item.Name.FirstToUpper()).PropertyType.IsGenericType&&
                    obj.GetType().GetProperty(item.Name.FirstToUpper()).PropertyType.GetGenericTypeDefinition() !=
                    typeof(ICollection <>))
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (obj.GetType().GetProperty(item.Name.FirstToUpper()).PropertyType.IsEnum)
                {
                    item.SetValue(result, (int)obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (!obj.GetType().GetProperty(item.Name.FirstToUpper()).PropertyType.IsGenericType)
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
            }
            result.gestionarcaducidad   = viewmodel.Gestionarcaducidad;
            result.tipogestionlotes     = (int)viewmodel.Tipogestionlotes;
            result.descripcion1generada = GenerarDescripcionGenerada(viewmodel.Descripcion1Generada_1,
                                                                     viewmodel.Descripcion1Generada_2, viewmodel.Descripcion1Generada_3, viewmodel.Descripcion1Generada_4,
                                                                     viewmodel.Descripcion1Generada_5, viewmodel.Descripcion1Generada_6);

            result.descripcion2generada = GenerarDescripcionGenerada(viewmodel.Descripcion2Generada_1,
                                                                     viewmodel.Descripcion2Generada_2, viewmodel.Descripcion2Generada_3, viewmodel.Descripcion2Generada_4,
                                                                     viewmodel.Descripcion2Generada_5, viewmodel.Descripcion2Generada_6);

            result.descripcionabreviadagenerada = GenerarDescripcionGenerada(viewmodel.Descripcionabreviadagenerada_1,
                                                                             viewmodel.Descripcionabreviadagenerada_2, viewmodel.Descripcionabreviadagenerada_3, viewmodel.Descripcionabreviadagenerada_4,
                                                                             viewmodel.Descripcionabreviadagenerada_5, viewmodel.Descripcionabreviadagenerada_6);


            result.fkunidadesmedida = fkunidadesmedida;
            result.tipofamilia      = (int)tipofamilia;
            return(result);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Creates an instance of a class implementing <see cref="IModelUI"/> to display <paramref name="model"/>.
        /// </summary>
        /// <param name="view">The view in which to put the UI.</param>
        /// <param name="commandDispatcher">The command dispatcher.</param>
        /// <param name="model">The model.</param>
        /// <param name="context">A context creation string. When a model needs different UI in
        /// different contexts, use this parameter to differentiate between contexts.</param>
        /// <typeparam name="T">The type of the returned object.</typeparam>
        /// <returns>An instance of <see cref="IModelUI"/> that display <paramref name="model"/>.</returns>
        public static T CreateUI <T>(IModelView view, CommandDispatcher commandDispatcher, IGraphElementModel model, string context) where T : class, IModelUI
        {
            if (view == null)
            {
                Debug.LogError("GraphElementFactory could not create element because view is null.");
                return(null);
            }

            if (model == null)
            {
                Debug.LogError("GraphElementFactory could not create element because model is null.");
                return(null);
            }

            var ext = ExtensionMethodCache <ElementBuilder> .GetExtensionMethod(
                view.GetType(),
                model.GetType(),
                FilterMethods,
                KeySelector
                );

            T newElem = null;

            if (ext != null)
            {
                var nodeBuilder = new ElementBuilder {
                    View = view, Context = context
                };
                newElem = ext.Invoke(null, new object[] { nodeBuilder, commandDispatcher, model }) as T;
            }

            if (newElem == null)
            {
                Debug.LogError($"GraphElementFactory doesn't know how to create a UI of type {typeof(T)} for model of type: {model.GetType()}");
                return(null);
            }

            return(newElem);
        }
Ejemplo n.º 16
0
        public override GuiasBalances EditPersitance(IModelView obj)
        {
            var viewmodel = obj as GuiasBalancesModel;
            var result    = _db.GuiasBalances.Where(w => w.Id == viewmodel.Id).Include(i => i.GuiasBalancesLineas).ToList().Single();

            foreach (var item in result.GetType().GetProperties())
            {
                if ((obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false) &&
                    (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.GetGenericTypeDefinition() !=
                     typeof(ICollection <>)) && item.Name.ToLower() != "guiasbalanceslineas")
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsEnum ?? false)
                {
                    item.SetValue(result, (int)obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (!obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false)
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
            }

            result.GuiasBalancesLineas.Clear();
            foreach (var item in viewmodel.GuiasBalancesLineas)
            {
                var newItem = _db.Set <GuiasBalancesLineas>().Create();
                newItem.cuenta          = item.cuenta;
                newItem.GuiaId          = item.GuiaId;
                newItem.GuiasBalancesId = item.GuiasBalancesId;
                newItem.Id          = item.Id;
                newItem.InformeId   = item.InformeId;
                newItem.orden       = item.orden;
                newItem.signo       = item.signo;
                newItem.signoea     = item.signoea;
                newItem.TipoGuia    = item.TipoGuia;
                newItem.TipoInforme = item.TipoInforme;
                result.GuiasBalancesLineas.Add(newItem);
            }
            return(result);
        }
Ejemplo n.º 17
0
        public override Criteriosagrupacion EditPersitance(IModelView obj)
        {
            var viewmodel = obj as CriteriosagrupacionModel;
            var result    = _db.Criteriosagrupacion.Where(f => f.id == viewmodel.Id).Include(b => b.CriteriosagrupacionLin).ToList().Single();

            //todo asignar
            foreach (var item in result.GetType().GetProperties())
            {
                if ((obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false) &&
                    (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.GetGenericTypeDefinition() !=
                     typeof(ICollection <>)))
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsEnum ?? false)
                {
                    item.SetValue(result, (int)obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (!obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false)
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
            }
            //todo asignar contador y referencia


            result.CriteriosagrupacionLin.Clear();
            foreach (var item in viewmodel.Lineas)
            {
                var newItem = _db.Set <CriteriosagrupacionLin>().Create();
                newItem.fkcriteriosagrupacion = viewmodel.Id;
                newItem.id    = item.Id;
                newItem.campo = (int)item.Campo;
                newItem.orden = item.Orden ?? 0;
                result.CriteriosagrupacionLin.Add(newItem);
            }


            return(result);
        }
        public override Usuarios EditPersitance(IModelView obj)
        {
            var model = obj as UsuariosModel;
            var efobj = _db.Set <Usuarios>().Single(f => f.id == model.Id);

            foreach (var item in efobj.GetType().GetProperties())
            {
                if (item.Name.FirstToUpper() == "Firma" || item.Name.FirstToUpper() == "Copiaremitente")
                {
                    continue;
                }

                if ((obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false) &&
                    obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.GetGenericTypeDefinition() !=
                    typeof(ICollection <>))
                {
                    item.SetValue(efobj, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsEnum ?? false)
                {
                    item.SetValue(efobj, (int)obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (!obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false)
                {
                    item.SetValue(efobj, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
            }

            if (!string.IsNullOrEmpty(model.Contenidofirma))
            {
                efobj.firma = model.Contenidofirma;
            }
            efobj.ssl            = model.Ssl;
            efobj.copiaremitente = (int?)model.Copiaremitente;

            return(efobj);
        }
        public override Facturas CreatePersitance(IModelView obj)
        {
            var viewmodel = obj as FacturasModel;
            var result    = _db.Set <Facturas>().Create();

            foreach (var item in result.GetType().GetProperties())
            {
                if ((obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false) &&
                    (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.GetGenericTypeDefinition() !=
                     typeof(ICollection <>)))
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsEnum ?? false)
                {
                    item.SetValue(result, (int)obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (!obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false)
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
            }
            result.fechaalta             = DateTime.Now;
            result.fechamodificacion     = result.fechaalta;
            result.fkusuarioalta         = Context.Id;
            result.fkusuariomodificacion = Context.Id;
            result.fkpuertosfkpaises     = viewmodel.Fkpuertos.Fkpaises;
            result.fkpuertosid           = viewmodel.Fkpuertos.Id;

            result.empresa = Empresa;

            viewmodel.Fkseries = result.fkseries;

            foreach (var item in viewmodel.Lineas)
            {
                var newItem = _db.Set <FacturasLin>().Create();
                newItem.empresa                       = Empresa;
                newItem.fkfacturas                    = result.id;
                newItem.id                            = item.Id;
                newItem.fkarticulos                   = item.Fkarticulos;
                newItem.descripcion                   = item.Descripcion;
                newItem.lote                          = item.Lote;
                newItem.tabla                         = item.Tabla;
                newItem.cantidad                      = item.Cantidad;
                newItem.cantidadpedida                = item.Cantidadpedida;
                newItem.largo                         = item.Largo;
                newItem.ancho                         = item.Ancho;
                newItem.grueso                        = item.Grueso;
                newItem.fkunidades                    = item.Fkunidades;
                newItem.metros                        = item.Metros;
                newItem.precio                        = item.Precio;
                newItem.porcentajedescuento           = item.Porcentajedescuento;
                newItem.importedescuento              = item.Importedescuento;
                newItem.fktiposiva                    = item.Fktiposiva;
                newItem.porcentajeiva                 = item.Porcentajeiva;
                newItem.cuotaiva                      = item.Cuotaiva;
                newItem.porcentajerecargoequivalencia = item.Porcentajerecargoequivalencia;
                newItem.cuotarecargoequivalencia      = item.Cuotarecargoequivalencia;
                newItem.importe                       = item.Importe;
                newItem.notas                         = item.Notas;
                newItem.canal                         = item.Canal;
                newItem.precioanterior                = item.Precioanterior;
                newItem.revision                      = item.Revision;
                newItem.decimalesmonedas              = item.Decimalesmonedas;
                newItem.decimalesmedidas              = item.Decimalesmedidas;
                newItem.fkalbaranes                   = item.Fkalbaranes;
                newItem.fkalbaranesfecha              = item.Fkalbaranesfecha;
                newItem.fkalbaranesreferencia         = item.Fkalbaranesreferencia;
                newItem.bundle                        = item.Bundle?.ToUpper();
                newItem.tblnum                        = item.Tblnum;
                newItem.contenedor                    = item.Contenedor;
                newItem.sello                         = item.Sello;
                newItem.caja                          = item.Caja;
                newItem.pesoneto                      = item.Pesoneto;
                newItem.pesobruto                     = item.Pesobruto;
                newItem.seccion                       = item.Seccion;
                newItem.costeadicionalportes          = item.Costeadicionalportes;
                newItem.costeacicionalvariable        = item.Costeadicionalvariable;
                newItem.costeadicionalmaterial        = item.Costeadicionalmaterial;
                newItem.costeadicionalotro            = item.Costeadicionalotro;

                result.FacturasLin.Add(newItem);
            }


            foreach (var item in viewmodel.Totales)
            {
                var newItem = _db.Set <FacturasTotales>().Create();
                newItem.empresa       = Empresa;
                newItem.fkfacturas    = result.id;
                newItem.fktiposiva    = item.Fktiposiva;
                newItem.porcentajeiva = item.Porcentajeiva;
                newItem.basetotal     = item.Baseimponible;
                newItem.brutototal    = item.Brutototal;
                newItem.cuotaiva      = item.Cuotaiva;
                newItem.porcentajerecargoequivalencia = item.Porcentajerecargoequivalencia;
                newItem.importerecargoequivalencia    = item.Importerecargoequivalencia;
                newItem.porcentajedescuentoprontopago = item.Porcentajedescuentoprontopago;
                newItem.importedescuentoprontopago    = item.Importedescuentoprontopago;
                newItem.porcentajedescuentocomercial  = item.Porcentajedescuentocomercial;
                newItem.importedescuentocomercial     = item.Importedescuentocomercial;
                newItem.baseretencion       = item.Baseretencion;
                newItem.porcentajeretencion = item.Porcentajeretencion;
                newItem.importeretencion    = item.Importeretencion;
                newItem.subtotal            = item.Subtotal;
                newItem.decimalesmonedas    = item.Decimalesmonedas;

                result.FacturasTotales.Add(newItem);
            }

            foreach (var item in viewmodel.Vencimientos)
            {
                var newItem = _db.Set <FacturasVencimientos>().Create();
                newItem.empresa            = Empresa;
                newItem.fkfacturas         = result.id;
                newItem.id                 = item.Id;
                newItem.diasvencimiento    = item.Diasvencimiento;
                newItem.fechavencimiento   = item.Fechavencimiento;
                newItem.importevencimiento = item.Importevencimiento;
                result.FacturasVencimientos.Add(newItem);
            }

            return(result);
        }
        public override ImputacionCostes EditPersitance(IModelView obj)
        {
            var viewmodel = obj as ImputacionCostesModel;
            var result    = _db.ImputacionCostes.Where(f => f.empresa == viewmodel.Empresa && f.id == viewmodel.Id).Include(b => b.ImputacionCostesLin).Include(b => b.ImputacionCostescostesadicionales).ToList().Single();

            //todo asignar
            foreach (var item in result.GetType().GetProperties())
            {
                if ((obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false) &&
                    (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.GetGenericTypeDefinition() !=
                     typeof(ICollection <>)))
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsEnum ?? false)
                {
                    item.SetValue(result, (int)obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (!obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false)
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
            }

            result.ImputacionCostesLin.Clear();

            foreach (var item in viewmodel.LineasLotes)
            {
                var newItem = _db.Set <ImputacionCostesLin>().Create();
                newItem.id = item.Id;
                newItem.fkimputacioncostes = result.id;
                newItem.fkarticulos        = item.Fkarticulos;
                newItem.descripcion        = item.Descripcion;
                newItem.lote                   = item.Lote;
                newItem.tabla                  = item.Tabla;
                newItem.cantidad               = item.Cantidad;
                newItem.largo                  = item.Largo;
                newItem.ancho                  = item.Ancho;
                newItem.grueso                 = item.Grueso;
                newItem.fkunidades             = item.Fkunidades;
                newItem.metros                 = item.Metros;
                newItem.notas                  = item.Notas;
                newItem.canal                  = item.Canal;
                newItem.revision               = item.Revision;
                newItem.decimalesmonedas       = item.Decimalesmonedas;
                newItem.decimalesmedidas       = item.Decimalesmedidas;
                newItem.orden                  = item.Orden ?? item.Id;
                newItem.costeadicionalvariable = item.Costeadicionalvariable;
                newItem.costeadicionalmaterial = item.Costeadicionalmaterial;
                newItem.costeadicionalotro     = item.Costeadicionalotro;
                newItem.costeadicionalportes   = item.Costeadicionalportes;
                newItem.precio                 = item.Precio;
                newItem.flagidentifier         = item.Flagidentifier;
                result.ImputacionCostesLin.Add(newItem);
            }


            result.ImputacionCostescostesadicionales.Clear();
            foreach (var item in viewmodel.LineasCostes)
            {
                var newItem = _db.Set <ImputacionCostescostesadicionales>().Create();
                newItem.empresa            = Empresa;
                newItem.fkimputacioncostes = result.id;
                newItem.id                  = item.Id;
                newItem.tipodocumento       = (int)item.Tipodocumento;
                newItem.referenciadocumento = item.Referenciadocumento;
                newItem.importe             = item.Importe;
                newItem.porcentaje          = item.Porcentaje;
                newItem.total               = item.Total;
                newItem.tipocoste           = (int)item.Tipocoste;
                newItem.tiporeparto         = (int)item.Tiporeparto;
                newItem.notas               = item.Notas;
                result.ImputacionCostescostesadicionales.Add(newItem);
            }

            return(result);
        }
        public override Traspasosalmacen CreatePersitance(IModelView obj)
        {
            var viewmodel = obj as TraspasosalmacenModel;
            var result    = _db.Set <Traspasosalmacen>().Create();

            foreach (var item in result.GetType().GetProperties())
            {
                if ((obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false) &&
                    (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.GetGenericTypeDefinition() !=
                     typeof(ICollection <>)))
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsEnum ?? false)
                {
                    item.SetValue(result, (int)obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (!obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false)
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
            }
            result.fechaalta             = DateTime.Now;
            result.fechamodificacion     = result.fechaalta;
            result.fkusuarioalta         = Context.Id;
            result.fkusuariomodificacion = Context.Id;
            result.fkpuertosfkpaises     = viewmodel.Fkpuertos.Fkpaises;
            result.fkpuertosid           = viewmodel.Fkpuertos.Id;
            result.tipoportes            = (int?)viewmodel.Tipodeportes;
            result.empresa = Empresa;

            foreach (var item in viewmodel.Lineas)
            {
                var newItem = _db.Set <TraspasosalmacenLin>().Create();
                newItem.empresa            = Empresa;
                newItem.fktraspasosalmacen = result.id;
                newItem.id                            = item.Id;
                newItem.fkarticulos                   = item.Fkarticulos;
                newItem.descripcion                   = item.Descripcion;
                newItem.lote                          = item.Lote;
                newItem.tabla                         = item.Tabla;
                newItem.cantidad                      = item.Cantidad;
                newItem.cantidadpedida                = item.Cantidadpedida;
                newItem.largo                         = item.Largo;
                newItem.ancho                         = item.Ancho;
                newItem.grueso                        = item.Grueso;
                newItem.fkunidades                    = item.Fkunidades;
                newItem.metros                        = item.Metros;
                newItem.precio                        = item.Precio;
                newItem.porcentajedescuento           = item.Porcentajedescuento;
                newItem.importedescuento              = item.Importedescuento;
                newItem.fktiposiva                    = item.Fktiposiva;
                newItem.porcentajeiva                 = item.Porcentajeiva;
                newItem.cuotaiva                      = item.Cuotaiva;
                newItem.porcentajerecargoequivalencia = item.Porcentajerecargoequivalencia ?? 0;
                newItem.cuotarecargoequivalencia      = item.Cuotarecargoequivalencia;
                newItem.importe                       = item.Importe;
                newItem.notas                         = item.Notas;
                newItem.canal                         = item.Canal;
                newItem.precioanterior                = item.Precioanterior;
                newItem.revision                      = item.Revision;
                newItem.decimalesmonedas              = item.Decimalesmonedas;
                newItem.decimalesmedidas              = item.Decimalesmedidas;
                newItem.bundle                        = item.Bundle?.ToUpper();
                newItem.tblnum                        = item.Tblnum;
                newItem.contenedor                    = item.Contenedor;
                newItem.sello                         = item.Sello;
                newItem.caja                          = item.Caja;
                newItem.pesoneto                      = item.Pesoneto;
                newItem.pesobruto                     = item.Pesobruto;
                newItem.seccion                       = item.Seccion;
                newItem.costeadicionalportes          = item.Costeadicionalportes;
                newItem.costeacicionalvariable        = item.Costeadicionalvariable;
                newItem.costeadicionalmaterial        = item.Costeadicionalmaterial;
                newItem.costeadicionalotro            = item.Costeadicionalotro;
                newItem.flagidentifier                = Guid.NewGuid();
                result.TraspasosalmacenLin.Add(newItem);
            }



            foreach (var item in viewmodel.Costes)
            {
                var newItem = _db.Set <TraspasosalmacenCostesadicionales>().Create();
                newItem.empresa            = Empresa;
                newItem.fktraspasosalmacen = result.id;
                newItem.id                  = item.Id;
                newItem.tipodocumento       = (int)item.Tipodocumento;
                newItem.referenciadocumento = item.Referenciadocumento;
                newItem.importe             = item.Importe;
                newItem.porcentaje          = item.Porcentaje;
                newItem.total               = item.Total;
                newItem.tipocoste           = (int)item.Tipocoste;
                newItem.tiporeparto         = (int)item.Tiporeparto;
                newItem.notas               = item.Notas;
                result.TraspasosalmacenCostesadicionales.Add(newItem);
            }

            return(result);
        }
        public override Articulos EditPersitance(IModelView obj)
        {
            var viewmodel = obj as ArticulosModel;
            //var result = _db.Articulos.Single(f => f.id == viewmodel.Id && f.empresa == viewmodel.Empresa);
            var result = _db.Articulos.Where(f => f.id == viewmodel.Id && f.empresa == viewmodel.Empresa).Include(b => b.ArticulosTercero).ToList().Single();

            /*
             * foreach (var item in result.GetType().GetProperties())
             * {
             *  if (typeof(ArticulosModel).GetProperties().Any(f => f.Name.ToLower() == item.Name.ToLower() && item.Name.ToLower()!= "tipogestionlotes"))
             *      item.SetValue(result, viewmodel.get(item.Name));
             * }
             */

            foreach (var item in result.GetType().GetProperties())
            {
                if ((obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false) &&
                    (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.GetGenericTypeDefinition() !=
                     typeof(ICollection <>)) && item.Name.ToLower() != "tipogestionlotes" && item.Name.ToLower() != "articulostercero" && item.Name.ToLower() != "articuloscomponentes")
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsEnum ?? false)
                {
                    item.SetValue(result, (int)obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (!obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false)
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
            }

            result.tipogestionlotes = (int)viewmodel.Tipogestionlotes;
            result.ArticulosTercero.Clear();


            //Las claves ajenas se copian del result
            foreach (var item in viewmodel.ArticulosTercero)
            {
                var newitem = _db.Set <ArticulosTercero>().Create();
                newitem.empresa                    = result.empresa;
                newitem.id                         = item.Id;
                newitem.codarticulo                = result.id;
                newitem.codtercero                 = item.CodTercero;
                newitem.descripciontercero         = item.DescripcionTercero;
                newitem.codarticulotercero         = item.CodArticuloTercero;
                newitem.descripcionarticulotercero = item.Descripcion;
                result.ArticulosTercero.Add(newitem);
            }

            result.ArticulosComponentes.Clear();
            foreach (var item in viewmodel.ArticulosComponentes)
            {
                var newitem = _db.Set <ArticulosComponentes>().Create();
                newitem.empresa               = result.empresa;
                newitem.fkarticulo            = item.FkArticulo;
                newitem.id                    = item.Id;
                newitem.idcomponente          = item.IdComponente;
                newitem.descripcioncomponente = item.DescripcionComponente;
                newitem.piezas                = item.Piezas;
                newitem.largo                 = item.Largo;
                newitem.ancho                 = item.Ancho;
                newitem.grueso                = item.Grueso;
                newitem.merma                 = item.Merma;
                result.ArticulosComponentes.Add(newitem);
            }


            return(result);
        }
Ejemplo n.º 23
0
        public override Campañas EditPersitance(IModelView obj)
        {
            var objmodel = obj as CampañasModel;
            var result   = _db.Set <Campañas>().Single(f => f.empresa == Context.Empresa && f.id == objmodel.Id);

            foreach (var item in result.GetType().GetProperties())
            {
                if ((obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false) &&
                    (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.GetGenericTypeDefinition() !=
                     typeof(ICollection <>)))
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsEnum ?? false)
                {
                    item.SetValue(result, (int)obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (!obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false)
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
            }

            result.empresa  = objmodel.Empresa;
            result.id       = objmodel.Id;
            result.fkseries = objmodel.Fkseries;
            result.identificadorsegmento = objmodel.Identificadorsegmento;
            result.referencia            = objmodel.Referencia;
            result.fechadocumento        = objmodel.Fechadocumento;
            result.asunto = objmodel.Asunto;
            result.fechaultimoseguimiento  = objmodel.Fechaultimoseguimiento;
            result.fechaproximoseguimiento = objmodel.Fechaproximoseguimiento;
            result.prioridad      = (int)objmodel.Prioridad;
            result.fkmodocontacto = objmodel.Fkmodocontacto;
            result.fkoperario     = objmodel.Fkoperario;
            result.fkcomercial    = objmodel.Fkcomercial;
            result.fkagente       = objmodel.Fkagente;
            result.notas          = objmodel.Notas;
            result.fechacierre    = objmodel.Fechacierre;
            result.coste          = objmodel.Coste;
            result.cerrado        = objmodel.Cerrado;
            result.fkreaccion     = objmodel.Fkreaccion;
            result.fketapa        = objmodel.Fketapa;


            // Añadir las líneas
            result.CampañasTercero.Clear();
            foreach (var item in objmodel.Campañas)
            {
                var newItem = _db.Set <CampañasTercero>().Create();
                newItem.empresa            = item.Empresa;
                newItem.fkcampañas         = item.Fkcampañas;
                newItem.id                 = item.Id;
                newItem.codtercero         = item.Codtercero;
                newItem.descripciontercero = item.Descripciontercero;
                newItem.poblacion          = item.Poblacion;
                newItem.fkprovincia        = item.Fkprovincia;
                newItem.fkpais             = item.Fkpais;
                newItem.email              = item.Email;
                newItem.telefono           = item.Telefono;

                result.CampañasTercero.Add(newItem);
            }

            return(result);
        }
Ejemplo n.º 24
0
        public override Presupuestos EditPersitance(IModelView obj)
        {
            var viewmodel = obj as PresupuestosModel;
            var result    = _db.Set <Presupuestos>().Where(f => f.empresa == Empresa && f.id == viewmodel.Id).Include(f => f.PresupuestosLin).Include(f => f.PresupuestosTotales).Single();

            //todo asignar
            foreach (var item in result.GetType().GetProperties())
            {
                if ((obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false) &&
                    (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.GetGenericTypeDefinition() !=
                     typeof(ICollection <>)))
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsEnum ?? false)
                {
                    item.SetValue(result, (int)obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (!obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false)
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
            }
            //todo asignar contador y referencia
            result.fechamodificacion     = DateTime.Now;
            result.fkusuariomodificacion = Context.Id;
            result.fkpuertosfkpaises     = viewmodel.Fkpuertos.Fkpaises;
            result.fkpuertosid           = viewmodel.Fkpuertos.Id;

            result.PresupuestosLin.Clear();
            foreach (var item in viewmodel.Lineas)
            {
                var newItem = _db.Set <PresupuestosLin>().Create();
                newItem.empresa                       = result.empresa;
                newItem.fkpresupuestos                = result.id;
                newItem.id                            = item.Id;
                newItem.fkarticulos                   = item.Fkarticulos;
                newItem.descripcion                   = item.Descripcion;
                newItem.lote                          = item.Lote;
                newItem.tabla                         = item.Tabla;
                newItem.cantidad                      = item.Cantidad;
                newItem.cantidadpedida                = item.Cantidadpedida;
                newItem.largo                         = item.Largo;
                newItem.ancho                         = item.Ancho;
                newItem.grueso                        = item.Grueso;
                newItem.fkunidades                    = item.Fkunidades;
                newItem.metros                        = item.Metros;
                newItem.precio                        = item.Precio;
                newItem.porcentajedescuento           = item.Porcentajedescuento;
                newItem.importedescuento              = item.Importedescuento;
                newItem.fktiposiva                    = item.Fktiposiva;
                newItem.porcentajeiva                 = item.Porcentajeiva;
                newItem.cuotaiva                      = item.Cuotaiva;
                newItem.porcentajerecargoequivalencia = item.Porcentajerecargoequivalencia ?? 0;
                newItem.cuotarecargoequivalencia      = item.Cuotarecargoequivalencia;
                newItem.importe                       = item.Importe;
                newItem.notas                         = item.Notas;
                newItem.canal                         = item.Canal;
                newItem.precioanterior                = item.Precioanterior;
                newItem.revision                      = item.Revision;
                newItem.decimalesmonedas              = item.Decimalesmonedas;
                newItem.decimalesmedidas              = item.Decimalesmedidas;
                newItem.orden                         = item.Orden;
                newItem.integridadreferenciaflag      = item.Integridadreferenciaflag;
                newItem.intaux                        = item.Intaux;
                result.PresupuestosLin.Add(newItem);
            }

            result.PresupuestosTotales.Clear();
            foreach (var item in viewmodel.Totales)
            {
                var newItem = _db.Set <PresupuestosTotales>().Create();
                newItem.empresa        = result.empresa;
                newItem.fkpresupuestos = result.id;
                newItem.fktiposiva     = item.Fktiposiva;
                newItem.porcentajeiva  = item.Porcentajeiva;
                newItem.basetotal      = item.Baseimponible;
                newItem.brutototal     = item.Brutototal;
                newItem.cuotaiva       = item.Cuotaiva;
                newItem.porcentajerecargoequivalencia = item.Porcentajerecargoequivalencia;
                newItem.importerecargoequivalencia    = item.Importerecargoequivalencia;
                newItem.porcentajedescuentoprontopago = item.Porcentajedescuentoprontopago;
                newItem.importedescuentoprontopago    = item.Importedescuentoprontopago;
                newItem.porcentajedescuentocomercial  = item.Porcentajedescuentocomercial;
                newItem.importedescuentocomercial     = item.Importedescuentocomercial;
                newItem.subtotal         = item.Subtotal;
                newItem.decimalesmonedas = item.Decimalesmonedas;
                result.PresupuestosTotales.Add(newItem);
            }

            result.PresupuestosComponentesLin.Clear();
            foreach (var item in viewmodel.Componentes)
            {
                var newItem = _db.Set <PresupuestosComponentesLin>().Create();
                newItem.empresa                  = Empresa;
                newItem.fkpresupuestos           = result.id;
                newItem.id                       = item.Id;
                newItem.idcomponente             = item.IdComponente;
                newItem.integridadreferenciaflag = item.Integridadreferenciaflag;
                newItem.descripcioncomponente    = item.Descripcioncomponente; newItem.piezas = item.Piezas;
                newItem.piezas                   = item.Piezas;
                newItem.largo                    = item.Largo;
                newItem.ancho                    = item.Ancho;
                newItem.grueso                   = item.Grueso;
                newItem.merma                    = item.Merma;
                newItem.precio                   = item.Precio;
                newItem.precioinicial            = item.PrecioInicial;
                newItem.idlineaarticulo          = item.Idlineaarticulo.Value;
                result.PresupuestosComponentesLin.Add(newItem);
            }
            return(result);
        }
        public override Reservasstock EditPersitance(IModelView obj)
        {
            var viewmodel = obj as ReservasstockModel;
            var result    = _db.Reservasstock.Where(f => f.empresa == viewmodel.Empresa && f.id == viewmodel.Id).Include(b => b.ReservasstockLin).Include(b => b.ReservasstockTotales).ToList().Single();

            //todo asignar
            foreach (var item in result.GetType().GetProperties())
            {
                if ((obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false) &&
                    (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.GetGenericTypeDefinition() !=
                     typeof(ICollection <>)))
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsEnum ?? false)
                {
                    item.SetValue(result, (int)obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (!obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false)
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
            }
            //todo asignar contador y referencia
            result.fechamodificacion     = DateTime.Now;
            result.fkusuariomodificacion = Context.Id;
            result.fkpuertosfkpaises     = viewmodel.Fkpuertos.Fkpaises;
            result.fkpuertosid           = viewmodel.Fkpuertos.Id;
            result.tipoportes            = (int?)viewmodel.Tipodeportes;
            result.ReservasstockLin.Clear();
            foreach (var item in viewmodel.Lineas)
            {
                var newItem = _db.Set <ReservasstockLin>().Create();
                newItem.empresa         = result.empresa;
                newItem.fkreservasstock = result.id;
                newItem.id                            = item.Id;
                newItem.fkarticulos                   = item.Fkarticulos;
                newItem.descripcion                   = item.Descripcion;
                newItem.lote                          = item.Lote;
                newItem.tabla                         = item.Tabla;
                newItem.cantidad                      = item.Cantidad;
                newItem.cantidadpedida                = item.Cantidadpedida;
                newItem.largo                         = item.Largo;
                newItem.ancho                         = item.Ancho;
                newItem.grueso                        = item.Grueso;
                newItem.fkunidades                    = item.Fkunidades;
                newItem.metros                        = item.Metros;
                newItem.precio                        = item.Precio;
                newItem.porcentajedescuento           = item.Porcentajedescuento;
                newItem.importedescuento              = item.Importedescuento;
                newItem.fktiposiva                    = item.Fktiposiva;
                newItem.porcentajeiva                 = item.Porcentajeiva;
                newItem.cuotaiva                      = item.Cuotaiva;
                newItem.porcentajerecargoequivalencia = item.Porcentajerecargoequivalencia ?? 0;
                newItem.cuotarecargoequivalencia      = item.Cuotarecargoequivalencia;
                newItem.importe                       = item.Importe;
                newItem.notas                         = item.Notas;
                newItem.canal                         = item.Canal;
                newItem.precioanterior                = item.Precioanterior;
                newItem.revision                      = item.Revision;
                newItem.decimalesmonedas              = item.Decimalesmonedas;
                newItem.decimalesmedidas              = item.Decimalesmedidas;
                newItem.fkpedidos                     = item.Fkpedidos;
                newItem.fkpedidosid                   = item.Fkpedidosid;
                newItem.fkpedidosreferencia           = item.Fkpedidosreferencia;
                newItem.bundle                        = item.Bundle?.ToUpper();
                newItem.tblnum                        = item.Tblnum;
                newItem.contenedor                    = item.Contenedor;
                newItem.sello                         = item.Sello;
                newItem.caja                          = item.Caja;
                newItem.pesoneto                      = item.Pesoneto;
                newItem.pesobruto                     = item.Pesobruto;
                newItem.seccion                       = item.Seccion;
                newItem.costeadicionalportes          = item.Costeadicionalportes;
                newItem.costeacicionalvariable        = item.Costeadicionalvariable;
                newItem.costeadicionalmaterial        = item.Costeadicionalmaterial;
                newItem.costeadicionalotro            = item.Costeadicionalotro;
                newItem.orden                         = item.Orden;
                newItem.flagidentifier                = item.Flagidentifier;
                result.ReservasstockLin.Add(newItem);
            }

            result.ReservasstockTotales.Clear();
            foreach (var item in viewmodel.Totales)
            {
                var newItem = _db.Set <ReservasstockTotales>().Create();
                newItem.empresa         = result.empresa;
                newItem.fkreservasstock = result.id;
                newItem.fktiposiva      = item.Fktiposiva;
                newItem.porcentajeiva   = item.Porcentajeiva;
                newItem.basetotal       = item.Baseimponible;
                newItem.brutototal      = item.Brutototal;
                newItem.cuotaiva        = item.Cuotaiva;
                newItem.porcentajerecargoequivalencia = item.Porcentajerecargoequivalencia;
                newItem.importerecargoequivalencia    = item.Importerecargoequivalencia;
                newItem.porcentajedescuentoprontopago = item.Porcentajedescuentoprontopago;
                newItem.importedescuentoprontopago    = item.Importedescuentoprontopago;
                newItem.porcentajedescuentocomercial  = item.Porcentajedescuentocomercial;
                newItem.importedescuentocomercial     = item.Importedescuentocomercial;
                newItem.subtotal         = item.Subtotal;
                newItem.decimalesmonedas = item.Decimalesmonedas;
                result.ReservasstockTotales.Add(newItem);
            }
            return(result);
        }
        public override Transformacioneslotes CreatePersitance(IModelView obj)
        {
            var viewmodel = obj as TransformacioneslotesModel;
            var result    = _db.Set <Transformacioneslotes>().Create();

            foreach (var item in result.GetType().GetProperties())
            {
                if ((obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false) &&
                    (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.GetGenericTypeDefinition() !=
                     typeof(ICollection <>)))
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsEnum ?? false)
                {
                    item.SetValue(result, (int)obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (!obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false)
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
            }

            result.fechaalta             = DateTime.Now;
            result.fechamodificacion     = result.fechaalta;
            result.fkusuarioalta         = Context.Id;
            result.fkusuariomodificacion = Context.Id;
            result.empresa = Empresa;



            foreach (var item in viewmodel.Lineas)
            {
                var newItem = _db.Set <Transformacionesloteslin>().Create();
                newItem.empresa                = Empresa;
                newItem.id                     = item.Id;
                newItem.fkarticulos            = item.Fkarticulos;
                newItem.descripcion            = item.Descripcion;
                newItem.lote                   = item.Lote;
                newItem.tabla                  = item.Tabla;
                newItem.cantidad               = item.Cantidad;
                newItem.largo                  = item.Largo;
                newItem.ancho                  = item.Ancho;
                newItem.grueso                 = item.Grueso;
                newItem.fkunidades             = item.Fkunidades;
                newItem.metros                 = item.Metros;
                newItem.notas                  = item.Notas;
                newItem.canal                  = item.Canal;
                newItem.revision               = item.Revision;
                newItem.decimalesmonedas       = item.Decimalesmonedas;
                newItem.decimalesmedidas       = item.Decimalesmedidas;
                newItem.orden                  = item.Orden ?? item.Id;
                newItem.precio                 = item.Precio;
                newItem.flagidentifier         = Guid.NewGuid();
                newItem.costeacicionalvariable = item.Costeadicionalvariable;
                newItem.costeadicionalmaterial = item.Costeadicionalmaterial;
                newItem.costeadicionalotro     = item.Costeadicionalotro;
                newItem.costeadicionalportes   = item.Costeadicionalportes;

                result.Transformacionesloteslin.Add(newItem);
            }

            foreach (var item in viewmodel.Costes)
            {
                var newItem = _db.Set <Transformacioneslotescostesadicionales>().Create();
                newItem.empresa = Empresa;
                newItem.fkTransformacioneslotes = result.id;
                newItem.id                  = item.Id;
                newItem.tipodocumento       = (int)item.Tipodocumento;
                newItem.referenciadocumento = item.Referenciadocumento;
                newItem.importe             = item.Importe;
                newItem.porcentaje          = item.Porcentaje;
                newItem.total               = item.Total;
                newItem.tipocoste           = (int)item.Tipocoste;
                newItem.tiporeparto         = (int)item.Tiporeparto;
                newItem.notas               = item.Notas;
                result.Transformacioneslotescostesadicionales.Add(newItem);
            }

            return(result);
        }
        public override PresupuestosCompras CreatePersitance(IModelView obj)
        {
            var viewmodel = obj as PresupuestosComprasModel;
            var result    = _db.Set <PresupuestosCompras>().Create();

            foreach (var item in result.GetType().GetProperties())
            {
                if ((obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false) &&
                    (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.GetGenericTypeDefinition() !=
                     typeof(ICollection <>)))
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsEnum ?? false)
                {
                    item.SetValue(result, (int)obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
                else if (!obj.GetType().GetProperty(item.Name.FirstToUpper())?.PropertyType.IsGenericType ?? false)
                {
                    item.SetValue(result, obj.GetType().GetProperty(item.Name.FirstToUpper())?.GetValue(obj, null));
                }
            }
            result.id                    = -1;
            result.fechaalta             = DateTime.Now;
            result.fechamodificacion     = result.fechaalta;
            result.fkusuarioalta         = Context.Id;
            result.fkusuariomodificacion = Context.Id;
            result.fkpuertosfkpaises     = viewmodel.Fkpuertos.Fkpaises;
            result.fkpuertosid           = viewmodel.Fkpuertos.Id;

            result.empresa = Empresa;

            foreach (var item in viewmodel.Lineas)
            {
                var newItem = _db.Set <PresupuestosComprasLin>().Create();
                newItem.empresa = Empresa;
                newItem.fkpresupuestoscompras = result.id;
                newItem.id                            = item.Id;
                newItem.fkarticulos                   = item.Fkarticulos;
                newItem.descripcion                   = item.Descripcion;
                newItem.lote                          = item.Lote;
                newItem.tabla                         = item.Tabla;
                newItem.cantidad                      = item.Cantidad;
                newItem.cantidadpedida                = item.Cantidadpedida;
                newItem.largo                         = item.Largo;
                newItem.ancho                         = item.Ancho;
                newItem.grueso                        = item.Grueso;
                newItem.fkunidades                    = item.Fkunidades;
                newItem.metros                        = item.Metros;
                newItem.precio                        = item.Precio;
                newItem.porcentajedescuento           = item.Porcentajedescuento;
                newItem.importedescuento              = item.Importedescuento;
                newItem.fktiposiva                    = item.Fktiposiva;
                newItem.porcentajeiva                 = item.Porcentajeiva;
                newItem.cuotaiva                      = item.Cuotaiva;
                newItem.porcentajerecargoequivalencia = item.Porcentajerecargoequivalencia ?? 0;
                newItem.cuotarecargoequivalencia      = item.Cuotarecargoequivalencia;
                newItem.importe                       = item.Importe;
                newItem.notas                         = item.Notas;
                newItem.canal                         = item.Canal;
                newItem.precioanterior                = item.Precioanterior;
                newItem.revision                      = item.Revision;
                newItem.decimalesmonedas              = item.Decimalesmonedas;
                newItem.decimalesmedidas              = item.Decimalesmedidas;
                newItem.orden                         = item.Orden;
                result.PresupuestosComprasLin.Add(newItem);
            }


            foreach (var item in viewmodel.Totales)
            {
                var newItem = _db.Set <PresupuestosComprasTotales>().Create();
                newItem.empresa = Empresa;
                newItem.fkpresupuestoscompras = result.id;
                newItem.fktiposiva            = item.Fktiposiva;
                newItem.porcentajeiva         = item.Porcentajeiva;
                newItem.basetotal             = item.Baseimponible;
                newItem.brutototal            = item.Brutototal;
                newItem.cuotaiva = item.Cuotaiva;
                newItem.porcentajerecargoequivalencia = item.Porcentajerecargoequivalencia;
                newItem.importerecargoequivalencia    = item.Importerecargoequivalencia;
                newItem.porcentajedescuentoprontopago = item.Porcentajedescuentoprontopago;
                newItem.importedescuentoprontopago    = item.Importedescuentoprontopago;
                newItem.porcentajedescuentocomercial  = item.Porcentajedescuentocomercial;
                newItem.importedescuentocomercial     = item.Importedescuentocomercial;
                newItem.subtotal         = item.Subtotal;
                newItem.decimalesmonedas = item.Decimalesmonedas;

                result.PresupuestosComprasTotales.Add(newItem);
            }



            return(result);
        }