public void SendForAll() { IsStopped = false; if (CurrentUser == null) { CurrentUser = 0; } var mailTemplate = GetTemplate(); Task.Factory.StartNew(() => { var count = 0; while (true) { if (IsStopped) { return; } if (count++ > 100000) { return; } var currentUserId = CurrentUser.GetValueOrDefault(); using (var context = new PassportDataContext()) { var userQuerybale = context.Users.AsQueryable(); var mailListType = mailTemplate.V2; userQuerybale = AddFilter(userQuerybale, mailListType); var user = userQuerybale .Select(x => new { x.UserID, x.Email, FullName = x.FirstName + " " + x.SecondName }) .OrderBy(x => x.UserID) .Where(x => x.UserID > currentUserId).FirstOrDefault(); if (user == null) { CurrentUser = null; return; } using (var client = new SmtpClient()) { var time = DateTime.Now; Send(client, mailTemplate.V1, user.Email, user.FullName); CurrentUser = user.UserID; var pause = 3000 - (int)(DateTime.Now - time).TotalMilliseconds; if (pause > 0) { Thread.Sleep(pause); } } } } }, TaskCreationOptions.LongRunning).ContinueWith(task => { if (task.Exception != null) { IsStopped = true; Logger.Exception(task.Exception, "maillist " + task.Exception); } }); }
private void Unsubscribe(string email) { using (var context = new PassportDataContext()) { foreach (var user in context.Users.Where(u => u.Email == email)) { user.MailListSubscribed = false; user.MailListTypes = (byte)MailListType.None; } context.SubmitChanges(); } }
public void Update() { var context = new PassportDataContext(); var photos = context.UserContacts.Where(x => x.ContactTypeID == ContactTypes.VKontakte && x.User.Student_ID > 0) .Select(x => new { x.User.Student_ID, x.Contact }) .ToDictionary(x => x.Student_ID.Value, x => GetVkUrl(x.Contact)); var students = photos.Keys.ToList(); var specContext = new SpecialistDataContext(); var responses = specContext.GetTable <Response>().Select(x => new { x.RawQuestionnaire.Questionnaire.Student_ID, Response = x }) .Where(x => students.Contains(x.Student_ID)).ToList(); foreach (var response in responses) { var vkUrl = photos[response.Student_ID]; if (vkUrl != null) { response.Response.PhotoUrl = vkUrl.Item1; response.Response.SocialUrl = vkUrl.Item2; } } specContext.SubmitChanges(); }