public void Create([Bind(Include = "ContactInformationType,Value")] ContactInformation contactInformation, int contactRecordId) { if (ModelState.IsValid) { db.ContactInformations.Add(contactInformation); AddToContactRecord(contactRecordId, contactInformation); db.SaveChanges(); } }
private ActionResult Create(DiaryRecord diaryRecord) { if (ModelState.IsValid) { db.DiaryRecords.Add(diaryRecord); db.SaveChanges(); return(RedirectToAction("Index")); } return(View("Create", diaryRecord)); }
public ActionResult Create([Bind(Include = "FirstName,LastName,Patronymic,BirthDate,Company")] ContactRecord contactRecord) { if (ModelState.IsValid) { db.Contacts.Add(contactRecord); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(contactRecord)); }
public ActionResult Creat(Diary diary, string start_date, string end_date) { diary = TryParseDate(diary, start_date, end_date); if (ModelState.IsValid) { db.Diarys.Add(diary); db.SaveChanges(); return(RedirectToAction("Index", "Home")); } ViewBag.TypeEntries = diary.TypeEntries; return(View()); }
//<summary> // Saving the given title and text as a Note // and updating the data source of the binding source. //</summary> public void SaveNote(string title, string text) { Note note = new Note(title, text); if (context.Notes.Select(x => x.Title).Contains(title)) { throw new ArgumentException("You have already the same title!"); } context.Users.Single(x => x.ID == currentUser.ID).Notes.Add(note); context.SaveChanges(); currentUser.Notes.Add(note); Notes.DataSource = currentUser.Notes; }
public ServiceResponse Delete(int id) { using (DiaryContext db = new DiaryContext()) { if (!db.Users.Any(x => x.Id == id)) { return(new ServiceResponse(HttpStatusCode.NotFound, "There is not existing user with given id!")); } var userToRemove = db.Users.Include(x => x.Diaries).Include(x => x.UserDetails).FirstOrDefault(x => x.Id == id); DiaryService diaryService = new DiaryService(); foreach (var diary in userToRemove.Diaries) { diaryService.Delete(diary.Id); } if (userToRemove.UserDetails != null) { db.UserDetails.Remove(userToRemove.UserDetails); } db.SaveChanges(); } using (DiaryContext db = new DiaryContext()) { var userToRemove = db.Users.Include(x => x.Diaries).Include(x => x.UserDetails).FirstOrDefault(x => x.Id == id); var userManager = new UserManager <User, int>(new UserStore <User, CustomRole, int, CustomUserLogin, CustomUserRole, CustomUserClaim>(db)); userManager.Delete(userToRemove); db.SaveChanges(); } return(new ServiceResponse(HttpStatusCode.OK, "User deleted!")); }
public ServiceResponse <AvatarResponse> AddAvatar(AddAvatarRequest request) { Avatar avatar; using (DiaryContext db = new DiaryContext()) { var userDetails = db.UserDetails.FirstOrDefault(x => x.Id == request.UserDetailsId); if (userDetails == null) { return(new ServiceResponse <AvatarResponse>(null, HttpStatusCode.NotFound, "Unable to find the user details!")); } avatar = db.Avatars.FirstOrDefault(x => x.Id == userDetails.Id); if (avatar != null) { avatar.Image = Convert.FromBase64String(request.Image); } else { avatar = new Avatar() { Id = userDetails.Id, Image = Convert.FromBase64String(request.Image), UserDetails = userDetails }; db.Avatars.Add(avatar); } db.SaveChanges(); } return(new ServiceResponse <AvatarResponse>(new AvatarResponse(avatar), HttpStatusCode.OK, "Avatar created successfully")); }
public ServiceResponse <UserDetailsResponse> UpdateDetails(UpdateUserDetailsRequest userDetailsRequest) { using (DiaryContext db = new DiaryContext()) { UserDetails userDetailsToUpdate = db.UserDetails.FirstOrDefault(x => x.Id == userDetailsRequest.UserId); if (userDetailsToUpdate == null) { return(new ServiceResponse <UserDetailsResponse>(null, HttpStatusCode.NotFound, "There are not existing user details with given id!")); } userDetailsToUpdate = db.UserDetails.FirstOrDefault(x => x.Id == userDetailsRequest.UserId); if (userDetailsRequest.Age > 0) { userDetailsToUpdate.Age = userDetailsRequest.Age; } if (userDetailsRequest.Height > 0) { userDetailsToUpdate.Height = userDetailsRequest.Height; } if (userDetailsRequest.Weight > 0) { userDetailsToUpdate.Weight = userDetailsRequest.Weight; } float[] results = CalculateBMIandBMR(userDetailsToUpdate.Weight, userDetailsToUpdate.Height, userDetailsToUpdate.Age); userDetailsToUpdate.BMI = results[0]; userDetailsToUpdate.BMR = results[1]; db.SaveChanges(); return(new ServiceResponse <UserDetailsResponse>(new UserDetailsResponse(userDetailsToUpdate), HttpStatusCode.OK, "UserDetails added succesfully!")); } }
public ServiceResponse <UserDetailsResponse> AddDetails(AddUserDetailsRequest userDetailsRequest) { using (DiaryContext db = new DiaryContext()) { User userVerification = db.Users.FirstOrDefault(x => x.Id == userDetailsRequest.UserId); if (userVerification == null || userVerification.UserDetails != null) { return(new ServiceResponse <UserDetailsResponse>(null, HttpStatusCode.BadRequest, "User does not exist or it already has a details")); } var userDetails = new UserDetails { Id = userDetailsRequest.UserId, Age = userDetailsRequest.Age, Height = userDetailsRequest.Height, Weight = userDetailsRequest.Weight, User = db.Users.FirstOrDefault(x => x.Id == userDetailsRequest.UserId) }; var BMIandBMR = CalculateBMIandBMR(userDetails.Weight, userDetails.Height, userDetails.Height); userDetails.BMI = BMIandBMR[0]; userDetails.BMR = BMIandBMR[1]; var _user = db.UserDetails.Add(userDetails); db.SaveChanges(); return(new ServiceResponse <UserDetailsResponse>(new UserDetailsResponse(_user), HttpStatusCode.OK, "UserDetails added succesfully!")); } }
public ServiceResponse <UserResponse> Update(UpdateUserRequest updateUserRequest) { User userToUpdate; using (DiaryContext db = new DiaryContext()) { if (!db.Users.Any(x => x.Id == updateUserRequest.Id)) { return(new ServiceResponse <UserResponse>(null, HttpStatusCode.NotFound, "There is not existing user with given id!")); } userToUpdate = db.Users.FirstOrDefault(x => x.Id == updateUserRequest.Id); if (!string.IsNullOrEmpty(updateUserRequest.Name)) { userToUpdate.Name = updateUserRequest.Name; } if (!string.IsNullOrEmpty(updateUserRequest.Surname)) { userToUpdate.Surname = updateUserRequest.Surname; } if (!string.IsNullOrEmpty(updateUserRequest.City)) { userToUpdate.City = updateUserRequest.City; } db.SaveChanges(); return(new ServiceResponse <UserResponse>(new UserResponse(userToUpdate), HttpStatusCode.OK, "User was updated successfully")); } }
public ServiceResponse Delete(int id) { using (DiaryContext db = new DiaryContext()) { if (!db.Diaries.Any(x => x.Id == id)) { return(new ServiceResponse(HttpStatusCode.NotFound, "There is not existing user with given id!")); } var diaryToRemove = db.Diaries.Include(x => x.Days).Include(x => x.User).FirstOrDefault(x => x.Id == id); DayService dayService = new DayService(); foreach (var day in diaryToRemove.Days) { dayService.Delete(day.Id); } db.SaveChanges(); } using (DiaryContext db = new DiaryContext()) { var diaryToRemove2 = db.Diaries.Include(x => x.Days).Include(x => x.User).FirstOrDefault(x => x.Id == id); db.Diaries.Remove(diaryToRemove2); db.SaveChanges(); } return(new ServiceResponse(HttpStatusCode.OK, "User deleted!")); }
public ServiceResponse Delete(int id) { using (DiaryContext db = new DiaryContext()) { if (!db.Days.Any(x => x.Id == id)) { return(new ServiceResponse(HttpStatusCode.NotFound, "There is not existing day with given id!")); } var dayToRemove = db.Days.Include("Diary").Include("Dream").Include("TrainingUnits").FirstOrDefault(x => x.Id == id); TrainingService trainingService = new TrainingService(); foreach (var trainingUnit in dayToRemove.TrainingUnits) { trainingService.DeleteTrainingUnit(trainingUnit.Id); } if (dayToRemove.Dream != null) { db.Dreams.Remove(dayToRemove.Dream); } db.SaveChanges(); } using (DiaryContext db = new DiaryContext()) { var dayToRemove2 = db.Days.Include("Diary").Include("Dream").Include("TrainingUnits").FirstOrDefault(x => x.Id == id); db.Days.Remove(dayToRemove2); db.SaveChanges(); } return(new ServiceResponse(HttpStatusCode.OK, "Day deleted!")); }
//<summary> // Checking the information for registering and adding the User into the DB. //</summary> public bool Registrate(string username, string password, string confirmPassword) { if (password != confirmPassword) { throw new ArgumentException("Passwords do not match"); } if (context.Users.Select(x => x.Username).Contains(username)) { throw new ArgumentException("User is already registrated"); } else if (username.Count() < 4) { throw new ArgumentException("Username must be at least 4 letters"); } else if (password.Count() < 4) { throw new ArgumentException("Password must be at least 4 letters"); } else { context.Users.Add(new User(username, password)); context.SaveChanges(); } return(true); }
public ServiceResponse <ExerciseTrainingResponse> Add(AddExerciseTrainingRequest addExerciseTrainingRequest) { using (DiaryContext db = new DiaryContext()) { var trainingUnit = db.TrainingUnits.FirstOrDefault(x => x.Id == addExerciseTrainingRequest.TrainingUnitId); if (trainingUnit == null) { return(new ServiceResponse <ExerciseTrainingResponse>(null, HttpStatusCode.NotFound, "Unable to find the training unit!")); } var exercise = db.Exercises.FirstOrDefault(x => x.Id == addExerciseTrainingRequest.ExerciseId); if (exercise == null) { return(new ServiceResponse <ExerciseTrainingResponse>(null, HttpStatusCode.NotFound, "Unable to find the exercise!")); } var exerciseDetails = db.ExercisesDetails.FirstOrDefault(x => x.Id == addExerciseTrainingRequest.ExerciseDetailsId); if (exerciseDetails == null) { return(new ServiceResponse <ExerciseTrainingResponse>(null, HttpStatusCode.NotFound, "Unable to find the exercise details!")); } var exerciseTraining = new ExerciseTraining { TrainingUnit = trainingUnit, Exercise = exercise, ExerciseDetails = exerciseDetails }; ExerciseTraining _ExerciseTraining = db.ExerciseTrainings.Add(exerciseTraining); db.SaveChanges(); return(new ServiceResponse <ExerciseTrainingResponse>(new ExerciseTrainingResponse(_ExerciseTraining), HttpStatusCode.OK, "ExerciseTraining added succesfully!")); } }
private static void SetUpDevelopmentUser() { applicationUser = new ApplicationUser(); using (var context = new DiaryContext()) { context.Users.Add(applicationUser); context.SaveChanges(); } }
private int SaveEntryReturnId(EntryModel entry) { using (var context = new DiaryContext()) { context.Entries.Add(entry); context.SaveChanges(); } return(entry.Id); }
//public ServiceResponse<IEnumerable<DiaryResponse>> Read() //{ // List<Diary> diaries = new List<Diary>(); // using (DiaryContext db = new DiaryContext()) // { // diaries = db.Diaries.Include(x => x.Days).Include(x => x.User).ToList(); // } // List<DiaryResponse> diaryResponses = new List<DiaryResponse>(); // foreach (var item in diaries) // { // diaryResponses.Add(new DiaryResponse(item)); // } // return new ServiceResponse<IEnumerable<DiaryResponse>>(diaryResponses, HttpStatusCode.OK, "Table downloaded!"); //} //public ServiceResponse<DiaryResponse> ReadById(int id) //{ // DiaryResponse diaryResponse = GetDiary(id); // if(diaryResponse == null) // { // return new ServiceResponse<DiaryResponse>(null, HttpStatusCode.NotFound, "There is not existing diary with given id!"); // } // return new ServiceResponse<DiaryResponse>(diaryResponse, HttpStatusCode.OK, "Diary downloaded!"); //} public ServiceResponse <DiaryResponse> Update(UpdateDiaryRequest updateDiaryRequest) { Diary diaryToUpdate; using (DiaryContext db = new DiaryContext()) { if (!db.Diaries.Any(x => x.Id == updateDiaryRequest.Id)) { return(new ServiceResponse <DiaryResponse>(null, HttpStatusCode.NotFound, "There is not existing diary with given id!")); } diaryToUpdate = db.Diaries.FirstOrDefault(x => x.Id == updateDiaryRequest.Id); if (!string.IsNullOrEmpty(updateDiaryRequest.Conclusions)) { diaryToUpdate.Conclusions = updateDiaryRequest.Conclusions; } if (updateDiaryRequest.EndDate.Date.Year > 2019) { diaryToUpdate.EndDate = updateDiaryRequest.EndDate; } if (updateDiaryRequest.StartDate.Date.Year > 2019) { diaryToUpdate.StartDate = updateDiaryRequest.StartDate; } if (updateDiaryRequest.BenchPressStart != 0) { diaryToUpdate.BenchPressStart = updateDiaryRequest.BenchPressStart; } if (updateDiaryRequest.SquatStart != 0) { diaryToUpdate.SquatStart = updateDiaryRequest.SquatStart; } if (updateDiaryRequest.DeadliftStart != 0) { diaryToUpdate.DeadliftStart = updateDiaryRequest.DeadliftStart; } if (updateDiaryRequest.BenchPressEnd != 0) { diaryToUpdate.BenchPressEnd = updateDiaryRequest.BenchPressEnd; } if (updateDiaryRequest.SquatEnd != 0) { diaryToUpdate.SquatEnd = updateDiaryRequest.SquatEnd; } if (updateDiaryRequest.DeadliftEnd != 0) { diaryToUpdate.DeadliftEnd = updateDiaryRequest.DeadliftEnd; } if (updateDiaryRequest.Progress != 0) { diaryToUpdate.Progress = updateDiaryRequest.Progress; } db.SaveChanges(); return(new ServiceResponse <DiaryResponse>(new DiaryResponse(diaryToUpdate), HttpStatusCode.OK, "User was updated successfully")); } }
public ServiceResponse <ExerciseEquipmentResponse> Add(AddExerciseEquipmentRequest exerciseRequest) { using (DiaryContext db = new DiaryContext()) { var exerciseEquipment = new ExerciseEquipment { Name = exerciseRequest.Name }; ExerciseEquipment _exercise = db.ExerciseEquipment.Add(exerciseEquipment); db.SaveChanges(); return(new ServiceResponse <ExerciseEquipmentResponse>(new ExerciseEquipmentResponse(_exercise), HttpStatusCode.OK, "Exercise added succesfully!")); } }
public ServiceResponse DeleteAvatar(int id) { using (DiaryContext db = new DiaryContext()) { if (!db.Avatars.Any(x => x.Id == id)) { return(new ServiceResponse(HttpStatusCode.NotFound, "There is no existing avatar with given id!")); } Avatar avatarToRemove = db.Avatars.FirstOrDefault(x => x.Id == id); db.Avatars.Remove(avatarToRemove); db.SaveChanges(); } return(new ServiceResponse(HttpStatusCode.OK, "Avatar deleted!")); }
public ServiceResponse SaveBrandingSettings(SaveBrandingRequest request) { using (DiaryContext db = new DiaryContext()) { var userDetails = db.UserDetails.FirstOrDefault(x => x.Id == request.Id); if (userDetails == null) { return(new ServiceResponse(HttpStatusCode.BadRequest, "There is no existing user details with given id!")); } userDetails.BrandingSettings = request.BrandingSettings; db.SaveChanges(); } return(new ServiceResponse(HttpStatusCode.OK, "Branding saved!")); }
public ServiceResponse DeleteExerciseTraining(int id) { using (DiaryContext db = new DiaryContext()) { if (!db.ExerciseTrainings.Any(x => x.Id == id)) { return(new ServiceResponse(HttpStatusCode.NotFound, "There is not existing exercise training with given id!")); } var exerciseToRemove = db.ExerciseTrainings.Include("Exercise").Include("ExerciseDetails").Include("TrainingUnit").FirstOrDefault(x => x.Id == id); db.ExerciseTrainings.Remove(exerciseToRemove); db.SaveChanges(); } return(new ServiceResponse(HttpStatusCode.OK, "Exercise Training deleted!")); }
public ServiceResponse <ExerciseDetailsResponse> Add(AddExerciseDetailsRequest exerciseRequest) { using (DiaryContext db = new DiaryContext()) { var exerciseDetails = new ExerciseDetails { Eccentric = exerciseRequest.Eccentric, EccentricPause = exerciseRequest.EccentricPause, Concetric = exerciseRequest.Concetric, ConcetricPause = exerciseRequest.ConcetricPause, Repeats = exerciseRequest.Repeats, Series = exerciseRequest.Series }; ExerciseDetails _exercise = db.ExercisesDetails.Add(exerciseDetails); db.SaveChanges(); return(new ServiceResponse <ExerciseDetailsResponse>(new ExerciseDetailsResponse(_exercise), HttpStatusCode.OK, "Exercise added succesfully!")); } }
public ServiceResponse <TrainingUnitResponse> Add(AddTrainingUnitRequest trainingUnitRequest) { using (DiaryContext db = new DiaryContext()) { var day = db.Days.FirstOrDefault(x => x.Id == trainingUnitRequest.DayId); if (day == null) { return(new ServiceResponse <TrainingUnitResponse>(null, HttpStatusCode.NotFound, "Unable to find the day!")); } var trainingUnit = new TrainingUnit { Day = day }; TrainingUnit _trainingUnit = db.TrainingUnits.Add(trainingUnit); db.SaveChanges(); return(new ServiceResponse <TrainingUnitResponse>(new TrainingUnitResponse(_trainingUnit), HttpStatusCode.OK, "Training unit added succesfully!")); } }
public ServiceResponse DeleteExercise(int id) { using (DiaryContext db = new DiaryContext()) { if (!db.Exercises.Any(x => x.Id == id)) { return(new ServiceResponse(HttpStatusCode.NotFound, "There is not existing exercise with given id!")); } var exerciseToRemove = db.Exercises.Include("ExerciseEquipment").Include("ExerciseTrainings").FirstOrDefault(x => x.Id == id); TrainingService trainingService = new TrainingService(); foreach (var exerciseTraining in exerciseToRemove.ExerciseTrainings) { trainingService.DeleteExerciseTraining(exerciseTraining.Id); } db.Exercises.Remove(exerciseToRemove); db.SaveChanges(); } return(new ServiceResponse(HttpStatusCode.OK, "Exercise deleted!")); }
public ServiceResponse <DayResponse> Add(AddDayRequest dayRequest) { using (DiaryContext db = new DiaryContext()) { var diary = db.Diaries.FirstOrDefault(x => x.Id == dayRequest.DiaryId); if (diary == null) { return(new ServiceResponse <DayResponse>(null, HttpStatusCode.NotFound, "Unable to find the diary!")); } var day = new Day { Date = dayRequest.Date, Diary = diary, }; Day _day = db.Days.Add(day); db.SaveChanges(); return(new ServiceResponse <DayResponse>(new DayResponse(_day, typeof(DayResponse)), HttpStatusCode.OK, "Day added succesfully!")); } }
//public ServiceResponse<IEnumerable<DayResponse>> Read() //{ // List<Day> days = new List<Day>(); // using (DiaryContext db = new DiaryContext()) // { // days = db.Days.Include("Diary").Include("Dream").Include("TrainingUnits").ToList(); // } // List<DayResponse> dayResponses = new List<DayResponse>(); // foreach (var item in days) // { // dayResponses.Add(new DayResponse(item,typeof(DayResponse))); // } // return new ServiceResponse<IEnumerable<DayResponse>>(dayResponses, HttpStatusCode.OK, "Table downloaded!"); //} //public ServiceResponse<DayResponse> ReadById(int id) //{ // DayResponse dayResponse = GetDay(id); // if (dayResponse == null) // { // return new ServiceResponse<DayResponse>(null, HttpStatusCode.NotFound, "There is not existing day with given id!"); // } // return new ServiceResponse<DayResponse>(dayResponse, HttpStatusCode.OK, "Diary downloaded!"); //} //public ServiceResponse<DayResponse> Update(UpdateDayRequest updateDayRequest) //{ // Day dayToUpdate; // using (DiaryContext db = new DiaryContext()) // { // if (!db.Days.Any(x => x.Id == updateDayRequest.Id)) // { // return new ServiceResponse<DayResponse>(null, HttpStatusCode.NotFound, "There is not existing day with given id!"); // } // dayToUpdate = db.Days.FirstOrDefault(x => x.Id == updateDayRequest.Id); // if (updateDayRequest.Date.Year > 2019) // { // dayToUpdate.Date = updateDayRequest.Date; // } // db.SaveChanges(); // return new ServiceResponse<DayResponse>(new DayResponse(dayToUpdate,typeof(DayResponse)), HttpStatusCode.OK, "User was updated successfully"); // } //} public ServiceResponse <DreamResponse> AddDream(AddDreamRequest dreamRequest) { using (DiaryContext db = new DiaryContext()) { var dreamVerification = db.Days.FirstOrDefault(x => x.Id == dreamRequest.Id); if (dreamVerification == null || dreamVerification.Dream != null) { return(new ServiceResponse <DreamResponse>(null, HttpStatusCode.BadRequest, "Day does not exist or it already has a dream")); } var dream = new Dream { Id = dreamRequest.Id, Length = dreamRequest.Length, Quality = dreamRequest.Quality, Day = db.Days.FirstOrDefault(x => x.Id == dreamRequest.Id) }; var _dream = db.Dreams.Add(dream); db.SaveChanges(); return(new ServiceResponse <DreamResponse>(new DreamResponse(_dream), HttpStatusCode.OK, "Dream added succesfully!")); } }
public ServiceResponse <ExerciseResponse> Add(AddExerciseRequest exerciseRequest) { using (DiaryContext db = new DiaryContext()) { var exerciseEquipment = db.ExerciseEquipment.FirstOrDefault(x => x.Id == exerciseRequest.ExerciseEquipmentId); if (exerciseEquipment == null) { return(new ServiceResponse <ExerciseResponse>(null, HttpStatusCode.NotFound, "Unable to find the equipment!")); } var exercise = new Exercise { Name = exerciseRequest.Name, Description = exerciseRequest.Description, ExerciseEquipment = exerciseEquipment, BodyPart = exerciseRequest.BodyPart }; Exercise _exercise = db.Exercises.Add(exercise); db.SaveChanges(); return(new ServiceResponse <ExerciseResponse>(new ExerciseResponse(_exercise), HttpStatusCode.OK, "Exercise added succesfully!")); } }
public ServiceResponse DeleteTrainingUnit(int id) { using (DiaryContext db = new DiaryContext()) { if (!db.TrainingUnits.Any(x => x.Id == id)) { return(new ServiceResponse(HttpStatusCode.NotFound, "There is not existing training unit with given id!")); } var trainingToRemove = db.TrainingUnits.Include("Day").Include("ExerciseTrainings").FirstOrDefault(x => x.Id == id); foreach (var exerciseTraining in trainingToRemove.ExerciseTrainings) { DeleteExerciseTraining(exerciseTraining.Id); } db.SaveChanges(); } using (DiaryContext db = new DiaryContext()) { var trainingToRemove2 = db.TrainingUnits.Include("Day").Include("ExerciseTrainings").FirstOrDefault(x => x.Id == id); db.TrainingUnits.Remove(trainingToRemove2); db.SaveChanges(); } return(new ServiceResponse(HttpStatusCode.OK, "Training unit deleted!")); }
public ServiceResponse <DiaryResponse> Add(AddDiaryRequest diaryRequest) { using (DiaryContext db = new DiaryContext()) { var user = db.Users.FirstOrDefault(x => x.Id == diaryRequest.UserId); if (user == null) { return(new ServiceResponse <DiaryResponse>(null, HttpStatusCode.NotFound, "Unable to find the user!")); } var diary = new Diary { User = user, StartDate = diaryRequest.StartDate, EndDate = diaryRequest.StartDate, BenchPressStart = diaryRequest.BenchPressStart, SquatStart = diaryRequest.SquatStart, DeadliftStart = diaryRequest.DeadliftStart }; Diary _diary = db.Diaries.Add(diary); db.SaveChanges(); return(new ServiceResponse <DiaryResponse>(new DiaryResponse(_diary), HttpStatusCode.OK, "Diary added succesfully!")); } }
public static void InsertData(DiaryContext ctx) { var brazil = new Country { Id = Guid.NewGuid(), Name = "Brazil", TwoLetterIso = "BR" }; var austria = new Country { Id = Guid.NewGuid(), Name = "Austria", TwoLetterIso = "AT" }; var indonesia = new Country { Id = Guid.NewGuid(), Name = "Indonesia", TwoLetterIso = "ID" }; var project1 = new Project { Id = Guid.NewGuid(), ProjectName = "Fortaleza", Longitude = -3.7844296m, Latitude = -38.6557987m, CountryId = brazil.Id }; var project2 = new Project { Id = Guid.NewGuid(), ProjectName = "Gerlos", Longitude = 47.2206366m, Latitude = 12.0264733m, CountryId = austria.Id }; var project3 = new Project { Id = Guid.NewGuid(), ProjectName = "Walai", Longitude = -3.7627406m, Latitude = 121.9409223m, CountryId = indonesia.Id }; var projects = new[] { project1, project2, project3 }; ctx.Countries.AddRange(brazil, austria, indonesia); ctx.Projects.AddRange(projects); foreach (var project in projects) { for (int i = 0; i < 10; i++) { var employee = new Employee { Id = Guid.NewGuid(), Created = DateTime.Now, FirstName = "Employee", LastName = $"Name {i}", ProjectId = project.Id }; var area = new Area { Id = Guid.NewGuid(), AreaName = _areas[i], ProjectId = project.Id }; ctx.Areas.Add(area); ctx.Employees.Add(employee); } } var issueTypes = new[] { new IssueType { Id = new Guid(), Title = "structural damage" }, new IssueType { Id = new Guid(), Title = "electrical issues" }, new IssueType { Id = new Guid(), Title = "material damage" }, new IssueType { Id = new Guid(), Title = "broken tool" }, new IssueType { Id = new Guid(), Title = "vehicle issue" }, }; ctx.IssueTypes.AddRange(issueTypes); for (int i = 0; i < 10000; i++) { var issue = new Issue { Id = Guid.NewGuid(), Title = $"Issue Nr {i}", IssueTypeId = issueTypes[i % issueTypes.Length].Id, AreaId = project1.Areas.ElementAt(i % 10).Id, CreationTime = DateTime.Now }; if (i % 13 < 10) { issue.AssignedToId = project1.Employees.ElementAt(i % 13).Id; } ctx.Issues.Add(issue); } ctx.SaveChanges(); }