public Result UpdateReasons(List <ReasonEntity> list)
        {
            var con    = new DapperConnectionManager();
            var query  = new QueryEntity();
            var result = new Result();

            using (var scope = new TransactionScope())
            {
                query.Query  = @"DELETE FROM Reasons";
                query.Entity = new { };
                result       = con.ExecuteQueryUnScoped(query);
                if (!result.Success)
                {
                    result.Message = "An error occurred";
                    return(result);
                }
                foreach (var item in list)
                {
                    query.Query  = @"INSERT into  Reasons (Ix, Text, Title, TextPrev) VALUES(@Ix, @Text, @Title, @TextPrev)";
                    query.Entity = item;
                    result       = con.ExecuteQueryUnScoped(query);
                    if (!result.Success)
                    {
                        result.Message = "An error occurred";
                        return(result);
                    }
                }
                scope.Complete();
            }
            result.Message = "Reasons updated";
            return(result);
        }
Exemple #2
0
        public Result Insert(RoleEntity entity)
        {
            var    con   = new DapperConnectionManager();
            var    query = new QueryEntity();
            Result result;

            using (var scope = new TransactionScope())
            {
                var linkEntity = new LinkEntity
                {
                    Href   = " ",
                    Name   = entity.Title,
                    Type   = "ROLE",
                    Active = false
                };

                query.Entity = linkEntity;
                query.Query  = @"INSERT INTO Links (Name, Type, Href, Active) VALUES(@Name, @Type, @Href, @Active)";


                result = con.InsertQueryUnScoped(query);
                if (!result.Success)
                {
                    return(result);
                }

                var linkId = (int)result.Entity;

                entity.LinkId = linkId;
                query.Entity  = entity;
                query.Query   = @"INSERT INTO Roles (Name, LinkId, WhatIs, WhatIsTheirRole, Accountabilities, Examples, FurtherInformation, Title, LinkName, Pathways) 
                                               VALUES(@Name, @LinkId, @WhatIs, @WhatIsTheirRole, @Accountabilities, @Examples, @FurtherInformation, @Title, @LinkName, @Pathways)";
                result        = con.InsertQueryUnScoped(query);

                if (!result.Success)
                {
                    result.Message = "An error occurred";
                    return(result);
                }

                //LINK HREF UPDATE
                var queryUpdateLink = new QueryEntity()
                {
                    Entity = new { Href = "/roles/" + (int)result.Entity, LinkId = linkId },
                    Query  = "UPDATE Links set Href = @Href where LinkId = @LinkId"
                };
                var resultUpdateLink = con.ExecuteQueryUnScoped(queryUpdateLink);
                if (!resultUpdateLink.Success)
                {
                    result.Message = "An error occurred";
                    result.Success = false;
                    return(result);
                }

                scope.Complete();
            }
            result.Message = "The role has been created";
            return(result);
        }
