void IAddModifyViewForm.Add(IDTO pNewTimeInterval)
 {
     this.dtpStartTime.Value = DateTime.Now;
     this.dtpEndTime.Value = DateTime.Now;
     this.Text = "Agregar nuevo Intervalo";
     this.iOriginalTimeInterval = (ScheduleEntryDTO)pNewTimeInterval;
 }
 void IAddModifyViewForm.Add(IDTO pNewSlide)
 {
     this.txtDuration.Text = String.Empty;
     //transicion
     this.Text = "Agregar nuevo Slide";
     this.iOriginalSlide = (SlideDTO)pNewSlide;
 }
 void IAddModifyViewForm.Add(IDTO pNewCampaign)
 {
     this.txtTitle.Text = String.Empty;
     this.txtDescription.Text = String.Empty;
     this.Text = "Agregar nueva Campaña";
     this.iOriginalCampaign = (CampaignDTO)pNewCampaign;
 }
 void IAddModifyViewForm.Add(IDTO pNewBanner)
 {
     this.txtName.Text = String.Empty;
     this.txtDescription.Text = String.Empty;
     this.Text = "Agregar nuevo Banner";
     this.iOriginalBanner = (AdminBannerDTO)pNewBanner;
 }
 void IAddModifyViewForm.Add(IDTO pNewStaticText)
 {
     this.txtTitle.Text = String.Empty;
     this.txtDescription.Text = String.Empty;
     this.txtText.Text = String.Empty;
     this.Text = "Agregar nuevo Texto Fijo";
     this.iOriginalStaticText = (StaticTextDTO)pNewStaticText;
 }
 void IAddModifyViewForm.Add(IDTO pNewRSSSource)
 {
     this.txtTitle.Text = String.Empty;
     this.txtDescription.Text = String.Empty;
     this.txtURL.Text = String.Empty;
     this.Text = "Agregar nueva FuenteRSS";
     this.iOriginalRSSSource = (RssSourceDTO)pNewRSSSource;
 }
 void IAddModifyViewForm.Add(IDTO pNewDateInterval)
 {
     this.txtTitle.Text = String.Empty;
     this.dtpStartDate.Value = DateTime.Now;
     this.dtpEndDate.Value = DateTime.Now;
     this.Text = "Agregar nuevo Intervalo";
     this.iOriginalDateInterval = (ScheduleDTO)pNewDateInterval;
 }
        /*public DataGridView DateSource
        {
            get { return this.dgv.DataSource; }
        }*/

        public void Agregar(IAddModifyViewForm pForm ,IDTO pDTO)
        {
            pForm.Agregar(pDTO);
            DialogResult resultado = pForm.ShowForm();
            if (resultado == DialogResult.OK)
            {
                //turno de la fachada
            }
        }
 public void Eliminar(IDTO pDTO)
 {
     DialogResult resultado = MessageBox.Show("¿Está seguro que desea eliminar este elemento?", "Atención", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
     switch (resultado)
     {
         case DialogResult.Yes:
             //this.iFachada.Delete(persona);
             //this.iBinding.Remove(persona);
             break;
         case DialogResult.No:
             break;
     }
 }
 void IAddModifyViewForm.Modify(IDTO pSlide)
 {
     if (pSlide == null)
     {
         throw new ArgumentNullException();
         //TODO excepcion argumentexception creo
     }
     else
     {
         this.iOriginalSlide = (SlideDTO)pSlide;
         this.txtDuration.Text = iOriginalSlide.Duration.ToString();
         this.Text = "Modificar Slide";
     }
 }
 void IAddModifyViewForm.Modify(IDTO pBanner)
 {
     if (pBanner == null)
     {
         throw new EntidadNulaException("El Banner indicado es nulo");
         //TODO excepcion argumentexception creo
     }
     else
     {
         this.iOriginalBanner = (AdminBannerDTO)pBanner;
         this.txtName.Text = iOriginalBanner.Name;
         this.txtDescription.Text = iOriginalBanner.Description;
         this.Text = "Modificar Banner";
     }  
 }
 void IAddModifyViewForm.Modify(IDTO pCampaign)
 {
     if (pCampaign == null)
     {
         throw new EntidadNulaException("La campaña indicada es nula");
         //TODO excepcion argumentexception creo
     }
     else
     {
         this.iOriginalCampaign = (CampaignDTO)pCampaign;
         this.txtTitle.Text = iOriginalCampaign.Name;
         this.txtDescription.Text = iOriginalCampaign.Description;
         this.Text = "Modificar Campaña";
     }
 }
 void IAddModifyViewForm.Modify(IDTO pTimeInterval)
 {
     if (pTimeInterval == null)
     {
         throw new EntidadNulaException("El intervalo de tiempo indicado es nulo");
         //TODO excepcion argumentexception creo
     }
     else
     {
         this.iOriginalTimeInterval = (ScheduleEntryDTO)pTimeInterval;
         this.dtpStartTime.Value = DateTime.MinValue + iOriginalTimeInterval.StartTime;
         this.dtpEndTime.Value = DateTime.MinValue + iOriginalTimeInterval.EndTime;
         this.Text = "Modificar Intervalo";
     }      
 }
 void IAddModifyViewForm.Modify(IDTO pStaticText)
 {
     if (pStaticText == null)
     {
         throw new EntidadNulaException("El texto fijo indicado es nulo");
         //TODO excepcion argumentexception creo
     }
     else
     {
         this.iOriginalStaticText = (StaticTextDTO)pStaticText;
         this.txtTitle.Text = iOriginalStaticText.Title;
         this.txtDescription.Text = iOriginalStaticText.Description;
         this.txtText.Text = iOriginalStaticText.Text;
         this.Text = "Modificar Texto Fijo";
     }    
 }
 void IAddModifyViewForm.Modify(IDTO pRSSSource)
 {
     if (pRSSSource == null)
     {
         throw new EntidadNulaException("La fuente RSS indicada es nula");
         //TODO excepcion argumentexception creo
     }
     else
     {
         this.iOriginalRSSSource = (RssSourceDTO)pRSSSource;
         this.txtTitle.Text = iOriginalRSSSource.Title;
         this.txtDescription.Text = iOriginalRSSSource.Description;
         this.txtURL.Text = iOriginalRSSSource.URL;
         this.Text = "Modificar FuenteRSS";
     }   
 }
Exemple #16
0
        private static void FillData(IDTO dto, EntityBase entity, bool populateEntityFromDTO)
        {
            var dtoType = dto.GetType();
            var entityType = entity.GetType();
            if (!VerifyValidEntityType(entityType, dtoType))
            { 
                throw new EntityConversionException(); 
            }
            var properties = dtoType.GetProperties();
            var sourceObject = populateEntityFromDTO ? (dto as object) : (entity as object);
            var destinationObject = populateEntityFromDTO ? (entity as object) : (dto as object);
            foreach (PropertyInfo property in properties)
            {
                var attributes = property.GetCustomAttributes(typeof(EntityPropertyMappingAttribute), false);
                if (attributes.Length == 0)
                {
                    continue;
                }
                bool skipThisProperty = false;
                foreach (object customAttribute in attributes)
                {
                    EntityPropertyMappingAttribute entityPropertyMappingAttribute = (EntityPropertyMappingAttribute)customAttribute;
                    if (entityPropertyMappingAttribute.MappingDirection == MappingDirectionType.None 
                        || (populateEntityFromDTO && entityPropertyMappingAttribute.MappingDirection == MappingDirectionType.DTOFromEntity)
                        || (!populateEntityFromDTO && entityPropertyMappingAttribute.MappingDirection == MappingDirectionType.EntityFromDTO))
                    {
                        skipThisProperty = true;
                        break;
                    }
                }

                if (skipThisProperty)
                {
                    continue;
                }

                var entityProperty = entityType.GetProperty(property.Name);
                var sourceProperty = populateEntityFromDTO ? property : entityProperty;
                var destinationProperty = populateEntityFromDTO ? entityProperty : property;
                var sourceValue = sourceProperty.GetValue(sourceObject, null);
                if (destinationProperty.CanWrite)
                {
                    destinationProperty.SetValue(destinationObject, sourceValue, null);
                }
            }
        }
 void IAddModifyViewForm.Modify(IDTO pDateInterval)
 {
     if (pDateInterval == null)
     {
         throw new EntidadNulaException("El intervalo de fechas indicado es nulo");
         //TODO excepcion argumentexception creo
     }
     else
     {
         this.iOriginalDateInterval = (ScheduleDTO)pDateInterval;
         this.txtTitle.Text = iOriginalDateInterval.Name;
         this.dtpStartDate.Value = iOriginalDateInterval.ActiveFrom;
         this.dtpEndDate.Value = iOriginalDateInterval.ActiveUntil;
         this.Text = "Modificar Intervalo";
         foreach (Days dia in iOriginalDateInterval.Days)
         {
             switch (dia)
             {
                 case Days.Domingo:
                     this.chkSunday.Checked = true;
                     break;
                 case Days.Lunes:
                     this.chkMonday.Checked = true;
                     break;
                 case Days.Martes:
                     this.chkTuesday.Checked = true;
                     break;
                 case Days.Miercoles:
                     this.chkWednesday.Checked = true;
                     break;
                 case Days.Jueves:
                     this.chkThursday.Checked = true;
                     break;
                 case Days.Viernes:
                     this.chkFriday.Checked = true;
                     break;
                 case Days.Sabado:
                     this.chkSaturday.Checked = true;
                     break;
                 default:
                     break;
             }
         }
     }
 }
Exemple #18
0
        /// <summary>
        /// Fills the data.
        /// </summary>
        /// <param name="viewModel">The dto.</param>
        /// <param name="dto">The viewModel.</param>
        /// <param name="viewModelFromDto">if private set to <c>true</c> [viewModel from dto].</param>
        private static void FillData(ViewModelBase viewModel, IDTO dto, bool viewModelFromDto)
        {
            var dtoType = dto.GetType();
            var viewModelType = viewModel.GetType();
            MappingType mappingType;

            if (!VerifyForViewModelType(viewModelType, dtoType, out mappingType))
            {
                throw new DTOConversionException(string.Format(Thread.CurrentThread.CurrentCulture, "ViewModel type '{0}' must match with type specified in ViewModelMappingAttribute on type '{1}' !", viewModelType.ToString(), dtoType.ToString()));
            }

            var properties = dtoType.GetProperties();

            foreach (PropertyInfo property in properties)
            {
                bool skipThisProperty = false;
                object[] customAttributes = property.GetCustomAttributes(typeof(ViewModelPropertyMappingAttribute), false);
                if (mappingType == MappingType.TotalExplicit && customAttributes.Length == 0)
                {
                    continue;
                }

                foreach (object customAttribute in customAttributes)
                {
                    ViewModelPropertyMappingAttribute entityPropertyMappingAttribute = (ViewModelPropertyMappingAttribute)customAttribute;
                    if (entityPropertyMappingAttribute.MappingDirection == MappingDirectionType.None)
                    {
                        skipThisProperty = true;
                        break;
                    }
                }

                if (skipThisProperty)
                {
                    continue;
                }

                var entityPropertyName = GetEntityPropertyName(property, mappingType, viewModelFromDto);
                if (!string.IsNullOrEmpty(entityPropertyName))
                {
                    var entityProperty = viewModelType.GetProperty(entityPropertyName);

                    if (entityProperty == null)
                    {
                        throw new DTOConversionException(entityPropertyName, dto);
                    }

                    var sourceProperty = viewModelFromDto ? property : entityProperty;
                    var destinationProperty = viewModelFromDto ? entityProperty : property;
                    var sourceObject = viewModelFromDto ? (object)dto : (object)viewModel;
                    var destinationObject = viewModelFromDto ? (viewModel as object) : (dto as object);
                    var sourceValue = sourceProperty.GetValue(sourceObject, null);

                    if (destinationProperty.CanWrite)
                    {
                        if (sourceProperty.PropertyType.IsEnum && destinationProperty.PropertyType == typeof(byte))
                        {
                            sourceValue = (byte)(int)sourceValue;
                        }

                        destinationProperty.SetValue(destinationObject, sourceValue, null);
                    }
                }
            }
        }
 public UpdateToDoItemCommandHandler(IUserManager userAccessor, IDTO dtoMapper, IInstanceDB instanceDB)
 {
     _userAccessor = userAccessor ?? throw new ArgumentNullException(nameof(userAccessor));
     _dtoMapper    = dtoMapper;
     _instanceDB   = instanceDB;
 }
 /// <summary>
 /// Fills the viewModel from DTO.
 /// </summary>
 /// <param name="toViewModel">
 /// The View Model to copy to.
 /// </param>
 /// <param name="fromDTO">
 /// The DTO to copy from.
 /// </param>
 public static void FillViewModelFromDTO(object toViewModel, IDTO fromDTO)
 {
     FillData(toViewModel, fromDTO, true);
 }
 public UpdatePatchToDoListCommandHandler(IPatchToDo patchToDo, IDTO dtoMapper, IInstanceDB instanceDB)
 {
     _patchToDo  = patchToDo;
     _dtoMapper  = dtoMapper;
     _instanceDB = instanceDB;
 }
Exemple #22
0
 /// <summary>
 /// Fills the DTO from entity.
 /// </summary>
 /// <param name="fromEntity">From entity.</param>
 /// <param name="toDTO">To DTO.</param>
 public static void FillDTOFromEntity(object fromEntity, IDTO toDTO)
 {
     FillData(toDTO, fromEntity, false);
 }
        public IViewModel SaveFonogram(IDTO idto)
        {
            _repository.Fonogram(idto);

            return(ConvertToViewModel.GetFonogramViewModel(_repository.GetViewable()));
        }
Exemple #24
0
 public CommonData.ReturnCode SearchData(IDTO searchDto, out DataTable dtResult)
 {
     throw new NotImplementedException();
 }
Exemple #25
0
 public CommonData.ReturnCode InsertData(IDTO insertDto)
 {
     CommonData.ReturnCode returnCode = CategoryDAO.InsertData(insertDto as CategoryDTO);
     return(returnCode);
 }
Exemple #26
0
 public CommonData.ReturnCode UpdateData(IDTO updateDto)
 {
     CommonData.ReturnCode returnCode = CategoryDAO.UpdateData(updateDto as CategoryDTO);
     return(returnCode);
 }
Exemple #27
0
 public CommonData.ReturnCode SearchData(IDTO searchDto, out List <CategoryDTO> list)
 {
     CommonData.ReturnCode returnCode = CategoryDAO.SearchData(searchDto as CategoryDTO, out list);
     return(returnCode);
 }
Exemple #28
0
 public int UpdateData(IDTO updateDto)
 {
     throw new NotImplementedException();
 }
Exemple #29
0
        public int InsertData(IDTO insertDto)
        {
            int returnCode = ItemDAO.InsertData(insertDto as ItemDTO);

            return(returnCode);
        }
        public IViewModel SaveAlbum(IDTO idto)
        {
            _repository.Album(idto);

            return(ConvertToViewModel.GetAlbumViewModel(_repository.GetViewable()));
        }
Exemple #31
0
 /// <summary>
 /// Fills the viewModel from DTO.
 /// </summary>
 /// <param name="toViewModel">
 /// The View Model to copy to.
 /// </param>
 /// <param name="fromDTO">
 /// The DTO to copy from.
 /// </param>
 public static void FillViewModelFromDTO(ViewModelBase toViewModel, IDTO fromDTO)
 {
     FillData(toViewModel, fromDTO, true);
 }
Exemple #32
0
 /// <summary>
 /// Fills Entity from DTO
 /// </summary>
 /// <param name="fromDTO">From DTO</param>
 /// <param name="toEntity"></param>
 public static void FillEntityFromDTO(IDTO fromDTO, EntityBase toEntity)
 {
     FillData(fromDTO, toEntity, true);
 }
Exemple #33
0
 public override IDataParameter CreateParameter(string key, IDTO value) => new SqlParameter($"@{key}", value.Id);
 /// <summary>
 /// Fills the DTO from Complex object.
 /// </summary>
 /// <param name="fromComplex">
 /// The from Complex Object.
 /// </param>
 /// <param name="toDTO">
 /// To DTO.
 /// </param>
 public static void FillDTOFromComplexObject(object fromComplex, IDTO toDTO)
 {
     FillData(toDTO, fromComplex, false);
 }
Exemple #35
0
 public DataSaver(IDTO inputDTO)
 {
     _repository       = new RepSaver();
     _localSaveService = new AppSaveService(_repository);
     evaluateInput(inputDTO);
 }
Exemple #36
0
 /// <summary>
 /// Fills the entity from DTO.
 /// </summary>
 /// <param name="fromDTO">From DTO.</param>
 /// <param name="toEntity">To entity.</param>
 public static void FillEntityFromDTO(IDTO fromDTO, object toEntity)
 {
     FillData(fromDTO, toEntity, true);
 }
        /// <summary>
        /// Fills the data.
        /// </summary>
        /// <param name="dto">The dto.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="entityFromDto">if private set to <c>true</c> [entity from dto].</param>
        private static void FillData(IDTO dto, object entity, bool entityFromDto)
        {
            var         dtoType    = dto.GetType();
            var         entityType = entity.GetType();
            MappingType mappingType;

            if (!VerifyForEntityType(entityType, dtoType, out mappingType))
            {
                throw new EntityConversionException(string.Format(Thread.CurrentThread.CurrentCulture, "Entity type '{0}' must match with type specified in EntityMappingAttribute on type '{1}' !", entityType.ToString(), dtoType.ToString()));
            }

            var properties = dtoType.GetProperties();

            foreach (PropertyInfo property in properties)
            {
                bool skipThisProperty = false;

                object[] customAttributes = property.GetCustomAttributes(typeof(EntityPropertyMappingAttribute), false);
                if (mappingType == MappingType.TotalExplicit && customAttributes.Length == 0)
                {
                    continue;
                }

                foreach (object customAttribute in customAttributes)
                {
                    EntityPropertyMappingAttribute entityPropertyMappingAttribute = (EntityPropertyMappingAttribute)customAttribute;
                    if (entityPropertyMappingAttribute.MappingDirection == MappingDirectionType.None)
                    {
                        skipThisProperty = true;
                        break;
                    }
                }

                if (skipThisProperty)
                {
                    continue;
                }

                var entityPropertyName = GetEntityPropertyName(property, mappingType, entityFromDto);

                if (!string.IsNullOrEmpty(entityPropertyName))
                {
                    var entityProperty = entityType.GetProperty(entityPropertyName);

                    if (entityProperty == null)
                    {
                        throw new EntityConversionException(entityPropertyName, entity);
                    }

                    var sourceProperty      = entityFromDto ? property : entityProperty;
                    var destinationProperty = entityFromDto ? entityProperty : property;
                    var sourceObject        = entityFromDto ? (dto as object) : (entity as object);
                    var destinationObject   = entityFromDto ? (entity as object) : (dto as object);

                    bool    isComplexProperty        = false;
                    DTOType DTOTypeOfComplexProperty = DTOType.Undefined;

                    //var allTypes = Assembly.GetExecutingAssembly();
                    //var aa = allTypes.GetTypes();

                    object[] complexPropertyMappingAttributes = property.GetCustomAttributes(typeof(ComplexPropertyMappingAttribute), false);
                    if (complexPropertyMappingAttributes.Length != 0)
                    {
                        if (complexPropertyMappingAttributes.Length > 1)
                        {
                            throw new EntityConversionException(string.Format("More than one {0} is not allowed at {1}.", "ComplexPropertyMappingAttribute", property.ToString()));
                        }
                        ComplexPropertyMappingAttribute complexPropertyMappingAttribute = (ComplexPropertyMappingAttribute)complexPropertyMappingAttributes[0];
                        isComplexProperty        = true;
                        DTOTypeOfComplexProperty = complexPropertyMappingAttribute.DTOType;
                    }


                    if (isComplexProperty)
                    {
                        object sourcePropertyObject = sourceProperty.GetValue(sourceObject);
                        if (sourcePropertyObject != null)
                        {
                            object destinationPropertyObject = destinationProperty.GetValue(destinationObject);
                            if (destinationPropertyObject == null)
                            {
                                object obj = null;
                                if (entityFromDto)
                                {
                                    // create the entity object
                                    obj = Activator.CreateInstance(destinationProperty.PropertyType);
                                }
                                else
                                {
                                    // create the DTO object
                                    obj = DTOFactory.Instance.Create(DTOTypeOfComplexProperty, null);
                                }
                                destinationProperty.SetValue(destinationObject, obj, null);
                                destinationPropertyObject = destinationProperty.GetValue(destinationObject);
                            }
                            if (entityFromDto)
                            {
                                FillData((IDTO)sourcePropertyObject, destinationPropertyObject, true);
                            }
                            else
                            {
                                FillData((IDTO)destinationPropertyObject, sourcePropertyObject, false);
                            }
                        }
                    }
                    else
                    {
                        var sourceValue = sourceProperty.GetValue(sourceObject, null);

                        if (destinationProperty.CanWrite)
                        {
                            if (sourceProperty.PropertyType.IsEnum && destinationProperty.PropertyType == typeof(byte))
                            {
                                sourceValue = (byte)(int)sourceValue;
                            }
                            destinationProperty.SetValue(destinationObject, sourceValue, null);
                        }
                    }
                }
            }
        }
Exemple #38
0
 public int InsertData(IDTO insertDto)
 {
     throw new NotImplementedException();
 }
Exemple #39
0
 public Search(IDTO inputDTO, ISearcher inputRepository)
 {
     _repository   = inputRepository;
     _localService = new AppSearchService(_repository);
     evaluateInput(inputDTO);
 }
 /// <summary>
 /// Fills the DTO from viewModel.
 /// </summary>
 /// <param name="toDTO">To dto.</param>
 /// <param name="fromViewModel">from view model.</param>
 public static void FillDTOFromViewModel(IDTO toDTO, object fromViewModel)
 {
     FillData(fromViewModel, toDTO, false);
 }
Exemple #41
0
 public CommonData.ReturnCode SearchData(IDTO searchDto, out List <IDTO> list)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// Fills the data.
        /// </summary>
        /// <param name="viewModel">The dto.</param>
        /// <param name="dto">The viewModel.</param>
        /// <param name="viewModelFromDto">if private set to <c>true</c> [viewModel from dto].</param>
        private static void FillData(object viewModel, IDTO dto, bool viewModelFromDto)
        {
            var         dtoType       = dto.GetType();
            var         viewModelType = viewModel.GetType();
            MappingType mappingType;

            if (!VerifyForViewModelType(viewModelType, dtoType, out mappingType))
            {
                throw new DTOConversionException(string.Format(Thread.CurrentThread.CurrentCulture, "ViewModel type '{0}' must match with type specified in ViewModelMappingAttribute on type '{1}' !", viewModelType.ToString(), dtoType.ToString()));
            }

            var properties = dtoType.GetProperties();

            foreach (PropertyInfo property in properties)
            {
                bool     skipThisProperty = false;
                object[] customAttributes = property.GetCustomAttributes(typeof(ViewModelPropertyMappingAttribute), false);
                if (mappingType == MappingType.TotalExplicit && customAttributes.Length == 0)
                {
                    continue;
                }

                foreach (object customAttribute in customAttributes)
                {
                    ViewModelPropertyMappingAttribute entityPropertyMappingAttribute = (ViewModelPropertyMappingAttribute)customAttribute;
                    if (entityPropertyMappingAttribute.MappingDirection == MappingDirectionType.None)
                    {
                        skipThisProperty = true;
                        break;
                    }
                }

                if (skipThisProperty)
                {
                    continue;
                }

                var entityPropertyName = GetEntityPropertyName(property, mappingType, viewModelFromDto);
                if (!string.IsNullOrEmpty(entityPropertyName))
                {
                    var entityProperty = viewModelType.GetProperty(entityPropertyName);

                    if (entityProperty != null)
                    {
                        var sourceProperty      = viewModelFromDto ? property : entityProperty;
                        var destinationProperty = viewModelFromDto ? entityProperty : property;
                        var sourceObject        = viewModelFromDto ? (object)dto : (object)viewModel;
                        var destinationObject   = viewModelFromDto ? (viewModel as object) : (dto as object);
                        var sourceValue         = sourceProperty.GetValue(sourceObject, null);

                        if (destinationProperty.CanWrite)
                        {
                            if (sourceProperty.PropertyType.IsEnum && destinationProperty.PropertyType == typeof(byte))
                            {
                                sourceValue = (byte)(int)sourceValue;
                            }

                            destinationProperty.SetValue(destinationObject, sourceValue, null);
                        }
                    }
                }
            }
        }
Exemple #43
0
        public int SearchData(IDTO searchDto, out DataTable dtResult)
        {
            int returnCode = MeasureDAO.SearchData(searchDto as MeasureDTO, out dtResult);

            return(returnCode);
        }
Exemple #44
0
 public AddToDoItemCommandHandler(IUserManager userAccessor, IDTO dTO, IInstanceDB instanceDB)
 {
     _userAccessor = userAccessor ?? throw new ArgumentNullException(nameof(userAccessor));
     _dTO          = dTO;
     _instanceDB   = instanceDB;
 }
Exemple #45
0
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            Type modelType      = bindingContext.ModelType;
            bool hasComposedKey = modelType.GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IDTO <,>));

            typeProperties.TryGetValue(modelType, out PropertyInfo[] properties);
            if (properties == null)
            {
                properties = modelType.GetProperties();
                typeProperties.Add(modelType, properties);
            }
            IValueProvider             valueProvider      = bindingContext.ValueProvider;
            object                     result             = bindingContext.Model ?? Activator.CreateInstance(modelType);
            IEnumerable <PropertyInfo> filteredProperties = properties.Where(i => i.CanWrite);

            if (hasComposedKey)
            {
                filteredProperties = filteredProperties.Where(i => i.Name != "Id");
            }
            foreach (PropertyInfo property in filteredProperties)
            {
                string name         = property.Name;
                Type   propertyType = property.PropertyType;
                ValueProviderResult propertyValueResult = valueProvider.GetValue(name);
                string propertyValue = propertyValueResult?.AttemptedValue;
                if (propertyValue != null && property.GetCustomAttribute <DataTypeAttribute>()?.DataType != DataType.Password)
                {
                    propertyValue = propertyValue.Trim();
                }
                propertiesValidations.TryGetValue(property, out IEnumerable <ValidationAttribute> validationAttributes);
                if (validationAttributes == null)
                {
                    validationAttributes = property.GetCustomAttributes().Where(i => typeof(ValidationAttribute).IsAssignableFrom(i.GetType())).Cast <ValidationAttribute>();
                    propertiesValidations.Add(property, validationAttributes);
                }
                bool   isValid      = true;
                string errorMessage = null;
                if (validationAttributes.FirstOrDefault(i => i is RequiredAttribute) is RequiredAttribute || !string.IsNullOrEmpty(propertyValue))
                {
                    foreach (ValidationAttribute validation in validationAttributes)
                    {
                        if (!validation.IsValid(propertyValue))
                        {
                            isValid      = false;
                            errorMessage = validation.ErrorMessage;
                            break;
                        }
                    }
                }
                if (isValid)
                {
                    if (typeof(IDTO).IsAssignableFrom(propertyType))
                    {
                        Type basePropertyType = propertyType.GetInterfaces().FirstOrDefault(i => i.IsGenericType && (i.GetGenericTypeDefinition() == typeof(IDTO <>) || i.GetGenericTypeDefinition() == typeof(IDTO <,>)));
                        if (basePropertyType.GetGenericTypeDefinition() == typeof(IDTO <>))
                        {
                            Type basePropertyTypeArgument = basePropertyType.GetGenericArguments()[0];
                            IDTO propertyObjectValue      = Activator.CreateInstance(propertyType) as IDTO;
                            if (basePropertyTypeArgument == typeof(string))
                            {
                                propertyObjectValue.Id = propertyValue;
                            }
                            else if (basePropertyTypeArgument == typeof(Guid) && propertyValue != null)
                            {
                                propertyObjectValue.Id = Guid.Parse(propertyValue);
                            }
                            else if (basePropertyTypeArgument == typeof(byte) && propertyValue != null)
                            {
                                propertyObjectValue.Id = byte.Parse(propertyValue);
                            }
                            property.SetValue(result, propertyObjectValue);
                        }
                        else
                        {
                            Type[]   basePropertyTypeArguments = basePropertyType.GetGenericArguments();
                            Type     basePropertyTypeFirstArgument = basePropertyTypeArguments.First(), basePropertyTypeSecondArgument = basePropertyTypeArguments.Last();
                            IDTO     propertyObjectValue = Activator.CreateInstance(propertyType) as IDTO;
                            Type     idType = typeof(CompositeKey <,>).MakeGenericType(basePropertyTypeFirstArgument, basePropertyTypeSecondArgument);
                            object   idObject = Activator.CreateInstance(idType);
                            object   idFirstKey = null, idSecondKey = null;
                            string[] propertyValues = propertyValue.Split('|');
                            string   firstPropertyValue = propertyValues.First(), secondPropertyValue = propertyValues.Last();
                            if (basePropertyTypeFirstArgument == typeof(string))
                            {
                                idFirstKey = firstPropertyValue;
                            }
                            else if (typeof(IDTO <string>).IsAssignableFrom(basePropertyTypeFirstArgument))
                            {
                                IDTO <string> idFirstKeyObject = Activator.CreateInstance(basePropertyTypeFirstArgument) as IDTO <string>;
                                idFirstKeyObject.Id = firstPropertyValue;
                                idFirstKey          = idFirstKeyObject;
                            }
                            if (basePropertyTypeSecondArgument == typeof(string))
                            {
                                idSecondKey = secondPropertyValue;
                            }
                            else if (typeof(IDTO <string>).IsAssignableFrom(basePropertyTypeSecondArgument))
                            {
                                IDTO <string> idSecondKeyObject = Activator.CreateInstance(basePropertyTypeSecondArgument) as IDTO <string>;
                                idSecondKeyObject.Id = secondPropertyValue;
                                idSecondKey          = idSecondKeyObject;
                            }
                            idType.GetProperty("FirstKey").SetValue(idObject, idFirstKey);
                            idType.GetProperty("SecondKey").SetValue(idObject, idSecondKey);
                            propertyObjectValue.Id = idObject;
                            property.SetValue(result, propertyObjectValue);
                        }
                    }
                    else
                    {
                        if (propertyType == typeof(Guid) && propertyValue != null)
                        {
                            property.SetValue(result, Guid.Parse(propertyValue));
                        }
                        else
                        {
                            property.SetValue(result, propertyValue);
                        }
                    }
                }
                else
                {
                    bindingContext.ModelState.AddModelError(name, errorMessage);
                }
            }
            return(result);
        }
