// PUT api/<TrainingCategory>/5
        public IHttpActionResult PutTrainingCategory(TrainingCategory trainingCategory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //if (id != training.Id)
            //{
            //    return BadRequest();
            //}

            db.Entry(trainingCategory).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                //if (!TrainingExists(id))
                //{
                //    return NotFound();
                //}
                //else
                //{
                //    throw;
                //}
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #2
0
        public int InsertTrainingCategory(TrainingCategory TrainingCategory)
        {
            using (SqlConnection con = new SqlConnection(_ConnectionString.Value.ConnectionString))
            {
                con.Open();
                SqlTransaction sqltrans = con.BeginTransaction();
                var            param    = new DynamicParameters();
                param.Add("@Id", TrainingCategory.Id);
                param.Add("@Code", TrainingCategory.Code);
                param.Add("@Name", TrainingCategory.Name);
                param.Add("@Description", TrainingCategory.Description);
                param.Add("@IsPrimary", TrainingCategory.IsPrimary);
                var result = con.Execute("InsertUpdateSingleTrainingCategory", param, sqltrans, 0, System.Data.CommandType.StoredProcedure);

                if (result > 0)
                {
                    sqltrans.Commit();
                }
                else
                {
                    sqltrans.Rollback();
                }
                return(result);
            }
        }
        public ActionResult DeleteConfirmed(int id)
        {
            TrainingCategory trainingCategory = db.TrainingCategories.Find(id);

            db.TrainingCategories.Remove(trainingCategory);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #4
0
        private HonoplayDbContext InitAndGetDbContext(out Guid tenantId, out int adminUserId, out int trainingSeriesId, out int trainingCategoryId)
        {
            var context = GetDbContext();

            var salt      = ByteArrayExtensions.GetRandomSalt();
            var adminUser = new AdminUser
            {
                Id           = 1,
                Email        = "*****@*****.**",
                Password     = "******".GetSHA512(salt),
                PasswordSalt = salt,
                LastPasswordChangeDateTime = DateTime.Today.AddDays(-5),
            };

            context.AdminUsers.Add(adminUser);

            var tenant = new Tenant
            {
                Name     = "TestTenant#01",
                HostName = "localhost"
            };

            context.Tenants.Add(tenant);

            context.TenantAdminUsers.Add(new TenantAdminUser
            {
                TenantId    = tenant.Id,
                AdminUserId = adminUser.Id,
                CreatedBy   = adminUser.Id
            });

            var trainingSeries = new TrainingSeries
            {
                TenantId  = tenant.Id,
                CreatedBy = adminUser.Id,
                Name      = "testSeries"
            };

            context.TrainingSerieses.Add(trainingSeries);

            var trainingCategory = new TrainingCategory
            {
                CreatedBy   = adminUser.Id,
                Description = "test",
                Name        = "sample",
            };

            context.TrainingCategories.Add(trainingCategory);

            context.SaveChanges();

            adminUserId        = adminUser.Id;
            tenantId           = tenant.Id;
            trainingSeriesId   = trainingSeries.Id;
            trainingCategoryId = trainingCategory.Id;

            return(context);
        }
 public ActionResult Edit([Bind(Include = "ID,Name")] TrainingCategory trainingCategory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(trainingCategory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(trainingCategory));
 }
Пример #6
0
        public static TrainingCategoryView Create(TrainingCategory o)
        {
            var v = new TrainingCategoryView();

            if (!(o?.Data is null))
            {
                Copy.Members(o.Data, v);
            }

            return(v);
        }
        private HonoplayDbContext InitAndGetDbContext(out int trainingCategoryId)
        {
            var context = GetDbContext();
            var salt    = ByteArrayExtensions.GetRandomSalt();

            var adminUser = new AdminUser
            {
                Id           = 1,
                Email        = "*****@*****.**",
                Password     = "******".GetSHA512(salt),
                PasswordSalt = salt,
                LastPasswordChangeDateTime = DateTimeOffset.Now.AddDays(-5)
            };

            context.AdminUsers.Add(adminUser);

            var tenant = new Tenant
            {
                Name      = "testTenant",
                HostName  = "localhost",
                CreatedBy = adminUser.Id
            };

            context.Tenants.Add(tenant);

            context.TenantAdminUsers.Add(new TenantAdminUser
            {
                TenantId    = tenant.Id,
                AdminUserId = adminUser.Id,
                CreatedBy   = adminUser.Id
            });

            var question = new Question
            {
                Duration  = 3,
                Text      = "testQuestion",
                CreatedBy = adminUser.Id,
                TenantId  = tenant.Id
            };

            context.Questions.Add(question);

            var trainingCategory = new TrainingCategory
            {
                Id   = 1,
                Name = "trainingCategory1"
            };

            context.TrainingCategories.Add(trainingCategory);

            trainingCategoryId = trainingCategory.Id;
            context.SaveChanges();
            return(context);
        }
        public IHttpActionResult PostTrainingCategory(TrainingCategory trainingCategory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            db.TrainingCategories.Add(trainingCategory);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = trainingCategory.Id }, trainingCategory));
        }
        public ActionResult Create([Bind(Include = "ID,Name")] TrainingCategory trainingCategory)
        {
            if (ModelState.IsValid)
            {
                db.TrainingCategories.Add(trainingCategory);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(trainingCategory));
        }
        public IHttpActionResult GetTrainingCategory(int id)
        {
            TrainingCategory objOftrainingCategory = db.TrainingCategories.Find(id);

            if (objOftrainingCategory == null)
            {
                return(NotFound());
            }

            return(Ok(objOftrainingCategory));
        }
