public void Create(DentistDTO dentistDTO) { var dentist = DentistMapper.DTOtoApplicationUser(dentistDTO); PasswordHasher <ApplicationUser> passwordHasher = new PasswordHasher <ApplicationUser>(); var passwordHash = passwordHasher.HashPassword(dentist, dentistDTO.Password); dentist.PasswordHash = passwordHash; _context.ApplicationUsers.Add(dentist); var role = _context.ApplicationRole.Where(r => r.Name.Equals("Dentist")).Single(); dentist.UserRoles.Add(new ApplicationUserRole() { User = dentist, Role = role, }); var userId = _userProviderService.GetUserId(); var affiliateId = _context.ApplicationUsers .Where(u => u.Id.Equals(userId)) .Select(u => u.AffiliateId) .Single(); var affiliate = _context.Affiliates.Find(affiliateId); dentist.Affiliate = affiliate; _context.SaveChanges(); }
public ScheduleDTO Get(int id) { var schedule = _context.Schedule .Include(s => s.Patient) .Where(s => s.Id.Equals(id)) .Where(s => s.UserId.Equals(_userProviderService.GetUserId())) .SingleOrDefault(); if (schedule is null) { return(null); } return(ScheduleMapper.ScheduleToDTO(schedule)); }
public void Create(CommentDTO commentDTO) { var tooth = _context.Teeth.Find(commentDTO.ToothId); var comment = CommentMapper.DTOtoComment(commentDTO); comment.Tooth = tooth; comment.Created = DateTime.Now; comment.UserId = _userProviderService.GetUserId(); _context.Comments.Add(comment); _context.SaveChanges(); }
public StatisticDTO Get() { var affiliateId = _context.ApplicationUsers .Where(u => u.Id.Equals(_userProviderService.GetUserId())) .Select(u => u.AffiliateId) .Single(); var firstDay = DateTimeDayOfMonth.FirstDayOfMonth(DateTime.Now); var firstDayLastMonth = DateTimeDayOfMonth.FirstDayOfMonth(DateTime.Now.AddMonths(-1)); var lastDay = DateTimeDayOfMonth.LastDayOfMonth(DateTime.Now); var lastDayLastMonth = DateTimeDayOfMonth.LastDayOfMonth(DateTime.Now.AddMonths(-1)); return(GetStatisticData(affiliateId, firstDay, firstDayLastMonth, lastDay, lastDayLastMonth)); }
public void Create(TreatmentHistoryDTO treatmentHistoryDTO) { var treatmentHistory = TreatmentHistoryMapper.DTOtoTreatmentHistory(treatmentHistoryDTO); var medicalChart = _context.MedicalCharts.Find(treatmentHistoryDTO.MedicalChartId); var treatment = _context.Treatments.Find(treatmentHistoryDTO.TreatmentId); var tooth = _context.Teeth.Find(treatmentHistoryDTO.ToothId); string userId; if (treatmentHistoryDTO.UserId is null) { userId = _userProviderService.GetUserId(); } else { userId = treatmentHistoryDTO.UserId; } var user = _context.ApplicationUsers.Find(userId); var affiliateId = _context.ApplicationUsers .Where(u => u.Id.Equals(userId)) .Select(u => u.AffiliateId) .Single(); var affiliate = _context.Affiliates.Find(affiliateId); treatmentHistory.Price = treatment.Price; treatmentHistory.Treatment = treatment; treatmentHistory.Tooth = tooth; treatmentHistory.Affiliate = affiliate; treatmentHistory.MedicalChart = medicalChart; treatmentHistory.User = user; _context.TreatmentHistories.Add(treatmentHistory); _context.SaveChanges(); }
public UserDTO GetCurrent() { var applicationUser = _context.ApplicationUsers .Include(ur => ur.UserRoles) .ThenInclude(r => r.Role) .Include(a => a.Affiliate) .SingleOrDefault(x => x.Id.Equals(_userProviderService.GetUserId())); if (applicationUser == null) { return(null); } return(UserMapper.ApplicationUserToDTO(applicationUser)); }