Exemple #46
0
 /// <summary>
 /// Fills the DTO from viewModel.
 /// </summary>
 /// <param name="toDTO">To dto.</param>
 /// <param name="fromViewModel">from view model.</param>
 public static void FillDTOFromViewModel(IDTO toDTO, ViewModelBase fromViewModel)
 {
     FillData(fromViewModel, toDTO, false);
 }
Exemple #47
0
        public void Album(IDTO idto)
        {
            Album album = Deleter.DeleteAlbum(idto.Id);

            _viewable = DbModelsToViewable.ConvertToAlbumViewable(album);
        }
Exemple #48
0
 /// <summary>
 /// Fills DTO from Entity
 /// </summary>
 /// <param name="fromEntity">From Entity</param>
 /// <param name="toDTO">DTO to be filled</param>
 public static void FillDTOFromEntity(EntityBase fromEntity, IDTO toDTO)
 {
     FillData(toDTO, fromEntity, false);
 }
Exemple #49
0
        public void Fonogram(IDTO idto)
        {
            Fonogram fonogram = Deleter.DeleteFonogram(idto.Id);

            _viewable = DbModelsToViewable.ConvertToFonogramViewable(fonogram);
        }
Exemple #50
0
        public void Izvodjac(IDTO idto)
        {
            Izvodjac izvodjac = Deleter.DeleteIzvodjac(idto.Id);

            _viewable = DbModelsToViewable.ConvertToIzvodjacViewable(izvodjac);
        }
        public IViewModel SaveIzvodjac(IDTO idto)
        {
            _repository.Izvodjac(idto);

            return(ConvertToViewModel.GetIzvodjacViewModel(_repository.GetViewable()));
        }
 public SaveReadUpdate(IDTO inputDTO, IRepository inputRepository)
 {
     _repository   = inputRepository;
     _localService = new AppMainService(_repository);
     evaluateInput(inputDTO);
 }
Exemple #53
0
 /// <summary>
 /// Fills the DTO from Complex object.
 /// </summary>
 /// <param name="fromComplex">
 /// The from Complex Object.
 /// </param>
 /// <param name="toDTO">
 /// To DTO.
 /// </param>
 public static void FillDTOFromComplexObject(ComplexObject fromComplex, IDTO toDTO)
 {
     FillData(toDTO, fromComplex, false);
 }