public Inspection Create(Inspection inspection) { inspection.Id = Guid.NewGuid(); _context.Add(inspection); _context.SaveChanges(); return(inspection); }
public void CreateCourse(Course course) { _trainingContext.Add(course); //_trainingContext.Database.ExecuteSqlRaw("SET IDENTITY_INSERT Teachers ON"); _trainingContext.SaveChanges(); //_trainingContext.Database.ExecuteSqlRaw("SET IDENTITY_INSERT Teachers OFF"); }
public Operation Create(Operation operation) { operation.Id = Guid.NewGuid(); _context.Add(operation); _context.SaveChanges(); return(operation); }
public Contract Create(Contract contract) { contract.Id = Guid.NewGuid(); _context.Add(contract); _context.SaveChanges(); return(contract); }
public ActionResult Create([Bind(Include = "ID,OpponentName,Position,WinLoss,DateOfEvent,StudentID")] SubmissionLog submissionLog) { if (ModelState.IsValid) { db.SubmissionLogs.Add(submissionLog); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(submissionLog)); }
public ActionResult Create([Bind(Include = "Id,RankID,VideoTitle,VideoSrc,IsVideoComplete,VideoRank")] Video video) { if (ModelState.IsValid) { db.Videos.Add(video); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(video)); }
public ActionResult Create([Bind(Include = "ID,RankType")] Rank rank) { if (ModelState.IsValid) { db.Ranks.Add(rank); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(rank)); }
public ActionResult Create([Bind(Include = "Id,FirstName,LastName,Email,FighterRank,SparingCount,RankID")] Student student) { if (ModelState.IsValid) { db.Students.Add(student); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(student)); }
public void Add(Training item) { try { _context.Trainings.Add(item); _context.SaveChanges(); } catch (Exception) { throw; } }
public int Insert(EmployeeDTO objDTO) { try { employeeDTOs.Add(objDTO); return(context.SaveChanges()); } catch (Exception ex) { logger.LogError($"Не удалось создать Employee на уровне EmployeeDBRepository: {ex}"); throw new Exception("Не удалось добавить сотрудника в БД через EF"); } }
public int Insert(TaskDTO objDTO) { try { taskDTOs.Add(objDTO); return(context.SaveChanges()); } catch (Exception ex) { logger.LogError($"Не удалось создать Task на уровне TaskDBRepository: {ex}"); throw new Exception("Не удалось добавить задачу в БД через EF"); } }
public void Add(Training item) { try { _context.Training.Add(item); _context.SaveChanges(); //throw new NotImplementedException(); } catch (Exception) { throw; } }
public int Insert(ProjectDTO objDTO) { try { projectDTOs.Add(objDTO); context.SaveChanges(); return(projectDTOs.LastOrDefault().Id); } catch (Exception ex) { logger.LogError($"Не удалось создать Project на уровне ProjectDBRepository: {ex}"); throw new Exception("Не удалось добавить проект в БД через EF"); } }
public Models.ApplicationUser.ApplicationUser Insert(ApplicationUserInsert insert) { var entity = _mapper.Map <eTraining.Database.Entities.ApplicationUser>(insert); if (insert.Password != insert.PasswordConfirm) { throw new Exception("Passwordi se ne slazu."); } entity.PasswordSalt = GenerateSalt(); entity.PasswordHash = GenerateHash(entity.PasswordSalt, insert.Password); _ctx.ApplicationUser.Add(entity); _ctx.SaveChanges(); return(_mapper.Map <Models.ApplicationUser.ApplicationUser>(entity)); }
public IActionResult Index() { var context = new TrainingContext(); var student = new Student() { Name = "Jalaluddin", BirthDate = DateTime.Now, StudentCourses = new List <StudentCourse>() }; var course = new Course() { Name = "Laravel", Price = 20000, Topics = new List <CourseTopic>() }; course.Topics.Add(new CourseTopic() { Name = "Intro", Description = "Getting started" }); student.StudentCourses.Add(new StudentCourse() { Course = course }); context.Students.Add(student); context.SaveChanges(); return(View()); }
public JsonResult SaveTraining(string content) { string userId = this.User.Identity.GetUserId(); if (userId == null) { return(Json("Can't save. User is not logined.")); } int trainingId = (from t in db.Trainings where t.UserId == userId select t.id).FirstOrDefault(); if (trainingId != 0) { db.Trainings.Find(trainingId).Content = content; } else { Training training = new Training { Content = content, UserId = userId }; db.Trainings.Add(training); } db.SaveChanges(); return(Json("Saved")); }
public void AddTrainingDetails(TrainingModel model) { //Auto mapper to map data between the two models. var trainingDetails = Mapper.Map <TrainingModel, TrainingDetails>(model); //Context to save data. _trainingContext.TrainingDetails.Add(trainingDetails); _trainingContext.SaveChanges(); }
public async void Get_returns_list_of_trainings() { //Arrange var sampleTraining1 = new Training() { Id = 1, StartDate = new DateTime(2019, 09, 20), EndDate = new DateTime(2019, 09, 21), TrainingName = "Asp.net Training" }; var sampleTraining2 = new Training() { Id = 2, StartDate = new DateTime(2019, 09, 21), EndDate = new DateTime(2019, 09, 22), TrainingName = "Web Api training" }; context.AddRange(sampleTraining1, sampleTraining2); context.SaveChanges(); //Act var taskResult = await myController.GetTrainings(); //Assert Assert.IsType <ActionResult <IEnumerable <Training> > >(taskResult); }
public bool Delete(int id) { try { var trainingsFound = trainingContext.Trainings.Find(id); if (trainingsFound != null) { trainingContext.Trainings.Remove(trainingsFound); trainingContext.SaveChanges(); if (trainingContext.Trainings.Find(id) == null) { return(true); } } return(false); } catch (Exception) { throw; } }
static void CreateData(TrainingContext db) { Teacher t1 = new Teacher { Name = "Miss Anderson" }; Teacher t2 = new Teacher { Name = "Miss Bingham" }; Classroom r1 = new Classroom { Number = "R101" }; Classroom r2 = new Classroom { Number = "R202" }; Course c1 = new Course { Title = "Introduction to EF Core", Author = t1, Editor = t2 }; Course c2 = new Course { Title = "Basic Car Maintenance", Author = t2, Editor = t1 }; Student s1 = new Student { Name = "Jenny Jones", Classroom = r1 }; Student s2 = new Student { Name = "Kenny Kent", Classroom = r1 }; Student s3 = new Student { Name = "Lucy Locket", Classroom = r1 }; Student s4 = new Student { Name = "Micky Most", Classroom = r2 }; Student s5 = new Student { Name = "Nelly Norton", Classroom = r2 }; Student s6 = new Student { Name = "Ozzy Osborne", Classroom = r2 }; c1.Students = new Student[] { s1, s2, s3, s4 }; c2.Students = new Student[] { s3, s4, s5, s6 }; db.Add(c1); db.Add(c2); db.SaveChanges(); }
public ActionResult Registration([Bind(Include = "Id,Name,Surname,Email,University,Course")] RegistrationStudent student) { student.TrainingId = (int)TempData["Id"]; if (ModelState.IsValid) { db.Students.Add(student); db.SaveChanges(); TempData["Massage"] = "Регистрация прошла успешно."; return(RedirectToAction("ShowMassage")); } TempData["Id"] = student.Id; return(View(student)); }
public JsonResult AddUser(string Email_ID, string Password, string Name, string City, string Gender, long Mobile_Number) { string msg = ""; if (db.UserInfo.Any(a => a.EmailId == Email_ID)) { msg = "UserExists"; //user already exist } else { UserInfo user = new UserInfo() { EmailId = Email_ID, Password = Password, Name = Name, City = City, Gender = Gender, MobileNumber = Mobile_Number }; db.UserInfo.Add(user); db.SaveChanges(); msg = "Registered"; //you are succesfully registered } return(Json(msg)); }
private void Create_Click(object sender, RoutedEventArgs e) { int id_train; if (Intensity_num != 0 && type_train != 0 && list_ex_id.Count != 0 && this.new_name.Text != "") { using (TrainingContext db = new TrainingContext()) { Training new_train = new Training { Name_training = this.new_name.Text, Description = this.new_Disc.Text, Groupe = type_train, ID_training = 1, ID_type = user.ID_user, Img = "/Training/user_training.png", Intensity = Intensity_num, Time = time_ex_all }; db.Trainings.Add(new_train); db.SaveChanges(); } using (TrainingContext db = new TrainingContext()) { db.Trainings.Load(); var list = db.Trainings.Local.ToBindingList(); id_train = list.Count; } using (ConnectionContext db = new ConnectionContext()) { foreach (var item in list_ex_id) { var new_con = new Connection { ID_note = 1, ID_ex = item, ID_training = id_train }; db.Connections.Add(new_con); } db.SaveChanges(); } var win_user_train = new MainTrainWin(user); win_user_train.Show(); win_c.Close(); } else { var win_er = new ERRORWin(); win_er.ChooseError("ERRORDataEntry"); win_er.Show(); } }
static void Main(string[] args) { var ctx = new TrainingContext(); Batch batch = new Batch() { BatchID = 1, BatchName = "Jan15-CS", BatchOwner = "Sharan" }; Trainee trainee = new Trainee() { TraineeID = 101, TraineeName = "John", EmailID = "*****@*****.**", DateOfJoining = Convert.ToDateTime("01/01/2015"), Batch = batch }; ctx.Trainees.Add(trainee); ctx.SaveChanges(); Console.WriteLine("Done"); Console.ReadLine(); }
public BookingResult CreateTrainingBooking(string name, DateTime startDate, DateTime endDate) { var minDate = new DateTime(1970, 01, 01); if (string.IsNullOrEmpty(name) || startDate <= minDate || endDate <= minDate) { return(new BookingResult() { Message = "All fields are mandatory, please fill in all fields before continuing." }); } if (startDate > endDate) { return(new BookingResult() { Message = "The training start date must be earlier than the end date, please try again." }); } _repository.Add(new Training() { TrainingName = name, StartDate = startDate, EndDate = endDate }); _context.SaveChanges(); var trainingDuration = (endDate - startDate).Days + 1; return(new BookingResult() { Message = $"The training has been booked successfully. Training duration: {trainingDuration} days.", TrainingDurationInDays = trainingDuration, IsSuccess = true }); }
public void Add(Session entity) { TrainingContext.Sessions.Add(entity); TrainingContext.SaveChanges(); }
public void AddTrainings(Training item) { _context.trainings.Add(item); _context.SaveChanges(); }
public int Save() { var insertedCount = _dbContext.SaveChanges(); return(insertedCount); }
public void Add(Trainings item) { _context.Training.Add(item); _context.SaveChanges(); }
public void Add(Event entity) { TrainingContext.Events.Add(entity); TrainingContext.SaveChanges(); }