示例#1
0
        public Type ToEntity()
        {
            Type typeAsEntity = new Type()
            {
                Id       = this.Id,
                Name     = this.Name,
                IsActive = this.IsActive,
                Topic    = new Topic()
                {
                    Id = this.TopicId
                },
                AdditionalFields = new List <AdditionalField>()
            };

            if (aFDTOs != null)
            {
                foreach (AdditionalFieldDTO afDTO in this.aFDTOs)
                {
                    AdditionalField af = afDTO.ToEntity();
                    af.Type = typeAsEntity;
                    typeAsEntity.AdditionalFields.Add(af);
                }
            }
            return(typeAsEntity);
        }
示例#2
0
 private void ValidateType(Type type)
 {
     if (IsTypeRegistered(type))
     {
         throw new BusinessLogicException("Error: Type with same name associated to this topic already registered");
     }
 }
        public List <Area> ParseElements(List <AreaImpModel> areaImpModels)
        {
            List <Area> realAreas = new List <Area>();

            foreach (AreaImpModel areaImp in areaImpModels)
            {
                Area realArea = new Area();
                realArea.Name = areaImp.Name;
                if (areaImp.Topics != null)
                {
                    foreach (TopicImpModel topicImp in areaImp.Topics)
                    {
                        Topic realTopic = new Topic();
                        realTopic.Name = topicImp.Name;
                        realTopic.Area = realArea;
                        if (topicImp.Types != null)
                        {
                            foreach (TypeImpModel typeImp in topicImp.Types)
                            {
                                Type realType = new Type();
                                realType.AdditionalFields = new List <AdditionalField>();
                                realType.Name             = typeImp.Name;
                                realType.Topic            = realTopic;
                                realTopic.Types.Add(realType);
                            }
                            realArea.Topics.Add(realTopic);
                        }
                    }
                    realAreas.Add(realArea);
                }
            }
            return(realAreas);
        }
示例#4
0
 private void ValidateTopic(Type type)
 {
     if (!IsTopicRegistered(type.Topic.Id))
     {
         throw new BusinessLogicException("Error: Topic does not exist");
     }
 }
        private void AreValuesValid(Request request, Type type)
        {
            AdditionalField addFieldById;

            foreach (AFValue afv in request.AddFieldValues)
            {
                addFieldById = type.AdditionalFields.Find(x => x.Id == afv.AdditionalFieldID);
                ValidateAFVObject(afv);
                if (addFieldById.FieldType == FieldType.Bool)
                {
                    ValidateBoolAFV(afv);
                }
                if (addFieldById.FieldType == FieldType.Texto)
                {
                    ValidateTextAFV(addFieldById, afv);
                }
                else if (addFieldById.FieldType == FieldType.Entero)
                {
                    ValidateIntegerAFV(addFieldById, afv);
                }
                else if (addFieldById.FieldType == FieldType.Fecha)
                {
                    ValidateDateAFV(addFieldById, afv);
                }
            }
        }
 private void ProcessTypeFromExistingTopic(Type type)
 {
     if (IsValidString(type.Name))
     {
         Type typeByName = typeRepository.GetByCondition(t => t.Name == type.Name &&
                                                         t.Topic.Name == type.Topic.Name);
         if (typeByName == null)
         {
             type.CreationDate     = DateTime.Now;
             type.Id               = Guid.NewGuid();
             type.IsActive         = true;
             type.AdditionalFields = new List <AdditionalField>();
             type.Topic            = topicRepository.GetByCondition(t => t.Name == type.Topic.Name &&
                                                                    t.Area.Name == type.Topic.Area.Name);
             typeRepository.Add(type);
             typeRepository.SaveChanges();
         }
         else
         {
             throw new ImportException($"Error on import: Type: {type.Name} from Topic: {type.Topic.Name} from Area: {type.Topic.Area.Name} already exists");
         }
     }
     else
     {
         throw new ImportException($"Error on import: Type from Topic: {type.Topic.Name} from Area: {type.Topic.Area.Name} was invalid");
     }
 }
示例#7
0
 public void ValidateAdd(Type type)
 {
     ValidateEntityObject(type);
     ValidateTopic(type);
     ValidateType(type);
     ValidateAdditionalFields(type);
 }
