public async Task <ActionResult> AddThread(int groupId, AddThreadViewModel model) { if (!ModelState.IsValid) { return(View(model)); } ViewBag.GroupId = groupId; // Creating the thread Thread thread = new Thread { Name = model.Name, Tags = (!String.IsNullOrEmpty(model.Tags)) ? model.Tags.Split(',').ToList().Where(s => !String.IsNullOrEmpty(s)).Select(s => s.Trim()).ToArray() : new string[0], Pinned = model.Pinned }; // Creating the message (There not connected here becouse they will be in the core of the code) Message message = new Message { Body = model.FirstMessage }; // Save the new thread and returns the result thread = await ThreadManager.CreateWithMessageAsync(thread, message, await GroupManager.FindByIdAsync(groupId)); return(RedirectToAction("Groups")); }
//GET: Forum/AddThread/{int} public ActionResult AddThread(int?ID) { if (ID == null) { return(View("Error")); } var model = new AddThreadViewModel { GroupID = (int)ID }; return(View(model)); }
public void AddCommand_ShouldBeEnabled_IfTitleAndContentAreNotEmpty() { // Arrange _target = new AddThreadViewModel(_schedulerService, _viewStackService.Object, _threadsServiceMock.Object); // Act _target.Activator.Activate(); _target.Title = "Title"; _target.Content = "Content"; _schedulerService.AdvanceBy(1000); // Assert _target.AddThread.CanExecute.Subscribe(canExecute => Assert.IsTrue(canExecute)); }
public void WhenExecuted_CheckIfPopPageIsCalled() { // Arrange _target = new AddThreadViewModel(_schedulerService, _viewStackService.Object, _threadsServiceMock.Object); _target.Title = "Title"; _target.Content = "Content"; // Act Observable.Return(Unit.Default).InvokeCommand(_target.AddThread); // Assert _threadsServiceMock .Verify(x => x.Create( It.IsAny <ThreadRequestDTO>()), Times.Once); }
public ActionResult AddThread(AddThreadViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var thread = new Thread { UserID = User.Identity.GetUserId(), Title = model.Title, GroupID = model.GroupID, Message = model.Message == null? "" : model.Message, TimeDate = DateTime.Now }; var db = new ApplicationDbContext(); var result = db.Threads.Add(thread); db.SaveChanges(); return(RedirectToAction("ViewThread", new { ID = result.ThreadID })); }
private ClassifiedModel PopulateClassifiedModel <T>(T type, AddThreadViewModel input) where T : ClassifiedModel { type.Username = input.Username; type.EmailAddress = input.Email; type.ClassifiedCategory = input.ClassifiedCategory; type.ClassifiedTitle = input.ClassifiedTitle; type.HousingType = input.HousingType; type.BuySellItem = input.BuySellItem; type.Price = input.Price; type.AdditionalInfo = input.AdditionalInfo; type.City = input.City; type.State = input.State; type.Country = input.Country; type.JobDetails = input.JobDetails; type.PostedOn = DateTime.Now; type.IpAddress = GetIp(); type.Browser = Request.Browser.Browser; type.ClassifiedRadio = input.ClassifiedRadio; type.LastUpdated = DateTime.Now; type.CurrentStatus = Constants.ClassifiedItemAvailable; //available if (Request.Files.Count > 0) { var pathParent = Server.MapPath("~/Content/CI"); for (int i = 0; i < Request.Files.Count; i++) { HttpPostedFileBase httpPostedFileBase = Request.Files[i]; if (httpPostedFileBase == null || httpPostedFileBase.ContentLength < 1) { continue; } var fileName = Path.GetFileName(httpPostedFileBase.FileName); var imageUrl = pathParent + "//" + fileName; httpPostedFileBase.SaveAs(imageUrl); type.ClassifiedImageLoc += fileName + "@"; } } return(type); }
public ActionResult AddThreadPost(AddThreadViewModel addThreadViewModel) { bool isLoggedIn = false; var httpCookie = Request.Cookies["LogOnCookie"]; if (httpCookie != null) { isLoggedIn = true; } ViewBag.Username = addThreadViewModel.Username; ViewBag.Email = addThreadViewModel.Email; if (addThreadViewModel.ThreadRadio == "announcement") { if (String.IsNullOrEmpty(addThreadViewModel.Announcement) || String.IsNullOrEmpty(addThreadViewModel.TagsAnnouncement)) { return(View("AddThread")); } ViewBag.Announcement = addThreadViewModel.Announcement; ViewBag.TagsA = addThreadViewModel.TagsAnnouncement; } if (addThreadViewModel.ThreadRadio == "generalThread") { if (String.IsNullOrEmpty(addThreadViewModel.Title) || String.IsNullOrEmpty(addThreadViewModel.Content) || String.IsNullOrEmpty(addThreadViewModel.TagsGeneral)) { return(View("AddThread")); } ViewBag.Title = addThreadViewModel.Title; ViewBag.Content = addThreadViewModel.Content; ViewBag.TagsG = addThreadViewModel.TagsGeneral; } if (!isLoggedIn) { if (_unitOfWork.DoesUserNameOrEmailExist(addThreadViewModel.Username) == 1) { ViewBag.Error = "Username already exists!"; return(View("AddThread")); } if (_unitOfWork.DoesUserNameOrEmailExist(addThreadViewModel.Email) == 2) { ViewBag.Error = "Email already exists!"; return(View("AddThread")); } } var scope = new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions() { IsolationLevel = IsolationLevel.ReadCommitted } ); try { using (scope){ if (!isLoggedIn) { var pass = System.Web.Security.Membership.GeneratePassword(10, 2); var passencrypted = Encryption.Encrypt(pass); var userModel = new UserModel { Username = ViewBag.Username, Email = ViewBag.Email, Password = passencrypted, ConfirmPassword = pass, IpAddress = GetIp(), Browser = Request.Browser.Browser, CreatedOn = DateTime.Now, LastSuccessfulLogin = DateTime.Now }; _unitOfWork.UserRepository.Insert(userModel); _unitOfWork.Save(); _unitOfWork.SendEmail(ViewBag.Email, "Your password for " + Constants.Domain, "Dear " + ViewBag.Username + ",<br />" + "You just posted a thread and thank you for your contribution. <br />Please find the auto generated temporary password." + "<br />Temporary Password:"******"<br />You may want to login with this and change it once you login.<br /><br /> Thanking you <br />" + Constants.Domain + "<br/>" + Constants.Slogan); } if (addThreadViewModel.ThreadRadio == null && addThreadViewModel.TagsAnnouncement == null && addThreadViewModel.TagsGeneral == null) { var cm = new ClassifiedModel(); var objClassifiedModel = PopulateClassifiedModel(cm, addThreadViewModel); _unitOfWork.ClassifiedRepository.Insert(objClassifiedModel); _unitOfWork.Save(); CacheImplementation.ClearSpecificCacheObject(CacheImplementation.Classifieds); } else { var threadModel = new ThreadModel { Username = ViewBag.Username, Email = ViewBag.Email, ThreadRadio = addThreadViewModel.ThreadRadio, Announcement = addThreadViewModel.Announcement, TagsAnnouncement = addThreadViewModel.TagsAnnouncement, Title = addThreadViewModel.Title, Content = addThreadViewModel.Content, TagsGeneral = addThreadViewModel.TagsGeneral, IpAddress = GetIp(), Browser = Request.Browser.Browser, SubmittedOn = DateTime.Now, LastUpdated = DateTime.Now, Likes = 0, Views = 0, Responses = 0 }; _unitOfWork.ThreadRepository.Insert(threadModel); _unitOfWork.Save(); CacheImplementation.ClearSpecificCacheObject(CacheImplementation.RecentThreads); CacheImplementation.ClearSpecificCacheObject(CacheImplementation.TrendingTagsAnnouncement); CacheImplementation.ClearSpecificCacheObject(CacheImplementation.TrendingTagsGeneral); } scope.Complete(); } ViewBag.Username = null; ViewBag.Email = null; ViewBag.Announcement = null; ViewBag.TagsA = null; ViewBag.Title = null; ViewBag.Content = null; ViewBag.TagsG = null; } catch (Exception ex) { scope.Dispose(); Elmah.ErrorSignal.FromCurrentContext().Raise(ex); } var cookieLogOn = new HttpCookie("LogOnCookie"); cookieLogOn.Values["username"] = addThreadViewModel.Username; cookieLogOn.Values["email"] = addThreadViewModel.Email; cookieLogOn.Expires = DateTime.Now.AddDays(2); Response.Cookies.Add(cookieLogOn); return(RedirectToAction("Index", "Home")); }