コード例 #1
0
        public void UpdateMedicalExamFieldValues(ref OperationResult pobjOperationResult, List <componentfieldvaluesrestrictionDto> pobjComponentFieldValuesRestrictionAdd, List <componentfieldvaluesrestrictionDto> pobjComponentFieldValuesRestrictionDelete, List <componentfieldvaluesrecommendationDto> pobjComponentFieldValuesRecommendationAdd, List <componentfieldvaluesrecommendationDto> pobjComponentFieldValuesRecommendationDelete, componentfieldvaluesDto pobjDtoEntity, List <string> ClientSession)
        {
            //mon.IsActive = true;

            try
            {
                SigesoftEntitiesModel dbContext = new SigesoftEntitiesModel();

                #region Actualizar Valor

                componentfieldvaluesrestrictionDto objcomponentfieldvaluesrestrictionDto = new componentfieldvaluesrestrictionDto();
                // Obtener la entidad fuente
                var objEntitySource = (from a in dbContext.componentfieldvalues
                                       where a.v_ComponentFieldValuesId == pobjDtoEntity.v_ComponentFieldValuesId
                                       select a).FirstOrDefault();

                // Crear la entidad con los datos actualizados
                pobjDtoEntity.d_UpdateDate   = DateTime.Now;
                pobjDtoEntity.i_UpdateUserId = Int32.Parse(ClientSession[2]);
                componentfieldvalues objEntity = componentfieldvaluesAssembler.ToEntity(pobjDtoEntity);

                // Copiar los valores desde la entidad actualizada a la Entidad Fuente
                dbContext.componentfieldvalues.ApplyCurrentValues(objEntity);

                // Guardar los cambios
                dbContext.SaveChanges();
                #endregion

                #region Crear Restriccion
                int intNodeId = int.Parse(ClientSession[0]);
                foreach (var item in pobjComponentFieldValuesRestrictionAdd)
                {
                    componentfieldvaluesrestriction objEntity1 = componentfieldvaluesrestrictionAssembler.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, 28), "VR");
                    objEntity1.v_ComponentFieldValuesRestrictionId = NewId1;
                    objEntity1.v_ComponentFieldValuesId            = pobjDtoEntity.v_ComponentFieldValuesId;

                    dbContext.AddTocomponentfieldvaluesrestriction(objEntity1);
                }
                // Guardar los cambios
                dbContext.SaveChanges();

                #endregion

                #region Eliminar Restriccion

                if (pobjComponentFieldValuesRestrictionDelete != null)
                {
                    // Eliminar Componentes del protocolo
                    foreach (var item in pobjComponentFieldValuesRestrictionDelete)
                    {
                        // Obtener la entidad fuente
                        var objEntitySource1 = (from a in dbContext.componentfieldvaluesrestriction
                                                where a.v_ComponentFieldValuesRestrictionId == item.v_ComponentFieldValuesRestrictionId
                                                select a).FirstOrDefault();

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

                // Guardar los cambios
                dbContext.SaveChanges();
                #endregion

                #region Crear Recommendation
                foreach (var item in pobjComponentFieldValuesRecommendationAdd)
                {
                    componentfieldvaluesrecommendation objEntity1 = componentfieldvaluesrecommendationAssembler.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, 31), "VC");
                    objEntity1.v_ComponentFieldValuesRecommendationId = NewId1;
                    objEntity1.v_ComponentFieldValuesId = pobjDtoEntity.v_ComponentFieldValuesId;

                    dbContext.AddTocomponentfieldvaluesrecommendation(objEntity1);
                }
                // Guardar los cambios
                dbContext.SaveChanges();

                #endregion

                #region Eliminar Recommendation

                if (pobjComponentFieldValuesRecommendationDelete != null)
                {
                    // Eliminar Componentes del protocolo
                    foreach (var item in pobjComponentFieldValuesRecommendationDelete)
                    {
                        // Obtener la entidad fuente
                        var objEntitySource1 = (from a in dbContext.componentfieldvaluesrecommendation
                                                where a.v_ComponentFieldValuesRecommendationId == item.v_ComponentFieldValuesRecommendationId
                                                select a).FirstOrDefault();

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

                // Guardar los cambios
                dbContext.SaveChanges();
                #endregion

                //// Guardar los cambios
                //dbContext.SaveChanges();

                pobjOperationResult.Success = 1;
                // Llenar entidad Log
                LogBL.SaveLog(ClientSession[0], ClientSession[1], ClientSession[2], LogEventType.ACTUALIZACION, "EXAMEN MÉDICO CAMPO VALOR", "v_MedicalExamId=" + objEntity.v_ComponentFieldValuesId.ToString(), Success.Ok, null);
                return;
            }
            catch (Exception ex)
            {
                pobjOperationResult.Success          = 0;
                pobjOperationResult.ExceptionMessage = Common.Utils.ExceptionFormatter(ex);
                // Llenar entidad Log
                LogBL.SaveLog(ClientSession[0], ClientSession[1], ClientSession[2], LogEventType.ACTUALIZACION, "EXAMEN MÉDICO CAMPO VALOR", "v_MedicalExamId=" + pobjDtoEntity.v_ComponentFieldValuesId.ToString(), Success.Failed, pobjOperationResult.ExceptionMessage);
                return;
            }
        }