示例#8
0
 public void ValidateEntityObject(Type type)
 {
     if (AreEmptyFields(type))
     {
         throw new BusinessLogicException("Error: Type had empty fields");
     }
 }
示例#9
0
        private bool IsTypeRegistered(Type type)
        {
            type.Topic = topicRespository.Get(type.Topic.Id);
            Type typeInDB = typeRepository.GetByCondition(t => t.Name == type.Name &&
                                                          t.Topic == type.Topic);

            return(typeInDB != null);
        }
示例#10
0
        private void GiveNewTypeFormat(Type type)
        {
            Topic realEntity = topicRespository.Get(type.Topic.Id);

            type.Topic        = realEntity;
            type.IsActive     = true;
            type.CreationDate = DateTime.Now;
            type.Id           = Guid.NewGuid();
        }
示例#11
0
        public void ValidateDelete(Type type)
        {
            Type typeById = typeRepository.Get(type.Id);

            if (typeById == null || !typeById.IsActive)
            {
                throw new BusinessLogicException("Error: Type to delete doesn't exist");
            }
        }
示例#12
0
 public Type Create(Type type)
 {
     typeValidator.ValidateAdd(type);
     GiveNewTypeFormat(type);
     FormatAdditionalFields(type);
     typeRepository.Add(type);
     typeRepository.SaveChanges();
     return(type);
 }
示例#13
0
        public Type Get(Guid id)
        {
            Type typeById = typeRepository.Get(id);

            if (typeById == null)
            {
                throw new BusinessLogicException("Error: Invalid ID, Type does not exist");
            }
            return(typeById);
        }
示例#14
0
 private bool Exists(List <Type> types, Type type)
 {
     for (int i = 0; i < types.Count; i++)
     {
         if (types[i].Id == type.Id)
         {
             return(true);
         }
     }
     return(false);
 }
示例#15
0
 public TypeDTO(Type type)
 {
     Id       = type.Id;
     Name     = type.Name;
     TopicId  = type.Topic.Id;
     IsActive = type.IsActive;
     aFDTOs   = new List <AdditionalFieldDTO>();
     foreach (AdditionalField af in type.AdditionalFields)
     {
         AdditionalFieldDTO afDTO = new AdditionalFieldDTO(af);
         aFDTOs.Add(afDTO);
     }
 }
示例#16
0
 private void ValidateAdditionalFields(Type type)
 {
     if (type.AdditionalFields.Count != 0)
     {
         foreach (AdditionalField af in type.AdditionalFields)
         {
             if (!IsAFValid(af, type))
             {
                 throw new BusinessLogicException("Error: AdditionalField had empty fields");
             }
             ValidateAFRange(af);
         }
     }
 }
        public void ValidateAFValues(Request request)
        {
            Type typeById = typeRepository.Get(request.TypeId);

            typeById.AdditionalFields = afRepository.GetAllByCondition(a => a.Type.Id == typeById.Id).ToList();
            foreach (AdditionalField af in typeById.AdditionalFields)
            {
                af.Range = rangeRepository.GetAllByCondition(r => r.AdditionalField.Id == af.Id).ToList();
            }
            if (typeById.AdditionalFields != null && typeById.AdditionalFields.Count != 0)
            {
                AreAFValuesEmpty(request.AddFieldValues);
                AreValuesValid(request, typeById);
            }
        }
示例#18
0
 private void FormatAdditionalFields(Type type)
 {
     foreach (AdditionalField af in type.AdditionalFields)
     {
         af.Id   = Guid.NewGuid();
         af.Type = type;
         if (af.Range.Count != 0)
         {
             foreach (AFRangeItem range in af.Range)
             {
                 range.Id = Guid.NewGuid();
                 range.AdditionalField = af;
             }
         }
     }
 }
示例#19
0
        public Topic ToEntity()
        {
            Topic topicAsEntity = new Topic()
            {
                Id    = this.Id,
                Name  = this.Name,
                Types = new List <Type>()
            };

            if (Types != null)
            {
                foreach (TypeDTO typeDTO in Types)
                {
                    Type type = typeDTO.ToEntity();
                    type.Topic = topicAsEntity;
                    topicAsEntity.Types.Add(type);
                }
            }
            return(topicAsEntity);
        }