Пример #11
0
 public IActionResult Delete(int id, TrainingCategory TrainingCategory)
 {
     try
     {
         // TODO: Add update logic here
         _ITraining.DeleteTrainingCategory(TrainingCategory.Id);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
        public IHttpActionResult DeleteTraining(int id)
        {
            TrainingCategory objOftrainingCategory = db.TrainingCategories.Find(id);

            if (objOftrainingCategory == null)
            {
                return(NotFound());
            }

            db.TrainingCategories.Remove(objOftrainingCategory);
            db.SaveChanges();

            return(Ok(objOftrainingCategory));
        }
        // GET: TrainingCategories/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TrainingCategory trainingCategory = db.TrainingCategories.Find(id);

            if (trainingCategory == null)
            {
                return(HttpNotFound());
            }
            return(View(trainingCategory));
        }
Пример #14
0
        public IActionResult Create(TrainingCategory TrainingCategory)
        {
            try
            {
                // TODO: Add insert logic here

                if (ModelState.IsValid)
                {
                    _ITraining.InsertTrainingCategory(TrainingCategory);
                    return(RedirectToAction("Index"));
                }
                return(View(TrainingCategory));
            }
            catch
            {
                return(View());
            }
        }
Пример #15
0
        public override void TestInitialize()
        {
            base.TestInitialize();
            trainings  = new TestRepository();
            entries    = new TestTimetableEntriesRepository();
            types      = new TestTrainingTypesRepository();
            coaches    = new TestCoachesRepository();
            categories = new TestTrainingCategoriesRepository();
            locations  = new TestLocationsRepository();

            trainingData = GetRandom.Object <TrainingData>();
            var t = new Training(trainingData);

            trainings.Add(t).GetAwaiter();

            typeData = GetRandom.Object <TrainingTypeData>();
            var tt = new TrainingType(typeData);

            types.Add(tt).GetAwaiter();

            locationData = GetRandom.Object <LocationData>();
            var l = new Location(locationData);

            locations.Add(l).GetAwaiter();

            coachData = GetRandom.Object <CoachData>();
            var c = new Coach(coachData);

            coaches.Add(c).GetAwaiter();

            categoryData = GetRandom.Object <TrainingCategoryData>();
            var tc = new TrainingCategory(categoryData);

            categories.Add(tc).GetAwaiter();

            obj = new TestClass(trainings, entries, categories, coaches, types, locations);
        }
Пример #16
0
        public static void PopulateTestData(HonoplayDbContext dbContext)
        {
            var tenantId       = Guid.Parse("b0dfcb00-6195-46a7-834e-c58276c3242a");
            var secondTenantId = Guid.Parse("f3878709-3cba-4ed3-4c03-08d70375909d");

            dbContext.Tenants.Add(new Tenant
            {
                Id          = tenantId,
                Name        = "api-test",
                Description = "test",
                HostName    = "localhost",
            });

            var salt      = ByteArrayExtensions.GetRandomSalt();
            var adminUser = new AdminUser
            {
                Email        = "*****@*****.**",
                Password     = "******".GetSHA512(salt),
                PasswordSalt = salt,
                LastPasswordChangeDateTime = DateTime.Today.AddDays(-5),
            };

            dbContext.AdminUsers.Add(adminUser);

            dbContext.TenantAdminUsers.Add(new TenantAdminUser
            {
                TenantId    = tenantId,
                AdminUserId = adminUser.Id,
                CreatedBy   = adminUser.Id
            });

            dbContext.Tenants.Add(new Tenant
            {
                Id          = secondTenantId,
                Name        = "api-tesasdt",
                Description = "test",
                HostName    = "localhosttt",
            });

            dbContext.TenantAdminUsers.Add(new TenantAdminUser
            {
                TenantId    = secondTenantId,
                AdminUserId = adminUser.Id,
                CreatedBy   = adminUser.Id
            });

            var questionTypes = new List <QuestionType>
            {
                new QuestionType
                {
                    Id   = 1,
                    Name = "questionType1"
                },
                new QuestionType
                {
                    Id   = 2,
                    Name = "questionType2"
                }
            };

            dbContext.QuestionTypes.AddRange(questionTypes);

            var questionDifficulties = new List <QuestionDifficulty>
            {
                new QuestionDifficulty
                {
                    Id   = 1,
                    Name = "questionDifficulty1"
                },
                new QuestionDifficulty
                {
                    Id   = 2,
                    Name = "questionDifficulty2"
                }
            };

            dbContext.QuestionDifficulties.AddRange(questionDifficulties);

            var questionCategories = new List <QuestionCategory>
            {
                new QuestionCategory
                {
                    Name     = "questionDifficulty1",
                    TenantId = tenantId
                },
                new QuestionCategory
                {
                    Name     = "questionDifficulty2",
                    TenantId = tenantId
                }
            };

            dbContext.QuestionCategories.AddRange(questionCategories);

            var department = new Department
            {
                CreatedBy = adminUser.Id,
                Name      = "yazilim",
                TenantId  = tenantId
            };

            dbContext.Departments.Add(department);

            var workingStatus = new WorkingStatus
            {
                Name      = "Full-Time",
                CreatedBy = adminUser.Id,
                TenantId  = tenantId
            };

            dbContext.WorkingStatuses.Add(workingStatus);

            var profession = new Profession
            {
                Name      = "Web",
                CreatedBy = adminUser.Id,
                TenantId  = tenantId
            };

            dbContext.Professions.Add(profession);

            var trainingSeries = new TrainingSeries
            {
                Name      = "series1",
                CreatedBy = adminUser.Id,
                TenantId  = tenantId
            };

            dbContext.TrainingSerieses.Add(trainingSeries);


            var trainingCategory = new TrainingCategory
            {
                CreatedBy   = adminUser.Id,
                Description = "sample",
                Name        = "test"
            };

            dbContext.TrainingCategories.Add(trainingCategory);

            var training = new Training
            {
                TrainingCategoryId = trainingCategory.Id,
                BeginDateTime      = DateTimeOffset.Now,
                EndDateTime        = DateTimeOffset.Now.AddDays(5),
                CreatedBy          = adminUser.Id,
                Description        = "description",
                Name             = "test",
                TrainingSeriesId = trainingSeries.Id
            };

            dbContext.Trainings.Add(training);

            var trainerUser = new TrainerUser
            {
                Name         = "Emre",
                PhoneNumber  = "1234567890",
                Surname      = "KAS",
                DepartmentId = department.Id,
                CreatedBy    = adminUser.Id,
                Email        = "*****@*****.**",
                Password     = "******".GetSHA512(salt),
                PasswordSalt = salt,
                ProfessionId = profession.Id
            };

            dbContext.TrainerUsers.Add(trainerUser);

            var traineeUser = new TraineeUser
            {
                DepartmentId           = department.Id,
                Name                   = "Yunus Emre",
                CreatedBy              = adminUser.Id,
                Gender                 = 1,
                Email                  = "*****@*****.**",
                Password               = "******".GetSHA512(salt),
                PasswordSalt           = salt,
                NationalIdentityNumber = "654654654444",
                PhoneNumber            = "053546835411",
                Surname                = "KAS",
                WorkingStatusId        = workingStatus.Id
            };

            dbContext.TraineeUsers.Add(traineeUser);

            var question = new Question
            {
                TenantId  = tenantId,
                CreatedBy = adminUser.Id,
                Duration  = 123,
                Text      = "Yukaridaki yukarida midir?",
            };

            dbContext.Questions.Add(question);

            var option = new Option
            {
                VisibilityOrder = 1,
                CreatedBy       = adminUser.Id,
                Text            = "yukaridadir",
                QuestionId      = question.Id
            };

            dbContext.Options.Add(option);

            var classroom = new Classroom
            {
                CreatedBy     = adminUser.Id,
                Name          = "test",
                TrainerUserId = trainerUser.Id,
                TrainingId    = training.Id,
            };

            dbContext.Classrooms.Add(classroom);

            var game = new Game
            {
                Name = "game1"
            };

            dbContext.Games.Add(game);

            var session = new Session
            {
                UpdatedBy   = adminUser.Id,
                Name        = "test",
                ClassroomId = classroom.Id,
                GameId      = game.Id,
            };

            dbContext.Sessions.Add(session);

            dbContext.TraineeGroups.Add(new TraineeGroup
            {
                CreatedBy = adminUser.Id,
                Name      = "traineeGroup",
                TenantId  = tenantId
            });
            dbContext.ContentFiles.Add(new ContentFile
            {
                Id          = Guid.Parse("4f2b88e3-704c-41d8-a679-f608a159d055"),
                Name        = "contentFile1",
                ContentType = "contentFile1",
                Data        = new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 },
                TenantId    = tenantId,
                CreatedBy   = adminUser.Id
            });

            dbContext.Avatars.Add(new Avatar
            {
                Name       = "avatar1",
                ImageBytes = new byte[] { 0x20 }
            });

            var tag = new Tag
            {
                Name       = "tag1",
                CreatedBy  = adminUser.Id,
                ToQuestion = true
            };

            dbContext.Tags.Add(tag);
            var questionTag = new QuestionTag
            {
                QuestionId = question.Id,
                TagId      = tag.Id
            };

            dbContext.QuestionTags.Add(questionTag);
            dbContext.SaveChanges();
        }
 public static TrainingCategoriesListModel Create(TrainingCategory trainingCategory)
 {
     return(Projection.Compile().Invoke(trainingCategory));
 }
