public object Dialog(UserDialogViewModel model, bool? ajax) { if (!Request.IsAuthenticated) throw new AuthenticationException(); if (!ModelState.IsValid) return View(model); var user = DataService.PerThread.BaseUserSet.OfType<User>().SingleOrDefault(u => u.Id == UserContext.Current.Id); if (user == null) throw new BusinessLogicException("Перезайдите"); if (!model.ContactId.HasValue) throw new BusinessLogicException("Не указан идентификатор контакта"); var message = MessageService.Send(UserContext.Current.Id, model.ContactId.Value, model.Text, MessageType.PrivateMessage); if (ajax.HasValue && ajax.Value) return Json(new UserDialog_MessageViewModel(message)); if (Request.UrlReferrer != null) return Redirect(Request.UrlReferrer.ToString()); return RedirectToAction("dialog", new { id = model.ContactId }); }
public ActionResult Dialog(Guid? id) { if (!Request.IsAuthenticated) throw new AuthenticationException(); var user = DataService.PerThread.BaseUserSet.OfType<User>().SingleOrDefault(u => u.Id == UserContext.Current.Id); if (user == null) throw new BusinessLogicException("Перезайдите"); UserDialogViewModel model; if (id.HasValue) { if (id.Value == UserContext.Current.Id) throw new BusinessLogicException("Нельзя посылать сообщения самому себе"); var contact = DataService.PerThread.BaseUserSet.OfType<User>().SingleOrDefault(x => x.Id == id.Value); if (contact == null) throw new BusinessLogicException("Указан неверный идентификатор пользователя"); if (contact.BlackList.Contains(user)) throw new BusinessLogicException("Вы находитесь в черном списке у данного пользователя, поэтому не можете посылать ему сообщения"); model = new UserDialogViewModel(contact); } else model = new UserDialogViewModel(null); MessageService.MarkAsRead(user.Id, id); return View(model); }