예제 #1
0
        public static string UpdateConfiguration(ConfigurationDTO configurationDTO)
        {
            using (DeverateContext db = new DeverateContext())
            {
                var result = from a in db.Account
                             where a.AccountId == configurationDTO.TestOwnerId
                             select a.CompanyId;
                int?companyId = result.First();
                var emps      = from a in db.Account
                                where a.CompanyId == companyId && a.IsActive == true && a.RoleId == 3
                                select new AccountDTO(a);
                if (emps.ToList().Count == 0)
                {
                    return("No available employee");
                }

                Configuration configuration = db.Configuration.SingleOrDefault(con => con.ConfigId == configurationDTO.ConfigId);
                configuration.ConfigId      = configurationDTO.ConfigId;
                configuration.TestOwnerId   = configurationDTO.TestOwnerId;
                configuration.TotalQuestion = configurationDTO.TotalQuestion;
                configuration.CreateDate    = DateTime.Now;
                configuration.StartDate     = configurationDTO.StartDate;
                configuration.EndDate       = configurationDTO.EndDate;
                configuration.Duration      = configurationDTO.Duration;
                configuration.IsActive      = true;
                db.Configuration.Update(configuration);
                db.SaveChanges();

                foreach (var item in configurationDTO.catalogueInConfigurations)
                {
                    CatalogueInConfiguration catalogueInConfiguration = db.CatalogueInConfiguration.SingleOrDefault(con => con.ConfigId == item.ConfigId);
                    catalogueInConfiguration.ConfigId    = configuration.ConfigId;
                    catalogueInConfiguration.CatalogueId = item.CatalogueId;
                    catalogueInConfiguration.WeightPoint = item.WeightPoint;
                    catalogueInConfiguration.IsActive    = item.IsActive;
                    db.CatalogueInConfiguration.Add(catalogueInConfiguration);
                    db.SaveChanges();
                }

                foreach (var item in configurationDTO.ConfigurationRank)
                {
                    ConfigurationRank configurationRank = new ConfigurationRank();
                    configurationRank.ConfigId    = configuration.ConfigId;
                    configurationRank.RankId      = item.RankId;
                    configurationRank.WeightPoint = item.WeightPoint;
                    configurationRank.IsActive    = item.IsActive;
                    db.ConfigurationRank.Add(configurationRank);
                    db.SaveChanges();
                }

                return(null);
            }
        }
 public static string UpdateCatalogue(CatalogueDTO catalogue)
 {
     using (DeverateContext context = new DeverateContext())
     {
         Catalogue cata = context.Catalogue.SingleOrDefault(c => c.CatalogueId == catalogue.CatalogueId);
         cata.Description = catalogue.Description;
         cata.Name        = catalogue.Name;
         cata.IsActive    = catalogue.IsActive;
         context.SaveChanges();
         return("UPdating catalogue success");
     }
 }
예제 #3
0
 public static string removeQuestion(List <QuestionDTO> Question)
 {
     using (DeverateContext context = new DeverateContext())
     {
         foreach (var ques in Question)
         {
             Question questionDb = context.Question.SingleOrDefault(c => c.QuestionId == ques.QuestionId);
             questionDb.IsActive = false;
             context.SaveChanges();
         }
         return("Removing Question success");
     }
 }
 public static string removeCatalogue(List <CatalogueDTO> catalogue)
 {
     using (DeverateContext context = new DeverateContext())
     {
         foreach (var cata in catalogue)
         {
             Catalogue cataDb = context.Catalogue.SingleOrDefault(c => c.CatalogueId == cata.CatalogueId);
             cataDb.IsActive = false;
             context.SaveChanges();
         }
         return("Removing catalog success");
     }
 }
 public static string CreateCatalogue(CatalogueDTO catalogue)
 {
     using (DeverateContext context = new DeverateContext())
     {
         Catalogue cata = new Catalogue();
         cata.Description = catalogue.Description;
         cata.Name        = catalogue.Name;
         cata.IsActive    = catalogue.IsActive;
         context.Catalogue.Add(cata);
         context.SaveChanges();
         return("Creating catalogue success");
     }
 }
예제 #6
0
 public static string UpdateCompany(CompanyDTO company)
 {
     using (DeverateContext db = new DeverateContext())
     {
         Company com = db.Company.SingleOrDefault(co => co.CompanyId == company.CompanyId);
         com.Name     = company.Name;
         com.Address  = company.Address;
         com.Fax      = company.Fax;
         com.Phone    = company.Phone;
         com.IsActive = company.IsActive;
         db.SaveChanges();
         return(null);
     }
 }
예제 #7
0
 public static string DisableCompany(List <CompanyDTO> company)
 {
     using (DeverateContext db = new DeverateContext())
     {
         Company com;
         foreach (var item in company)
         {
             com          = db.Company.SingleOrDefault(co => co.CompanyId == item.CompanyId);
             com.Name     = item.Name;
             com.Address  = item.Address;
             com.IsActive = item.IsActive;
         }
         db.SaveChanges();
         return(null);
     }
 }