Пример #18
0
        private HonoplayDbContext InitAndGetDbContext(out Guid tenantId)
        {
            var context = GetDbContext();

            var salt      = ByteArrayExtensions.GetRandomSalt();
            var adminUser = new AdminUser
            {
                Id           = 1,
                Email        = "*****@*****.**",
                Password     = "******".GetSHA512(salt),
                PasswordSalt = salt,
                LastPasswordChangeDateTime = DateTime.Today.AddDays(-5),
            };

            context.AdminUsers.Add(adminUser);

            var tenant = new Tenant
            {
                Name     = "TestTenant#01",
                HostName = "localhost"
            };

            context.Tenants.Add(tenant);

            context.TenantAdminUsers.Add(new TenantAdminUser
            {
                TenantId    = tenant.Id,
                AdminUserId = adminUser.Id,
                UpdatedBy   = adminUser.Id
            });

            var trainingSeries = new TrainingSeries
            {
                TenantId  = tenant.Id,
                UpdatedBy = adminUser.Id,
                Name      = "testSeries"
            };

            context.TrainingSerieses.Add(trainingSeries);

            var trainingCategory = new TrainingCategory
            {
                UpdatedBy   = adminUser.Id,
                Description = "test",
                Name        = "sample",
            };

            context.TrainingCategories.Add(trainingCategory);

            var training = new Training
            {
                UpdatedBy          = adminUser.Id,
                BeginDateTime      = DateTimeOffset.Now,
                Description        = "test",
                EndDateTime        = DateTimeOffset.Now.AddDays(5),
                TrainingCategoryId = trainingCategory.Id,
                TrainingSeriesId   = trainingSeries.Id,
                Name = "sample"
            };

            context.Trainings.Add(training);

            var department = new Department
            {
                TenantId  = tenant.Id,
                UpdatedBy = adminUser.Id,
                Name      = "sampleDepartment"
            };

            context.Departments.Add(department);

            var profession = new Profession
            {
                TenantId  = tenant.Id,
                UpdatedBy = adminUser.Id,
                Name      = "testProfession"
            };

            context.Professions.Add(profession);

            var trainerUser = new TrainerUser
            {
                UpdatedBy    = adminUser.Id,
                Name         = "sample",
                DepartmentId = department.Id,
                Email        = "*****@*****.**",
                PhoneNumber  = "16846546544545",
                ProfessionId = profession.Id,
                Surname      = "test"
            };

            context.TrainerUsers.Add(trainerUser);

            var classroom = new Classroom
            {
                UpdatedBy     = adminUser.Id,
                Name          = "test",
                TrainerUserId = trainerUser.Id,
                TrainingId    = training.Id,
            };

            context.Classrooms.Add(classroom);

            var game = new Game
            {
                Name = "game1"
            };

            context.Games.Add(game);

            var session = new Session
            {
                UpdatedBy   = adminUser.Id,
                Name        = "test",
                ClassroomId = classroom.Id,
                GameId      = game.Id,
            };

            context.Sessions.Add(session);

            context.SaveChanges();

            tenantId = tenant.Id;
            return(context);
        }
