public async Task MarkAsServed(int orderItemId) { var orderItem = this.GetOrderItemById(orderItemId); orderItem.Status = GlobalConstants.Served; orderItemRepository.Update(orderItem); await orderItemRepository.SaveChangesAsync(); }
public async Task EditAsync(ClassModifyInputModel modifiedModel) { var schoolClass = _classesRepository.All().FirstOrDefault(c => c.Id == modifiedModel.Id); if (schoolClass != null) { var inputModel = modifiedModel.Class; var teacherId = int.Parse(inputModel.TeacherId); var isClassLetterNumberCombinationAlreadyOccupied = _classesRepository.All().Any(c => c.Letter == inputModel.Letter && c.YearCreated == inputModel.YearCreated && c.Year == inputModel.Year && c.TeacherId == teacherId); if (isClassLetterNumberCombinationAlreadyOccupied) { throw new ArgumentException($"Sorry, there is already existing class for year {inputModel.YearCreated} that's currently in {inputModel.Year} grade and with letter {inputModel.Letter}"); } schoolClass.Letter = inputModel.Letter; schoolClass.Year = inputModel.Year; schoolClass.YearCreated = inputModel.YearCreated; if (schoolClass.TeacherId != teacherId) { var teacher = _teachersRepository.All().FirstOrDefault(t => t.Id == teacherId); if (teacher != null) { if (teacher.Class != null) { throw new ArgumentException($"Sorry, teacher with id {teacherId} is already registered as head of another class"); } if (teacher.SchoolId != schoolClass.Teacher.SchoolId) { var school = teacher.School; school.Classes.Add(schoolClass); _schoolsRepository.Update(school); await _schoolsRepository.SaveChangesAsync(); } // MUST be below the if above schoolClass.Teacher = teacher; } } _classesRepository.Update(schoolClass); await _classesRepository.SaveChangesAsync(); } }
public async Task SetUserEmail(string uniqueId, string email) { if (!string.IsNullOrEmpty(uniqueId)) { var hasDeletedRecord = false; switch (uniqueId[0]) { case GlobalConstants.TeacherIdPrefix: var teacherRecord = _teachersRepository.All().FirstOrDefault(p => p.UniqueId == uniqueId); teacherRecord.Email = email; _teachersRepository.Update(teacherRecord); await _teachersRepository.SaveChangesAsync(); break; case GlobalConstants.StudentIdPrefix: var studentRecord = _studentsRepository.All().FirstOrDefault(p => p.UniqueId == uniqueId); studentRecord.Email = email; studentRecord.Username = email; _studentsRepository.Update(studentRecord); await _studentsRepository.SaveChangesAsync(); break; case GlobalConstants.ParentIdPrefix: var parentRecord = _parentsRepository.All().FirstOrDefault(p => p.UniqueId == uniqueId); parentRecord.Email = email; _parentsRepository.Update(parentRecord); await _parentsRepository.SaveChangesAsync(); break; } } }
public async Task EditAsync(SchoolModifyInputModel modifiedModel) { var school = _schoolsRepository.All().FirstOrDefault(s => s.Id == modifiedModel.Id); if (school != null) { var modifiedSchool = modifiedModel.School; school.Name = modifiedSchool.Name; school.Address = modifiedSchool.Address; school.Type = modifiedSchool.Type; school.Name = modifiedSchool.Name; if (modifiedSchool.SchoolImage != null) { var fileName = modifiedSchool.SchoolImage.Name; var uniqueFileName = Guid.NewGuid() + fileName; await _fileManagementService.SaveImageAsync("schools", uniqueFileName, modifiedSchool.SchoolImage); school.SchoolImageName = uniqueFileName; } _schoolsRepository.Update(school); await _schoolsRepository.SaveChangesAsync(); } }
public async Task Update(SubjectEditModel model) { Subject subject = repository.All().Where(x => x.Id == model.Id).FirstOrDefault(); subject.Name = model.Name; repository.Update(subject); }
public async Task EditAsync(SubjectModifyInputModel modifiedModel) { var subject = _subjectsRepository.All().FirstOrDefault(s => s.Id == modifiedModel.Id); if (subject != null) { var inputModel = modifiedModel.Subject; subject.Name = inputModel.Name; subject.YearGrade = inputModel.YearGrade; subject.SchoolYear = inputModel.SchoolYear; var teacherId = int.Parse(inputModel.TeacherId); if (subject.TeacherId != teacherId) { var teacher = _teachersRepository.All().FirstOrDefault(t => t.Id == teacherId); if (teacher != null) { subject.Teacher = teacher; } } _subjectsRepository.Update(subject); await _subjectsRepository.SaveChangesAsync(); } }
public async Task <IActionResult> Edit(int id, [Bind("Name,UserId,AccountId,IsDeleted,DeletedOn,CreatedOn, Id,ModifiedOn,Stage")] Deal deal) { if (id != deal.Id) { return(NotFound()); } if (ModelState.IsValid) { try { dealRepository.Update(deal);//context.Update(deal); await dealRepository.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DealExists(deal.Id)) { return(NotFound()); } else { throw; } } } ViewData["UserId"] = new SelectList(context.Users, "Id", "FirstName", deal.UserId); ViewData["AccountId"] = new SelectList(context.Accounts, "Id", "Id", deal.AccountId); return(this.RedirectToAction("GetAll")); }
public async Task <int> Create(string id, string userId) { var package = _packageRepository.All() .SingleOrDefault(p => p.Id.Equals(id) && p.RecipientId.Equals(userId)); if (package == null) { return(0); } var price = (decimal)package.Weight * 2.67M; var receipt = new Receipt { Fee = price, RecipientId = package.RecipientId, Recipient = package.Recipient, PackageId = package.Id, Package = package, }; var status = _statusRepository.All().SingleOrDefault(s => s.Name.Equals("Acquired")); package.Status = status; _packageRepository.Update(package); await _packageRepository.SaveChangesAsync(); await _receiptRepository.AddAsync(receipt); return(await _receiptRepository.SaveChangesAsync()); }
public async Task EditAsync(StudentModifyInputModel modifiedModel) { var student = _studentsRepository.All().FirstOrDefault(s => s.Id == modifiedModel.Id); if (student != null) { var inputModel = modifiedModel.Student; student.FirstName = inputModel.FirstName; student.LastName = inputModel.LastName; student.BirthDate = inputModel.BirthDate; student.PersonalIdentificationNumber = inputModel.PersonalIdentificationNumber; var schoolId = int.Parse(inputModel.SchoolId); var school = _schoolsRepository.All().FirstOrDefault(s => s.Id == schoolId); if (school != null) { student.School = school; var classId = int.Parse(inputModel.ClassId); if (school.Classes.Any(c => c.Id == classId)) { student.Class = school.Classes.FirstOrDefault(c => c.Id == classId); } } _studentsRepository.Update(student); await _studentsRepository.SaveChangesAsync(); } }
public async Task UpdateCategory(Category category) { if (categoryRepository.All().Any(x => x.Name == category.Name)) { throw new DbUpdateConcurrencyException(); } categoryRepository.Update(category); await categoryRepository.SaveChangesAsync(); }
public async Task <int> UpdateDatabase(Package package, string statusName) { var status = _statusRepository.All().SingleOrDefault(s => s.Name.Equals(statusName)); package.Status = status; _packageRepository.Update(package); return(await _packageRepository.SaveChangesAsync()); }
public async Task EditAsync(CommentModifyInputModel modifiedModel) { var comment = _commentsRepository.All().FirstOrDefault(c => c.Id == modifiedModel.Id); if (comment != null) { comment.Content = modifiedModel.Content; _commentsRepository.Update(comment); await _commentsRepository.SaveChangesAsync(); } }
public async Task EditAsync(SkillModifyInputModel modifiedModel) { var skill = _skillsRepository.All().FirstOrDefault(e => e.Id == modifiedModel.Id); if (skill != null) { skill.Type = modifiedModel.Type; skill.Name = modifiedModel.Name; _skillsRepository.Update(skill); await _skillsRepository.SaveChangesAsync(); } }
public async Task Update(ReviewInputModel input) { var review = reviewsRepository.AllAsNoTrackingWithDeleted().FirstOrDefault(x => x.Id == input.Id); if (review == null) { throw new InvalidOperationException("The review could not be found"); } review = AutoMapperConfig.MapperInstance.Map <Review>(input); reviewsRepository.Update(review); await reviewsRepository.SaveChangesAsync(); }
public async Task EditAsync(AbsenceModifyInputModel modifiedModel) { var absence = _absencesRepository.All().FirstOrDefault(a => a.Id == modifiedModel.Id); if (absence != null) { var inputModel = modifiedModel.Absence; absence.Period = inputModel.Period; absence.Type = inputModel.Type; _absencesRepository.Update(absence); await _absencesRepository.SaveChangesAsync(); } }
public void Update(SportCenter entity, string city, string neighbour) { var model = sportCentersDb.GetById(entity.Id); model.Name = entity.Name; model.PhoneNumber = entity.PhoneNumber; model.ExactAddress = entity.ExactAddress; model.Address.City = city; model.Address.Neighborhood = neighbour; model.Description = entity.Description; sportCentersDb.Update(model); sportCentersDb.SaveChanges(); }
public async Task EditAsync(GradeModifyInputModel modifiedModel) { var grade = _gradesRepository.All().FirstOrDefault(g => g.Id == modifiedModel.Id); if (grade != null) { var inputModel = modifiedModel.Grade; grade.Value = inputModel.Value; grade.Period = inputModel.Period; grade.Type = inputModel.Type; _gradesRepository.Update(grade); await _gradesRepository.SaveChangesAsync(); } }
public async Task EditAsync(ParentModifyInputModel modifiedModel) { var parent = _parentsRepository.All().FirstOrDefault(p => p.Id == modifiedModel.Id); if (parent != null) { var studentIds = modifiedModel.Parent.StudentIds.Select(int.Parse).ToList(); if (!studentIds.Any()) // Make sure parent has student children { throw new ArgumentException($"Sorry, it's mandatory for a parent user to have at least 1 student"); } if (HasDifferentStudentIds(parent, studentIds) && studentIds.Any()) { var students = _studentsRepository.All().Where(s => studentIds.Contains(s.Id)); // Remove all pairs that are no longer valid foreach (var studentParent in parent.StudentParents.Where(sp => !studentIds.Contains(sp.StudentId))) { _studentParentsMappingRepository.Delete(studentParent); } foreach (var studentId in studentIds.Where(sid => !parent.StudentParents.Select(sp => sp.StudentId).Contains(sid))) { var student = _studentsRepository.All().FirstOrDefault(s => s.Id == studentId); if (student != null) { var studentParentPair = new StudentParent { Student = student, Parent = parent }; await _studentParentsMappingRepository.AddAsync(studentParentPair); } } await _studentParentsMappingRepository.SaveChangesAsync(); } parent.FirstName = modifiedModel.Parent.FirstName; parent.LastName = modifiedModel.Parent.LastName; parent.PhoneNumber = modifiedModel.Parent.PhoneNumber; _parentsRepository.Update(parent); await _parentsRepository.SaveChangesAsync(); } }
public async Task Update(ReservationCreateInputModel model) { var reservation = new Reservation { Id = model.Id, NumberOfSeats = model.NumberOfSeats, Duration = model.Duration, StartTime = model.StartTime, PersonEmail = model.Email, PersonName = model.Name, PersonNumber = model.Number, }; reservationRepository.Update(reservation); await reservationRepository.SaveChangesAsync(); }
public bool UpdateById(int id, string name) { var entity = sportCategoriesDb.GetById(id); if (entity == null) { return(false); } entity.Name = name; sportCategoriesDb.Update(entity); sportCategoriesDb.SaveChanges(); return(true); }
public async Task <int> Update(GenreInputModel input) { var genre = genresRepository.AllAsNoTrackingWithDeleted().FirstOrDefault(x => x.Id == input.Id); if (genre == null) { throw new InvalidOperationException("The genre could not be found"); } genre = AutoMapperConfig.MapperInstance.Map <Genre>(input); genresRepository.Update(genre); await genresRepository.SaveChangesAsync(); return(input.Id); }
public async Task EditAsync(ExperienceModifyInputModel modifiedModel) { var experience = _experienceRepository.All().FirstOrDefault(e => e.Id == modifiedModel.Id); if (experience != null) { experience.Position = modifiedModel.Position; experience.Company = modifiedModel.Company; experience.FromDate = modifiedModel.FromDate; experience.ToDate = modifiedModel.ToDate; experience.Location = modifiedModel.Location; experience.Description = modifiedModel.Description; _experienceRepository.Update(experience); await _experienceRepository.SaveChangesAsync(); } }
public async Task EditAsync(EducationModifyInputModel modifiedModel) { var education = _educationEntityRepository.All().FirstOrDefault(e => e.Id == modifiedModel.Id); if (education != null) { education.Programme = modifiedModel.Programme; education.Degree = modifiedModel.Degree; education.School = modifiedModel.School; education.FromDate = modifiedModel.FromDate; education.ToDate = modifiedModel.ToDate; education.Score = modifiedModel.Score; _educationEntityRepository.Update(education); await _educationEntityRepository.SaveChangesAsync(); } }
public async Task <int> Update(GameInputModel input) { var game = gamesRepository.AllAsNoTrackingWithDeleted().FirstOrDefault(x => x.Id == input.Id); if (game == null) { throw new InvalidOperationException("The game could not be found"); } game = AutoMapperConfig.MapperInstance.Map <Game>(input); gamesRepository.Update(game); await gamesRepository.SaveChangesAsync(); // TODO: Fix Update of Genres //await genresService.RelateGameWithGenres(game.Id, input.GenreIds); return(input.Id); }
public async Task <bool> AddViewAsync(string videoId) { if (videoId == null) { return(false); } var video = await videoRepository.GetByIdAsync(videoId); if (video == null) { return(false); } video.Views = ++video.Views; videoRepository.Update(video); await videoRepository.SaveChangesAsync(); return(true); }
public async Task EditAsync(TeacherModifyInputModel modifiedModel) { var teacher = _teachersRepository.All().FirstOrDefault(s => s.Id == modifiedModel.Id); if (teacher != null) { var inputModel = modifiedModel.Teacher; teacher.FirstName = inputModel.FirstName; teacher.LastName = inputModel.LastName; var schoolId = int.Parse(inputModel.SchoolId); var school = _schoolsRepository.All().FirstOrDefault(s => s.Id == schoolId); if (school != null) { teacher.School = school; } _teachersRepository.Update(teacher); await _teachersRepository.SaveChangesAsync(); } }