예제 #8
0
 public static Company CreateCompany(CompanyDataDTO companyData)
 {
     using (DeverateContext db = new DeverateContext())
     {
         Company com = new Company();
         com.Address  = companyData.CompanyDTO.Address;
         com.Name     = companyData.CompanyDTO.Name;
         com.CreateAt = DateTime.Now;
         com.Fax      = companyData.CompanyDTO.Fax;
         com.Phone    = companyData.CompanyDTO.Phone;
         com.IsActive = companyData.CompanyDTO.IsActive;
         var result = db.Company.Add(com);
         db.SaveChanges();
         return(result.Entity);
     }
 }
예제 #9
0
 public static string CreateQuestion(QuestionDTO ques)
 {
     using (DeverateContext context = new DeverateContext())
     {
         Question question = new Question();
         question.CatalogueId = ques.CatalogueId;
         question.Question1   = ques.Question1;
         question.IsActive    = ques.IsActive;
         question.MaxPoint    = ques.MaxPoint;
         question.CreateBy    = ques.CreateBy;
         question.Answer      = ques.Answer;
         context.Question.Add(question);
         context.SaveChanges();
         return("Creating Question success");
     }
 }
예제 #10
0
        public static string CreateCompanyAccount(DeverateContext context, CompanyManagerDTO cm)
        {
            Account account  = new Account();
            var     items    = cm.fullName.Split(' ');
            string  username = items[items.Length - 1];

            for (int i = 0; i < items.Length - 1; i++)
            {
                username += items[i].ElementAt(0);
            }
            List <Account> accounts = context.Account.ToList();

            username = username.ToUpper() + (accounts[accounts.Count - 1].AccountId + 1);
            username = RemoveVietnameseTone(username);
            bool includeLowercase = true;
            bool includeUppercase = true;
            bool includeNumeric   = true;
            bool includeSpecial   = true;
            bool includeSpaces    = false;
            int  lengthOfPassword = 16;

            string password = PasswordGenerator.GeneratePassword(includeLowercase, includeUppercase, includeNumeric, includeSpecial, includeSpaces, lengthOfPassword);

            while (!PasswordGenerator.PasswordIsValid(includeLowercase, includeUppercase, includeNumeric, includeSpecial, includeSpaces, password))
            {
                password = PasswordGenerator.GeneratePassword(includeLowercase, includeUppercase, includeNumeric, includeSpecial, includeSpaces, lengthOfPassword);
            }
            string salt            = BCrypt.Net.BCrypt.GenerateSalt(13);
            string encodedPassword = BCrypt.Net.BCrypt.HashPassword(password, salt);

            account.Username  = username.ToUpper();
            account.Password  = encodedPassword;
            account.Fullname  = cm.fullName;
            account.Gender    = false;
            account.JoinDate  = DateTime.Now;
            account.RoleId    = 2;
            account.CompanyId = cm.companyId;
            account.IsActive  = true;
            context.Account.Add(account);
            context.SaveChanges();
            return(username.ToUpper() + "_" + password);
        }
예제 #11
0
        /// <summary>
        /// Tạo bài kiểm tra cho người dùng dưa trên config
        /// </summary>
        /// <param name="db"></param>
        /// <param name="accountId"></param>
        /// <param name="config"></param>
        /// <returns></returns>
        public static List <QuestionDTO> GenerateQuestion(DeverateContext db, int?accountId, ConfigurationDTO config)
        {
            List <QuestionDTO> questions = new List <QuestionDTO>();

            try
            {
                Random rand = new Random();
                List <CatalogueDTO> catalogues = GetCatalogueWeights(db, config.configId);
                for (int i = 0; i < catalogues.Count; i++)
                {
                    catalogues[i].questions = GetQuestionOfCatalogue(db, catalogues[i].catalogueId);
                }
                catalogues = GetNumberOfQuestionEachCatalogue(db, config.totalQuestion, catalogues);

                for (int i = 0; i < catalogues.Count; i++)
                {
                    List <int?>        quesIds   = new List <int?>();
                    List <QuestionDTO> totalQues = catalogues[i].questions;
                    int quesLenght = totalQues.Count;
                    int numbOfQues = catalogues[i].numberOfQuestion > catalogues[i].questions.Count ? catalogues[i].questions.Count : catalogues[i].numberOfQuestion.Value;
                    for (int j = 0; j < numbOfQues; j++)
                    {
                        int rQues = rand.Next(0, quesLenght);
                        if (!quesIds.Contains(totalQues[rQues].questionId))
                        {
                            quesIds.Add(totalQues[rQues].questionId);
                            questions.Add(totalQues[rQues]);
                        }
                        else
                        {
                            j--;
                        }
                    }
                }
                questions = Shuffle(questions);

                Test test = new Test();
                test.ConfigId   = config.configId.Value;
                test.AccountId  = accountId;
                test.CreateDate = DateTime.Now;
                test.IsActive   = true;
                db.Test.Add(test);
                db.SaveChanges();

                test.Code = GenerateCode();
                db.SaveChanges();

                for (int i = 0; i < questions.Count; i++)
                {
                    QuestionInTest inTest = new QuestionInTest();
                    inTest.TestId     = test.TestId;
                    inTest.QuestionId = questions[i].questionId;
                    inTest.IsActive   = true;
                    db.QuestionInTest.Add(inTest);
                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                File.WriteAllText("log.txt", e.Message);
            }

            return(questions);
        }