public async Task <User> SignIntoTutorial(int id) { User created = null; User item = new User { TutorialId = id, Login = httpContext.HttpContext.User.Identity.Name }; var dbItem = (await UsersRepo.GetListAsync(item.Login)).Where(a => a.TutorialId == item.TutorialId).FirstOrDefault(); if (dbItem != null) { dbItem.Active = true; await UsersRepo.UpdateAsync(dbItem); } else { created = await UsersRepo.AddAsync(item); } string examName = ""; string message = ""; if (created != null || dbItem != null) { var temp = await TutorialRepo.GetAsync(id); if (temp != null) { string examUri = $"{httpContext.HttpContext.Request.Scheme}://{httpContext.HttpContext.Request.Host}/UserTutorials/Tutorial/{temp.Id}"; examName = temp.Name; message = localizer["Name: {0}", temp.Name] + $"<br/> Link: <a href='{examUri}'>{examUri}</a>"; } } await emailSender.SendEmailAsync(item.Login, localizer["User sing up for tutorial {0}", examName], message); return(created ?? dbItem); }
public async Task <User> SignIntoExam(int id) { User created = null; User item = new User { ExamId = id, Login = httpContext.HttpContext.User.Identity.Name }; var dbItem = (await UsersRepo.GetListAsync(item.Login)).Where(a => a.ExamId == item.ExamId).FirstOrDefault(); if (dbItem != null) { dbItem.Active = true; await UsersRepo.UpdateAsync(dbItem); } else { created = await UsersRepo.AddAsync(item); } string examName = ""; string message = ""; if (created != null || dbItem != null) { var temp = await ExamsRepo.GetAsync(id); if (temp != null) { string examUri = $"{httpContext.HttpContext.Request.Scheme}://{httpContext.HttpContext.Request.Host}/StartExam/{temp.Code}"; examName = temp.Name; message = localizer["Name {0}<br/>Code {1}<br/>When {2} - {3}<br/>Duration {4} min", temp.Name, temp.Code, temp.MinStart, temp.MaxStart, temp.DurationMinutes] + $"<br/> Link: <a href='{examUri}'>{examUri}</a>"; } } await emailSender.SendEmailAsync(item.Login, localizer["User sing up for exam {0}", examName], message); return(created ?? dbItem); }