Пример #19
0
        private HonoplayDbContext InitAndGetDbContext(out Guid tenantId, out int adminUserId, out int trainingId, out int trainerUserId, out int traineeUserId)
        {
            var context = GetDbContext();

            var salt      = ByteArrayExtensions.GetRandomSalt();
            var adminUser = new AdminUser
            {
                Id           = 1,
                Email        = "*****@*****.**",
                Password     = "******".GetSHA512(salt),
                PasswordSalt = salt,
                LastPasswordChangeDateTime = DateTime.Today.AddDays(-5),
            };

            context.AdminUsers.Add(adminUser);

            var tenant = new Tenant
            {
                Name     = "TestTenant#01",
                HostName = "localhost"
            };

            context.Tenants.Add(tenant);

            context.TenantAdminUsers.Add(new TenantAdminUser
            {
                TenantId    = tenant.Id,
                AdminUserId = adminUser.Id,
                CreatedBy   = adminUser.Id
            });

            var trainingSeries = new TrainingSeries
            {
                TenantId  = tenant.Id,
                CreatedBy = adminUser.Id,
                Name      = "testSeries"
            };

            context.TrainingSerieses.Add(trainingSeries);

            var trainingCategory = new TrainingCategory
            {
                CreatedBy   = adminUser.Id,
                Description = "test",
                Name        = "sample",
            };

            context.TrainingCategories.Add(trainingCategory);

            var training = new Training
            {
                CreatedBy          = adminUser.Id,
                BeginDateTime      = DateTimeOffset.Now,
                Description        = "test",
                EndDateTime        = DateTimeOffset.Now.AddDays(5),
                TrainingCategoryId = trainingCategory.Id,
                TrainingSeriesId   = trainingSeries.Id,
                Name = "sample"
            };

            context.Trainings.Add(training);

            var department = new Department
            {
                TenantId  = tenant.Id,
                CreatedBy = adminUser.Id,
                Name      = "sampleDepartment"
            };

            context.Departments.Add(department);

            var profession = new Profession
            {
                TenantId  = tenant.Id,
                CreatedBy = adminUser.Id,
                Name      = "testProfession"
            };

            context.Professions.Add(profession);

            var workingStatus = new WorkingStatus
            {
                CreatedBy = adminUser.Id,
                TenantId  = tenant.Id,
                Name      = "test"
            };

            context.WorkingStatuses.Add(workingStatus);

            var traineeUser = new TraineeUser
            {
                CreatedBy              = adminUser.Id,
                DepartmentId           = department.Id,
                Gender                 = 1,
                Name                   = "asdasd",
                NationalIdentityNumber = "12321421311",
                PhoneNumber            = "912489213123",
                Surname                = "test",
                WorkingStatusId        = 1
            };

            context.TraineeUsers.Add(traineeUser);

            var trainerUser = new TrainerUser
            {
                CreatedBy    = adminUser.Id,
                Name         = "sample",
                DepartmentId = department.Id,
                Email        = "*****@*****.**",
                PhoneNumber  = "16846546544545",
                ProfessionId = profession.Id,
                Surname      = "test"
            };

            context.TrainerUsers.Add(trainerUser);
            context.SaveChanges();

            adminUserId   = adminUser.Id;
            traineeUserId = traineeUser.Id;
            tenantId      = tenant.Id;
            trainingId    = training.Id;
            trainerUserId = trainerUser.Id;

            return(context);
        }