Exemple #3
0
        public Result Insert(SectionEntity entity)
        {
            var con    = new DapperConnectionManager();
            var query  = new QueryEntity();
            var result = new Result();

            using (var scope = new TransactionScope())
            {
                var linkEntity = new LinkEntity
                {
                    Href   = " ",
                    Name   = entity.Title,
                    Type   = "SECTION",
                    Active = false
                };

                query.Entity = linkEntity;
                query.Query  = @"INSERT INTO Links (Name, Type, Href, Active) VALUES(@Name, @Type, @Href, @Active)";


                result = con.InsertQueryUnScoped(query);
                if (!result.Success)
                {
                    return(result);
                }
                var linkId = (int)result.Entity;

                entity.LinkId = linkId;
                query.Entity  = entity;
                query.Query   = @"INSERT INTO Sections (Name, Title, Sealed, Published, LinkId) VALUES(@Name, @Title, @Sealed, @Published, @LinkId)";
                result        = con.InsertQueryUnScoped(query);

                if (!result.Success)
                {
                    result.Message = "An error occurred";
                    return(result);
                }

                //LINK HREF UPDATE
                var queryUpdateLink = new QueryEntity()
                {
                    Entity = new { Href = "/sections/" + (int)result.Entity, LinkId = linkId },
                    Query  = "UPDATE Links set Href = @Href where LinkId = @LinkId"
                };
                var resultUpdateLink = con.ExecuteQueryUnScoped(queryUpdateLink);
                if (!resultUpdateLink.Success)
                {
                    result.Message = "An error occurred";
                    result.Success = false;
                    return(result);
                }

                scope.Complete();
            }
            result.Message = "The section has been created";
            return(result);
        }
        public Result UpdateFieldNameAndPosition(int questionId, int position, string fieldName)
        {
            var con    = new DapperConnectionManager();
            var query  = new QueryEntity();
            var result = new Result();

            using (var scope = new TransactionScope())
            {
                query.Query  = @"DELETE FROM UserDataQuestions where QuestionId = @QuestionId";
                query.Entity = new { QuestionId = questionId };

                var resultDelete = con.ExecuteQueryUnScoped(query);

                if (!resultDelete.Success)
                {
                    return(resultDelete);
                }
                if (!string.IsNullOrEmpty(fieldName))
                {
                    query.Query  = @"INSERT UserDataQuestions (QuestionId, FieldName) VALUES (@QuestionId, @FieldName)";
                    query.Entity = new { QuestionId = questionId, FieldName = fieldName };
                    var resultUserData = con.ExecuteQueryUnScoped(query);
                    if (!resultUserData.Success)
                    {
                        return(resultUserData);
                    }
                }


                query.Entity   = new { QuestionId = questionId, Position = position };
                query.Query    = @"UPDATE Questions set Position = @Position where QuestionId = @QuestionId";
                result         = con.ExecuteQuery(query);
                result.Message = result.Success ? "The Position has been updated" : "An error occurred";
                scope.Complete();
            }

            return(result ?? new Result(false));
        }
        public Result EditJobListing(JobListingEntity entity)
        {
            var result = new Result();

            try
            {
                var con         = new DapperConnectionManager();
                var query       = new QueryEntity();
                var credentials = new CredentialsManager();

                // Check if employer is valid

                // check if the listing has required fields
                if (entity.Title == null ||
                    entity.NurseType == null ||
                    entity.Suburb == null)
                {
                    entity.PublishStatus = false;
                }

                entity.ModificationDate = DateTime.Now;

                // TODO : check for each element type and length



                query.Entity = entity;
                query.Query  = @"UPDATE JobListings SET  
                                            [Title] = ISNULL( @Title , Title ) ,
                                            [NurseType] = ISNULL( @NurseType , NurseType ) ,
                                            [SpecialRequirements] = ISNULL( @SpecialRequirements , SpecialRequirements ) ,
                                            [PublishStatus] = ISNULL( @PublishStatus , PublishStatus ) ,
                                            [MinSalary] = ISNULL( @MinSalary , MinSalary ) ,
                                            [MaxSalary] = ISNULL( @MaxSalary , MaxSalary ) ,
                                            [ApplicationDeadline] = ISNULL( @ApplicationDeadline , ApplicationDeadline ) ,
                                            [ModificationDate] = ISNULL( @ModificationDate , ModificationDate ) ,
                                            [Area] = ISNULL( @Area , Area ) ,
                                            [State] = ISNULL( @State , State ) ,
                                            [Country] = ISNULL( @Country , Country ) ,
                                            [Suburb] = ISNULL( @Suburb , Suburb ) ,
                                            [PostalCode] = ISNULL( @PostalCode , PostalCode ) ,
                                            [AddressLine1] = ISNULL( @AddressLine1 , AddressLine1 ) ,
                                            [AddressLine2] = ISNULL( @AddressLine2 , AddressLine2 ) ,
                                            [Completed] = ISNULL( @Completed , Completed ) ,
                                            [JobType] = ISNULL( @JobType , JobType )   
                                     WHERE JobListingId = @JobListingId";


                result = con.ExecuteQueryUnScoped(query);
                return(result);
            }
            catch (Exception ex)
            {
                if (result == null)
                {
                    result = new Result();
                }
                Logger.Log(ex);
                result.Entity  = null;
                result.Success = false;
                result.Message = "An error occurred";
            }
            return(result);
        }
        public Result Update(DomainEntity entity)
        {
            var          con          = new DapperConnectionManager();
            var          query        = new QueryEntity();
            Result       result       = new Result();
            ImageManager imageManager = new ImageManager();

            if (entity.IconFile != null)
            {
                var resImgCheck = imageManager.CheckFileImageAndSave(entity.ImagePath, entity.IconFile, 30, 30, 3000, 3000);
                if (!resImgCheck.Success)
                {
                    return(resImgCheck);
                }
                entity.Icon = resImgCheck.Entity.ToString();
            }

            if (entity.ImageFile != null)
            {
                var resImgCheck = imageManager.CheckFileImageAndSave(entity.ImagePath, entity.ImageFile, 30, 30, 3000, 3000);
                if (!resImgCheck.Success)
                {
                    return(resImgCheck);
                }
                entity.Image = resImgCheck.Entity.ToString();
            }

            using (var scope = new TransactionScope())
            {
                query.Entity  = entity;
                query.Query   = @"Update Domains set Name = @Name, Title = @Title, Text = @Text, Image = @Image, Icon = @Icon, Framework = @Framework WHERE DomainId = @DomainId";
                result        = con.ExecuteQueryUnScoped(query);
                result.Entity = entity.DomainId;
                var queryDeleteActions = new QueryEntity
                {
                    Query  = @"DELETE from DomainsActions where DomainId = @DomainId",
                    Entity = new { DomainId = entity.DomainId }
                };
                var resultDeleteActions = con.ExecuteQueryUnScoped(queryDeleteActions);

                if (!resultDeleteActions.Success)
                {
                    result.Message = "An error occurred";
                    return(result);
                }
                foreach (var item in entity.ActionsList)
                {
                    item.DomainId = entity.DomainId;
                    var queryActionCreate = new QueryEntity
                    {
                        Query  = @"INSERT into DomainsActions (DomainId, ActionId, Position) VALUES( @DomainId, @ActionId, @Position)",
                        Entity = item
                    };
                    var resultAction = con.ExecuteQueryUnScoped(queryActionCreate);

                    if (resultAction.Success)
                    {
                        continue;
                    }

                    result.Message = "An error occurred";
                    return(result);
                }
                scope.Complete();
                result.Message = result.Success ? "The domain has been updated" : "An error occurred";
            }

            return(result);
        }
        public Result Insert(DomainEntity entity)
        {
            var          con          = new DapperConnectionManager();
            var          query        = new QueryEntity();
            var          result       = new Result();
            ImageManager imageManager = new ImageManager();

            if (entity.IconFile != null)
            {
                var resImgCheck = imageManager.CheckFileImageAndSave(entity.ImagePath, entity.IconFile, 100, 100, 3000, 3000);
                if (!resImgCheck.Success)
                {
                    return(resImgCheck);
                }
                entity.Icon = resImgCheck.Entity.ToString();
            }

            if (entity.ImageFile != null)
            {
                var resImgCheck = imageManager.CheckFileImageAndSave(entity.ImagePath, entity.ImageFile, 100, 100, 3000, 3000);
                if (!resImgCheck.Success)
                {
                    return(resImgCheck);
                }
                entity.Image = resImgCheck.Entity.ToString();
            }
            using (var scope = new TransactionScope())
            {
                var linkEntity = new LinkEntity
                {
                    Href   = " ",
                    Name   = entity.Title,
                    Type   = LinksTypes.DOMAIN.ToString(),
                    Active = false
                };

                query.Entity = linkEntity;
                query.Query  = @"INSERT INTO Links (Name, Type, Href, Active) VALUES(@Name, @Type, @Href, @Active)";


                result = con.InsertQueryUnScoped(query);
                if (!result.Success)
                {
                    result.Message = "An error occurred";
                    return(result);
                }
                var linkId = (int)result.Entity;

                entity.LinkId = linkId;
                query.Entity  = entity;
                query.Query   = @"INSERT INTO Domains (Name, Title, Text, LinkId, Image, Icon, Framework) VALUES(@Name, @Title, @Text, @LinkId, @Image, @Icon, @Framework)";
                result        = con.InsertQueryUnScoped(query);

                if (!result.Success)
                {
                    result.Message = "An error occurred";
                    return(result);
                }

                var domainId = (int)result.Entity;

                var queryDeleteActions = new QueryEntity
                {
                    Query  = @"DELETE from DomainsActions where DomainId = @DomainId",
                    Entity = new { DomainId = domainId }
                };
                var resultDeleteActions = con.ExecuteQueryUnScoped(queryDeleteActions);

                if (!resultDeleteActions.Success)
                {
                    result.Message = "An error occurred";
                    return(result);
                }
                foreach (var item in entity.ActionsList)
                {
                    item.DomainId = domainId;
                    var queryActionCreate = new QueryEntity
                    {
                        Query  = @"INSERT into DomainsActions (DomainId, ActionId, Position) VALUES( @DomainId, @ActionId, @Position)",
                        Entity = item
                    };
                    var resultAction = con.ExecuteQueryUnScoped(queryActionCreate);

                    if (resultAction.Success)
                    {
                        continue;
                    }

                    result.Message = "An error occurred";
                    result.Success = false;
                    return(result);
                }


                //update link with href

                var queryUpdateLink = new QueryEntity()
                {
                    Entity = new { Href = string.Concat("/domains/", domainId), LinkId = linkId },
                    Query  = "UPDATE Links set Href = @Href where LinkId = @LinkId"
                };
                var resultUpdateLink = con.ExecuteQueryUnScoped(queryUpdateLink);
                if (!resultUpdateLink.Success)
                {
                    result.Message = "An error occurred";
                    return(result);
                }

                scope.Complete();
                result.Message = "The domain has been created";
            }
            return(result);
        }
        public Result SaveQuiz(UsersQuizzesEntity quiz, Dictionary <int, object> questionsAnswers)
        {
            try
            {
                var con = new DapperConnectionManager();

                var query = new QueryEntity();

                query.Query  = @"SELECT * FROM Users
                            where UserId = @UserId";
                query.Entity = new { UserId = quiz.UserId };
                var result = con.ExecuteQuery <UserEntity>(query);

                if (!result.Success)
                {
                    result.Message = "An error occured";
                    return(result);
                }

                var r = (IEnumerable <UserEntity>)result.Entity;

                var userEntity = r.FirstOrDefault();

                if (userEntity == null)
                {
                    result.Message = "An error occurred";
                    return(result);
                }

                foreach (var item in questionsAnswers)
                {
                    query.Entity = new { QuestionId = item.Key };
                    query.Query  = @"SELECT * FROM UserDataQuestions WHERE QuestionId = @QuestionId";
                    var resultUserData = con.ExecuteQuery <UserDataQuestionsEntity>(query);
                    if (!resultUserData.Success)
                    {
                        resultUserData.Message = "An error occurred";
                        return(resultUserData);
                    }
                    var data = ((IEnumerable <UserDataQuestionsEntity>)resultUserData.Entity).FirstOrDefault();
                    if (data == null)
                    {
                        continue;
                    }

                    var itemData = data.FieldName.ToString();

                    switch (itemData)
                    {
                    case "NurseType":
                        userEntity.NurseType = item.Value.ToString();
                        break;

                    case "Area":
                        userEntity.Area = item.Value.ToString();
                        break;

                    case "ActiveWorking":
                        userEntity.ActiveWorking = item.Value.ToString();
                        break;

                    case "PostalCode":
                        userEntity.PostalCode = item.Value.ToString();
                        break;

                    case "Address":
                        var adress = JsonConvert.DeserializeObject <AddressEntity>(item.Value.ToString());
                        userEntity.State      = adress.State;
                        userEntity.PostalCode = adress.PostalCode;
                        userEntity.Country    = adress.Country;
                        userEntity.Suburb     = adress.Suburb;
                        break;

                    case "Patients":
                        userEntity.Patients = item.Value.ToString();
                        break;

                    case "PatientsTitle":
                        userEntity.PatientsTitle = item.Value.ToString();
                        break;

                    case "Qualification":
                        userEntity.Qualification = item.Value.ToString();
                        break;

                    case "Setting":
                        userEntity.Setting = item.Value.ToString();
                        break;

                    case "Age":
                        userEntity.Age = item.Value.ToString();
                        break;
                    }
                }
                using (var scope = new TransactionScope())
                {
                    query.Entity = new { UserQuizId = quiz.UserQuizId };
                    query.Query  = @"SELECT * FROM UsersQuizzes WHERE UserQuizId = @UserQuizId";
                    result       = con.ExecuteQueryUnScoped <UsersQuizzesEntity>(query);
                    if (!result.Success)
                    {
                        return(result);
                    }

                    quiz.DateVal = DateTime.Now;
                    quiz.Date    = quiz.DateVal.ToString("d MMM yyyy");

                    var q = ((IEnumerable <UsersQuizzesEntity>)result.Entity).FirstOrDefault();

                    if (q != null)
                    {
                        query.Entity = quiz;
                        query.Query  = @"Update UsersQuizzes set Date = @Date , DateVal = @DateVal , Results = @Results , Completed = @Completed, Survey = @Survey where UserQuizId = @UserQuizId";
                        result       = con.ExecuteQueryUnScoped(query);
                    }
                    else
                    {
                        query.Entity = quiz;
                        query.Query  = @"INSERT INTO UsersQuizzes (UserId ,QuizId ,Date, DateVal, Results ,Completed, Type, Survey) VALUES (@UserId ,@QuizId ,@Date, @DateVal ,@Results ,@Completed, @Type, @Survey)";
                        result       = con.InsertQueryUnScoped(query);
                    }

                    var queryUser = new QueryEntity()
                    {
                        Entity = userEntity,
                        Query  = @"UPDATE Users set NurseType = @NurseType, ActiveWorking = @ActiveWorking, Area = @Area, Age = @Age, Country = @Country, Suburb = @Suburb, PostalCode = @PostalCode, State = @State, Patients = @Patients, PatientsTitle =@PatientsTitle, Qualification = @Qualification, Setting = @Setting where UserId = @UserId "
                    };
                    result        = con.ExecuteQueryUnScoped(queryUser);
                    result.Entity = null;
                    scope.Complete();
                    return(result);
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }
            return(new Result(false));
        }
        public Result Insert(SectorEntity entity)
        {
            var con    = new DapperConnectionManager();
            var query  = new QueryEntity();
            var result = new Result();

            using (var scope = new TransactionScope())
            {
                var linkEntity = new LinkEntity
                {
                    Href   = " ",
                    Name   = entity.Title,
                    Type   = LinksTypes.SECTOR.ToString(),
                    Active = false
                };

                query.Entity = linkEntity;
                query.Query  = @"INSERT INTO Links (Name, Type, Href, Active) VALUES(@Name, @Type, @Href, @Active)";


                result = con.InsertQueryUnScoped(query);
                if (!result.Success)
                {
                    result.Message = "An error occurred";
                    return(result);
                }
                var linkId = (int)result.Entity;

                entity.LinkId = linkId;
                query.Entity  = entity;
                query.Query   = @"INSERT INTO Sectors (Name, Title, Published, LinkId) VALUES(@Name, @Title, @Published, @LinkId)";
                result        = con.InsertQueryUnScoped(query);

                if (!result.Success)
                {
                    result.Message = "An error occurred";
                    return(result);
                }
                var sectorId = (int)result.Entity;

                var sectorViewRn = new SectorViewEntity
                {
                    Type      = "RN",
                    Framework = "rn",
                    SectorId  = sectorId
                };

                query.Entity = sectorViewRn;
                query.Query  = @"INSERT INTO SectorViews (Type, Framework, SectorId) VALUES(@Type, @Framework, @SectorId)";
                result       = con.InsertQueryUnScoped(query);
                if (!result.Success)
                {
                    result.Message = "An error occurred";
                    return(result);
                }

                var sectorViewEn = new SectorViewEntity
                {
                    Type      = "EN",
                    Framework = "en",
                    SectorId  = sectorId
                };

                query.Entity = sectorViewEn;
                query.Query  = @"INSERT INTO SectorViews (Type, Framework, SectorId) VALUES(@Type, @Framework, @SectorId)";
                result       = con.InsertQueryUnScoped(query);
                if (!result.Success)
                {
                    result.Message = "An error occurred";
                    return(result);
                }

                //LINK HREF UPDATE
                var queryUpdateLink = new QueryEntity()
                {
                    Entity = new { Href = "/sections/" + sectorId, LinkId = linkId },
                    Query  = "UPDATE Links set Href = @Href where LinkId = @LinkId"
                };
                var resultUpdateLink = con.ExecuteQueryUnScoped(queryUpdateLink);
                if (!resultUpdateLink.Success)
                {
                    result.Message = "An error occurred";
                    result.Success = false;
                    return(result);
                }

                scope.Complete();
                result.Entity  = sectorId;
                result.Message = "The sector has been created";
            }
            return(result);
        }
        public Result Update(QuestionEntity entity)
        {
            var con    = new DapperConnectionManager();
            var result = new Result();

            using (var scope = new TransactionScope())
            {
                var query = new QueryEntity();
                query.Entity = entity;
                query.Query  = @"UPDATE Questions set Text = @Text, SubText = @SubText, EmployerText = IFNULL(@EmployerText, @EmployerText), EmployerSubText = IFNULL(@EmployerSubText, @EmployerSubText)  , SubText = @SubText , Requirements = @Requirements, Examples = @Examples WHERE QuestionId = @QuestionId";
                result       = con.ExecuteQueryUnScoped(query);

                if (!result.Success)
                {
                    return(result);
                }

                var questionId = entity.QuestionId;

                Result resultAnswers;
                var    queryAnswers = new QueryEntity();

                if (entity.Answers.Any())
                {
                    queryAnswers.Entity = new { QuestionId = questionId };
                    queryAnswers.Query  = @"DELETE FROM Answers where QuestionId = @QuestionId";
                    resultAnswers       = con.ExecuteQueryUnScoped(queryAnswers);

                    if (!resultAnswers.Success)
                    {
                        resultAnswers.Message = "An error occurred";
                        return(resultAnswers);
                    }
                }


                foreach (var q in entity.Answers)
                {
                    q.QuestionId        = questionId;
                    queryAnswers.Entity = q;
                    queryAnswers.Query  = @"INSERT INTO Answers (QuestionId, Text, EmployerText , Value, MatchText, Type, TextValue) 
                            VALUES(@QuestionId, @Text, @EmployerText, @Value, @MatchText, @Type, @TextValue)";
                    resultAnswers       = con.InsertQueryUnScoped(queryAnswers);
                    if (!resultAnswers.Success)
                    {
                        resultAnswers.Message = "An error occurred";
                        return(resultAnswers);
                    }
                }


                if (!entity.SectorsQuestions.Any())
                {
                    scope.Complete();
                    result.Entity  = entity.QuestionId;
                    result.Message = result.Success ? "The Question has been created" : "An error occurred";
                    return(result);
                }

                var querySectors = new QueryEntity();
                querySectors.Entity = new { QuestionId = questionId };
                querySectors.Query  = @"DELETE FROM SectorsQuestions where QuestionId = @QuestionId";
                var resultSectors = con.ExecuteQueryUnScoped(querySectors);
                if (!resultSectors.Success)
                {
                    resultSectors.Message = "An error occurred";
                    return(resultSectors);
                }

                foreach (var q in entity.SectorsQuestions)
                {
                    q.QuestionId        = questionId;
                    queryAnswers.Entity = q;
                    queryAnswers.Query  = @"INSERT INTO SectorsQuestions (QuestionId, SectorId, Value) 
                            VALUES(@QuestionId, @SectorId, @Value)";
                    resultSectors       = con.ExecuteQueryUnScoped(queryAnswers);
                    if (!resultSectors.Success)
                    {
                        resultSectors.Message = "An error occurred";
                        return(resultSectors);
                    }
                }

                scope.Complete();
                result.Entity  = entity.QuestionId;
                result.Message = result.Success ? "The Question has been updated" : "An error updated";
            }

            return(result);
        }
        public Result Insert(QuestionEntity entity)
        {
            var con    = new DapperConnectionManager();
            var result = new Result();

            using (var scope = new TransactionScope())
            {
                var query = new QueryEntity();
                query.Entity = entity;
                query.Query  = @"INSERT INTO Questions (QuizId, Type, AspectId, Text, SubText, EmployerText, EmployerSubText, Requirements, Examples) 
                            VALUES(@QuizId, @Type, @AspectId, @Text, @SubText, @EmployerText, @EmployerSubText, @Requirements, @Examples)";
                result       = con.InsertQueryUnScoped(query);

                if (!result.Success)
                {
                    return(result);
                }

                var questionId = (int)result.Entity;

                Result resultAnswers;
                var    queryAnswers = new QueryEntity();
                foreach (var q in entity.Answers)
                {
                    q.QuestionId        = questionId;
                    queryAnswers.Entity = q;
                    queryAnswers.Query  = @"INSERT INTO Answers (QuestionId, Text, EmployerText, Value, MatchText, Type, TextValue) 
                            VALUES(@QuestionId, @Text, @EmployerText, @Value, @MatchText, @Type, @TextValue)";
                    resultAnswers       = con.InsertQueryUnScoped(queryAnswers);
                    if (!resultAnswers.Success)
                    {
                        resultAnswers.Message = "An error occurred";
                        return(resultAnswers);
                    }
                }
                if (!entity.SectorsQuestions.Any())
                {
                    scope.Complete();
                    result.Message = result.Success ? "The Question has been created" : "An error occurred";
                    return(result);
                }

                Result resultSectors;
                var    querySectors = new QueryEntity();

                foreach (var q in entity.SectorsQuestions)
                {
                    q.QuestionId        = questionId;
                    queryAnswers.Entity = q;
                    queryAnswers.Query  = @"INSERT INTO SectorsQuestions (QuestionId, SectorId, Value) 
                            VALUES(@QuestionId, @SectorId, @Value)";
                    resultSectors       = con.ExecuteQueryUnScoped(queryAnswers);
                    if (!resultSectors.Success)
                    {
                        resultSectors.Message = "An error occurred";
                        return(resultSectors);
                    }
                }
                scope.Complete();
                result.Message = result.Success ? "The Question has been created" : "An error occurred";
            }
            return(result);
        }
        public Result Update(AspectEntity entity)
        {
            var con    = new DapperConnectionManager();
            var query  = new QueryEntity();
            var result = new Result();

            using (var scope = new TransactionScope())
            {
                query.Entity = entity;
                query.Query  =
                    @"Update  Aspects set Title=@Title, Text=@Text, Examples=@Examples, OnlineResources=@OnlineResources, FurtherEducation =@FurtherEducation, PeopleContact = @PeopleContact, Levels = @Levels, Position = @Position
                                where AspectId = @AspectId";

                result = con.ExecuteQueryUnScoped(query);

                if (!result.Success)
                {
                    result.Message = "An error occurred";
                    return(result);
                }
                var aspectId = entity.AspectId;



                var listActionsToRemove = entity.ActionsList.Where(x => x.Removed);
                var listActionsToCreate = entity.ActionsList.Where(x => x.Created);
                var listActionsToCopy   = entity.ActionsList.Where(x => x.Added).ToList();

                foreach (var item in listActionsToRemove)
                {
                    var queryActionCreate = new QueryEntity
                    {
                        Query  = @"DELETE from AspectsActions where ActionId = @ActionId",
                        Entity = item
                    };
                    var resultAction = con.ExecuteQuery(queryActionCreate);
                    if (resultAction.Success)
                    {
                        continue;
                    }

                    result.Message = "An error occurred";
                    return(result);
                }


                foreach (var item in listActionsToCreate)
                {
                    var queryActionCreate = new QueryEntity
                    {
                        Query  = @"INSERT into Actions (Text, Title, Type) VALUES(@Text, @Title, @Type)",
                        Entity = item
                    };
                    var resultAction = con.InsertQueryUnScoped(queryActionCreate);

                    item.ActionId = (int)resultAction.Entity;
                    listActionsToCopy.Add(item);
                }


                foreach (var item in listActionsToCopy)
                {
                    item.AspectId = aspectId;
                    var queryActionCreate = new QueryEntity
                    {
                        Query  = @"INSERT into AspectsActions (AspectId, ActionId, LevelAction, Position) VALUES( @AspectId, @ActionId, @LevelAction, @Position)",
                        Entity = item
                    };
                    var resultAction = con.ExecuteQueryUnScoped(queryActionCreate);

                    if (resultAction.Success)
                    {
                        continue;
                    }

                    result.Message = "An error occurred";
                    return(result);
                }
                scope.Complete();
                result.Entity  = aspectId;
                result.Message = "The aspect has been created";
            }
            return(result);
        }
        public Result InsertTest(int domainId, int copyId)
        {
            var con    = new DapperConnectionManager();
            var query  = new QueryEntity();
            var result = new Result();


            query.Entity = new { DomainId = domainId };
            query.Query  = @"SELECT * FROM Aspects where DomainId = @DomainId";

            var domainActions = con.ExecuteQuery <AspectEntity>(query);

            var aspectsList = (IEnumerable <AspectEntity>)domainActions.Entity;

            foreach (var entity in aspectsList)
            {
                using (var scope = new TransactionScope())
                {
                    entity.DomainId = copyId;

                    var linkEntity = new LinkEntity
                    {
                        Href   = " ",
                        Name   = entity.Title,
                        Type   = LinksTypes.ASPECT.ToString(),
                        Active = true
                    };

                    query.Entity = linkEntity;
                    query.Query  = @"INSERT INTO Links (Name, Type, Href, Active) VALUES(@Name, @Type, @Href, @Active)";


                    result = con.InsertQueryUnScoped(query);
                    if (!result.Success)
                    {
                        result.Message = "An error occurred";
                        return(result);
                    }
                    var linkId = (int)result.Entity;

                    entity.LinkId = linkId;
                    query.Entity  = entity;
                    query.Query   = @"INSERT INTO Aspects (DomainId, LinkId, Title, Text, Examples, OnlineResources, FurtherEducation, PeopleContact, Levels) 
                                                    VALUES(@DomainId, @LinkId, @Title, @Text,@Examples, @OnlineResources, @FurtherEducation, @PeopleContact, @Levels )";

                    result = con.InsertQueryUnScoped(query);

                    if (!result.Success)
                    {
                        result.Message = "An error occurred";
                        return(result);
                    }
                    var aspectId = (int)result.Entity;


                    var queryUpdateLink = new QueryEntity()
                    {
                        Entity = new { Href = string.Concat("/aspects/", aspectId), LinkId = linkId },
                        Query  = "UPDATE Links set Href = @Href where LinkId = @LinkId"
                    };
                    var resultUpdateLink = con.ExecuteQueryUnScoped(queryUpdateLink);
                    if (!resultUpdateLink.Success)
                    {
                        result.Message = "An error occurred";
                        result.Success = false;
                        return(result);
                    }


                    scope.Complete();
                    result.Entity  = aspectId;
                    result.Message = "The aspect has been created";
                }
            }



            return(result);
        }
        public Result Insert(AspectEntity entity)
        {
            var con    = new DapperConnectionManager();
            var query  = new QueryEntity();
            var result = new Result();

            using (var scope = new TransactionScope())
            {
                var linkEntity = new LinkEntity
                {
                    Href   = " ",
                    Name   = entity.Title,
                    Type   = LinksTypes.ASPECT.ToString(),
                    Active = false
                };

                query.Entity = linkEntity;
                query.Query  = @"INSERT INTO Links (Name, Type, Href, Active) VALUES(@Name, @Type, @Href, @Active)";


                result = con.InsertQueryUnScoped(query);
                if (!result.Success)
                {
                    result.Message = "An error occurred";
                    return(result);
                }
                var linkId = (int)result.Entity;

                entity.LinkId = linkId;
                query.Entity  = entity;
                query.Query   = @"INSERT INTO Aspects (DomainId, LinkId, Title, Text, Examples, OnlineResources, FurtherEducation, PeopleContact, Levels) 
                                                    VALUES(@DomainId, @LinkId, @Title, @Text,@Examples, @OnlineResources, @FurtherEducation, @PeopleContact, @Levels )";

                result = con.InsertQueryUnScoped(query);

                if (!result.Success)
                {
                    result.Message = "An error occurred";
                    return(result);
                }
                var aspectId = (int)result.Entity;

                var listActionsToCreate = entity.ActionsList.Where(x => x.Created);
                var listActionsToCopy   = entity.ActionsList.Where(x => !x.Created).ToList();


                foreach (var item in listActionsToCreate)
                {
                    var queryActionCreate = new QueryEntity
                    {
                        Query  = @"INSERT into Actions (Text, Title, Type) VALUES(@Text, @Title, @Type)",
                        Entity = item
                    };
                    var resultAction = con.InsertQueryUnScoped(queryActionCreate);
                    if (!resultAction.Success)
                    {
                        result.Message = "An error occurred";
                        return(result);
                    }
                    item.ActionId = (int)resultAction.Entity;
                    listActionsToCopy.Add(item);
                }


                foreach (var item in listActionsToCopy)
                {
                    item.AspectId = aspectId;
                    var queryActionCreate = new QueryEntity
                    {
                        Query  = @"INSERT into AspectsActions (AspectId, ActionId, LevelAction, Position) VALUES( @AspectId, @ActionId, @LevelAction, @Position)",
                        Entity = item
                    };
                    var resultAction = con.ExecuteQueryUnScoped(queryActionCreate);
                    if (!resultAction.Success)
                    {
                        result.Message = "An error occurred";
                        result.Success = false;
                        return(result);
                    }
                }

                //update link with href

                var queryUpdateLink = new QueryEntity()
                {
                    Entity = new { Href = string.Concat("/aspects/", aspectId), LinkId = linkId },
                    Query  = "UPDATE Links set Href = @Href where LinkId = @LinkId"
                };
                var resultUpdateLink = con.ExecuteQueryUnScoped(queryUpdateLink);
                if (!resultUpdateLink.Success)
                {
                    result.Message = "An error occurred";
                    result.Success = false;
                    return(result);
                }


                scope.Complete();
                result.Entity  = aspectId;
                result.Message = "The aspect has been created";
            }
            return(result);
        }