Beispiel #1
0
 public void Update(Model.AttributeType entity)
 {
     using (var context = new ImobeNetContext())
     {
         var attributeTypeRepository = new BaseRepository <Model.AttributeType>(context);
         attributeTypeRepository.Update(entity);
         attributeTypeRepository.SaveChanges();
     }
 }
Beispiel #2
0
        public void InsertUpdate(Model.AttributeType entity, ICollection <AttributeTypeCulture> attributeTypeCulture, int[] attributes, Enums.ActionType actionType)
        {
            using (var context = new ImobeNetContext())
            {
                using (TransactionScope scopeOfTransaction = new TransactionScope())
                {
                    try
                    {
                        var attributeTypeRepository          = new BaseRepository <Model.AttributeType>(context);
                        var attributeTypeCultureRepository   = new BaseRepository <AttributeTypeCulture>(context);
                        var attributeAttributeTypeRepository = new BaseRepository <Model.Attribute_AttributeType>(context);

                        if (actionType == Enums.ActionType.Insert)
                        {
                            attributeTypeRepository.Insert(entity);
                        }
                        else
                        if (actionType == Enums.ActionType.Update)
                        {
                            attributeTypeRepository.Update(entity);
                        }

                        context.SaveChanges();

                        var attributeTypes = (from p in context.AttributeTypeCulture
                                              where p.IDAttributeType == entity.IDAttributeType
                                              select p);

                        //Deletando os idiomas
                        if (attributeTypes != null && attributeTypes.Count() > 0)
                        {
                            foreach (var attributeType in attributeTypes)
                            {
                                attributeTypeCultureRepository.Delete(attributeType);
                            }

                            context.SaveChanges();
                        }

                        // inserindo novos
                        foreach (var attributeType in attributeTypeCulture)
                        {
                            attributeType.IDAttributeType = entity.IDAttributeType.Value;
                            attributeTypeCultureRepository.Insert(attributeType);
                        }

                        context.SaveChanges();

                        var attrAttributeTypes = from aat in context.Attribute_AttributeType
                                                 where aat.IDAttributeType == entity.IDAttributeType
                                                 select aat;

                        //Deletando os atributos vinculados
                        if (attrAttributeTypes != null && attrAttributeTypes.Count() > 0)
                        {
                            foreach (var attrAttributeType in attrAttributeTypes)
                            {
                                attributeAttributeTypeRepository.Delete(attrAttributeType);
                            }

                            context.SaveChanges();
                        }

                        if (attributes != null && attributes.Count() > 0)
                        {
                            //Inserindo novos atributos
                            foreach (var attribute in attributes)
                            {
                                attributeAttributeTypeRepository.Insert(new Attribute_AttributeType()
                                {
                                    IDAttributeType = entity.IDAttributeType.Value, IDAttribute = attribute
                                });
                            }

                            context.SaveChanges();
                        }

                        scopeOfTransaction.Complete();
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        scopeOfTransaction.Dispose();
                    }
                }
            }
        }
Beispiel #3
0
 public void Update(Model.AttributeType entity, ICollection <AttributeTypeCulture> AttributeTypeCulture, int[] attributes)
 {
     this.InsertUpdate(entity, AttributeTypeCulture, attributes, Enums.ActionType.Update);
 }