public async Task <ActionResult <TypeOfExamDto> > DeleteTypeOfExam(int id, string userId) { var typeOfExam = await _context.TypeOfExams.FindAsync(id); if (typeOfExam == null) { return(NotFound()); } typeOfExam.DeletedDate = DateTime.Now; typeOfExam.DeletedUserId = userId; typeOfExam.VirtualDeleted = true; _context.Entry(typeOfExam).State = EntityState.Modified; var user = await _context.Users.FirstOrDefaultAsync(x => x.Id == userId); var log = new Log() { DateTime = DateTime.Now, TypeFullName = typeof(TypeOfExam).FullName, Content = "@userName@deleteAction@objTitle", TypeId = typeOfExam.Id, UserId = user.Id }; _context.Logs.Add(log); try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TypeOfExamExists(id)) { return(NotFound()); } else { throw; } } var result = new TypeOfExamDto() { Id = typeOfExam.Id, Name = typeOfExam.Name, ForeignName = typeOfExam.ForeignName, Cost = typeOfExam.Cost }; return(result); }
public async Task <ActionResult <TypeOfExamDto> > GetTypeOfExam(int id) { var typeOfExam = await _context.TypeOfExams.FindAsync(id); if (typeOfExam == null) { return(NotFound()); } var result = new TypeOfExamDto() { Id = typeOfExam.Id, Name = typeOfExam.Name, ForeignName = typeOfExam.ForeignName, Cost = typeOfExam.Cost }; return(result); }
public async Task <ActionResult <TypeOfExamDto> > PostTypeOfExam(TypeOfExamInputDto input) { try { var typeOfExam = new TypeOfExam() { Name = input.Name, ForeignName = input.ForeignName, Cost = input.Cost, CreatedDate = DateTime.Now, CreatedUserId = input.UserId }; _context.TypeOfExams.Add(typeOfExam); await _context.SaveChangesAsync(); var user = await _context.Users.FirstOrDefaultAsync(x => x.Id == input.UserId); var log = new Log() { DateTime = DateTime.Now, TypeFullName = typeof(TypeOfExam).FullName, Content = "@userName@addAction@objTitle", TypeId = typeOfExam.Id, UserId = user.Id }; _context.Logs.Add(log); await _context.SaveChangesAsync(); var result = new TypeOfExamDto() { Id = typeOfExam.Id, Name = typeOfExam.Name, ForeignName = typeOfExam.ForeignName, Cost = typeOfExam.Cost }; return(result); } catch (Exception ex) { return(null); } }