示例#20
0
 public void Remove(Type type)
 {
     typeValidator.ValidateDelete(type);
     typeRepository.SoftDelete(type);
     typeRepository.SaveChanges();
 }
        public void GetType_InexistentType_ShouldReturnNull()
        {
            Type typeById = typeRepositoryInMemory.Get(brokenContainer.Id);

            Assert.IsNull(typeById);
        }
示例#22
0
 public bool AreEmptyFields(Type type)
 {
     return(!IsValidString(type.Name) || type.Topic == null ||
            type.AdditionalFields == null);
 }
示例#23
0
 private bool IsAFValid(AdditionalField af, Type type)
 {
     return(af.Range != null && af.Type == type && IsValidString(af.Name));
 }
示例#24
0
        public void GenerateReportTypeB()
        {
            Area oneArea = new Area()
            {
                Name = "Limpieza"
            };

            Topic oneTopic = new Topic()
            {
                Name = "Limpieza Ciudad",
                Area = oneArea
            };

            Type oneType = new Type()
            {
                Name         = "Liempieza Calle",
                Topic        = oneTopic,
                CreationDate = DateTime.Now
            };

            Type anotherType = new Type()
            {
                Name         = "Liempieza Cuadra",
                Topic        = oneTopic,
                CreationDate = DateTime.Now.AddDays(-3)
            };

            Type anotherType2 = new Type()
            {
                Name         = "Liempieza Barrio",
                Topic        = oneTopic,
                CreationDate = DateTime.Now.AddDays(-2)
            };

            Request req1 = new Request()
            {
                RequestNumber = 1,
                CreationDate  = DateTime.Now,
                Email         = "*****@*****.**",
                Status        = Status.Creada,
                Type          = oneType
            };
            Request req2 = new Request()
            {
                Email         = "*****@*****.**",
                RequestNumber = 2,
                Status        = Status.Creada,
                Type          = oneType
            };
            Request req3 = new Request()
            {
                Email         = "*****@*****.**",
                RequestNumber = 3,
                Status        = Status.Aceptada,
                Type          = anotherType
            };

            Request req4 = new Request()
            {
                Email         = "*****@*****.**",
                RequestNumber = 4,
                Status        = Status.Aceptada,
                Type          = anotherType2
            };

            ReportTypeBElement repBElem1 = new ReportTypeBElement()
            {
                Amount = 2,
                Type   = oneType,
            };

            ReportTypeBElement repBElem2 = new ReportTypeBElement()
            {
                Amount = 1,
                Type   = anotherType,
            };

            ReportTypeBElement repBElem3 = new ReportTypeBElement()
            {
                Amount = 1,
                Type   = anotherType2,
            };

            List <Request> requests = new List <Request>();

            requests.Add(req1);
            requests.Add(req2);
            requests.Add(req3);
            requests.Add(req4);

            List <ReportTypeBElement> report = new List <ReportTypeBElement>();

            report.Add(repBElem1);
            report.Add(repBElem2);
            report.Add(repBElem3);

            var reqRepoMock   = new Mock <IRequestRepository>(MockBehavior.Strict);
            var adminRepoMock = new Mock <IRepository <Admin> >(MockBehavior.Strict);

            reqRepoMock.Setup(m => m.GetAllByCondition(It.IsAny <Expression <Func <Request, bool> > >())).Returns(requests);

            var adminLogic = new AdminLogic(adminRepoMock.Object, reqRepoMock.Object);

            List <ReportTypeBElement> reportGenerated = (List <ReportTypeBElement>)adminLogic.GenerateReportB(DateTime.Now.AddDays(-1), DateTime.Now.AddDays(+1));

            reqRepoMock.VerifyAll();

            Assert.IsTrue(report.SequenceEqual(reportGenerated));
        }
        private bool IsTypeValid(Guid id)
        {
            Type typeInDB = typeRepository.Get(id);

            return(typeInDB != null && typeInDB.IsActive);
        }