Пример #1
0
        public string AddProtocol(ref OperationResult pobjOperationResult, protocolDto pobjProtocol, List <protocolcomponentDto> pobjProtocolComponent, List <string> ClientSession)
        {
            //mon.IsActive = true;
            string NewId0 = null;

            try
            {
                SigesoftEntitiesModel dbContext = new SigesoftEntitiesModel();
                protocol objEntity = protocolAssembler.ToEntity(pobjProtocol);

                int intNodeId = 9;

                if (pobjProtocol.v_ProtocolId == null)
                {
                    objEntity.d_InsertDate   = DateTime.Now;
                    objEntity.i_InsertUserId = Int32.Parse(ClientSession[2]);
                    objEntity.i_IsDeleted    = 0;
                    // Autogeneramos el Pk de la tabla

                    NewId0 = Common.Utils.GetNewId(intNodeId, Utils.GetNextSecuentialId(intNodeId, 20), "PR");
                    objEntity.v_ProtocolId = NewId0;

                    dbContext.AddToprotocol(objEntity);
                    dbContext.SaveChanges();
                }
                else
                {
                    // Obtener la entidad fuente
                    var objEntitySource = (from a in dbContext.protocol
                                           where a.v_ProtocolId == pobjProtocol.v_ProtocolId
                                           select a).FirstOrDefault();

                    // Crear la entidad con los datos actualizados
                    pobjProtocol.i_IsDeleted    = 0;
                    pobjProtocol.d_UpdateDate   = DateTime.Now;
                    pobjProtocol.i_UpdateUserId = Int32.Parse(ClientSession[2]);

                    var objStrongEntity = protocolAssembler.ToEntity(pobjProtocol);

                    // Copiar los valores desde la entidad actualizada a la Entidad Fuente
                    dbContext.protocol.ApplyCurrentValues(objStrongEntity);
                }

                // Grabar detalle del protocolo
                foreach (var item in pobjProtocolComponent)
                {
                    protocolcomponent objEntity1 = protocolcomponentAssembler.ToEntity(item);

                    objEntity1.d_InsertDate   = DateTime.Now;
                    objEntity1.i_InsertUserId = Int32.Parse(ClientSession[2]);
                    objEntity1.i_IsDeleted    = 0;

                    var NewId1 = Common.Utils.GetNewId(intNodeId, Utils.GetNextSecuentialId(intNodeId, 21), "PC");
                    objEntity1.v_ProtocolComponentId = NewId1;
                    objEntity1.v_ProtocolId          = pobjProtocol.v_ProtocolId == null ? NewId0 : pobjProtocol.v_ProtocolId;

                    dbContext.AddToprotocolcomponent(objEntity1);
                    dbContext.SaveChanges();
                }

                pobjOperationResult.Success = 1;
            }
            catch (Exception ex)
            {
                pobjOperationResult.Success          = 0;
                pobjOperationResult.ExceptionMessage = Common.Utils.ExceptionFormatter(ex);
                // Llenar entidad Log
            }

            return(NewId0);
        }