private void SampleDataLoad() { for (var i = 11; i > 1; i--) { var ex = new Exercise(); ex.ExerciseName = "Assignment " + i; ex.ExerciseDate = DateTime.Today.AddDays(-i); ex.DurationInMinutes = 23 + i; exRepository.Create(ex); } }
public ActionResult <Result <bool> > CreateInstance([FromBody] CreateExerciseInstanceRQ body) { #region Map_User var isUserMapped = _userRepo.IsMapped(UserId); if (!isUserMapped) { var sqlUsername = NameHelper.GenerateSqlUserName(UserId); var sqlPass = NameHelper.GenerateRandomSqlPassowrd(); var mapSaveSuccess = _userRepo.CreateMapping(UserId, sqlUsername, sqlPass, UserId); if (!mapSaveSuccess) { return(Result <bool> .Fail("Error mapping user.")); } } var userMapEntity = _userRepo.Get(UserId); #endregion #region Check_Name var exerciseExists = _exerciseRepo.NameExists(body.Name, UserId); if (exerciseExists) { return(Result <bool> .Fail($"Instance '{body.Name}' already exists.")); } #endregion #region Clone_DB var nameOnServer = NameHelper.ExerciseName(); var templateEntity = _templateRepo.Get(body.TemplateId); var cloneSuccess = _msSqlService.CloneDatabase(templateEntity.NameOnServer, nameOnServer, false, true); if (!cloneSuccess) { return(Result <bool> .Fail("Failed to clone database.")); } #endregion #region Create_DB_User var createSuccess = _msSqlService.CreateDbUserContained(userMapEntity.SqlUsername, userMapEntity.SqlPassword, nameOnServer); if (!createSuccess) { return(Result <bool> .Fail("Failed to create database user.")); } var assignSuccess = _msSqlService.AssignCRUD(userMapEntity.SqlUsername, nameOnServer); if (!assignSuccess) { return(Result <bool> .Fail("Failed to assign database user permissions.")); } #endregion #region Save_Record var saveSuccess = _exerciseRepo.Create(body.TemplateId, UserId, body.Name, nameOnServer, UserId); if (!saveSuccess) { return(Result <bool> .Fail("Failed to save record.")); } #endregion return(Result <bool> .Success(true)); }
public void Post([FromBody] ExerciseViewModel exercise) { var exerciseEntity = new Exercise { ExerciseCategoryId = exercise.ExerciseCategoryId, Description = exercise.Description, }; _exerciseRepository.Create(exerciseEntity); foreach (var exerciseTip in exercise.ExerciseTip) { var exerciseTipEntity = new ExerciseTip { ExerciseId = exerciseEntity.Id, Description = exerciseTip.Description }; _exerciseTipRepository.Create(exerciseTipEntity); } }