Beispiel #1
0
    public ActionResult Create(AdminNote adminNote)
    {
        try
        {
            if (ModelState.IsValid)
            {
                adminNote.AdminKey = this.ControllerContext.HttpContext
                                     .User.Identity.GetUserId();
                adminNote.AdminName = this.ControllerContext.HttpContext
                                      .User.Identity.GetUserName();
                adminNote.CreateDate   = DateTimeDelegate();
                adminNote.ModifiedDate = DateTimeDelegate();
                adminNote.ObjectState  = ObjectState.Added;
                _adminNoteService.Insert(adminNote);

                return(RedirectToAction("UserDetails", "Admin",
                                        new { UserKey = adminNote.UserKey }));
            }
        }
        catch (Exception ex)
        {
            ControllerConstants.HandleException(ex);
            ViewBag.PopupMessage(string.Format
                                     ("We're sorry but an error occurred. {0}", ex.Message));
        }
        return(View(adminNote));
    }
    public void CreateAction_ModelStateIsValid_EnsureRedirectToActionContainsExpectedRoutes()
    {
        // Arrange
        var fakeNote    = new AdminNote();
        var stubService = new Mock <IAdminNoteService>();
        var sut         = new AdminsNotesController(stubService.Object);

        var fakeHttpContext = new Mock <HttpContextBase>();
        var fakeIdentity    = new GenericIdentity("User");
        var principal       = new GenericPrincipal(fakeIdentity, null);

        fakeHttpContext.Setup(t => t.User).Returns(principal);
        var controllerContext = new Mock <ControllerContext>();

        controllerContext.Setup(t => t.HttpContext)
        .Returns(fakeHttpContext.Object);
        sut.ControllerContext    = controllerContext.Object;
        sut.FakeDateTimeDelegate = () => new DateTime(2015, 01, 01);
        // Act
        var result = sut.Create(fakeNote) as RedirectToRouteResult;

        // Assert
        Assert.AreEqual(result.RouteValues["controller"], "Admin");
        Assert.AreEqual(result.RouteValues["action"], "UserDetails");
    }
        public async Task ExecuteAsync(CreateNoteCommand message, CancellationToken token)
        {
            var user = await _userRepository.LoadAsync(message.UserId, token);

            var adminUser = await _adminUserRepository.LoadAsync(message.AdminId, token);

            var note = new AdminNote(message.Text, user, adminUser);
            await _noteRepository.AddAsync(note, token);
        }
Beispiel #4
0
 public static SharedAdminNote ToShared(this AdminNote note)
 {
     return(new SharedAdminNote(
                note.Id,
                note.RoundId,
                note.Message,
                note.CreatedBy.LastSeenUserName,
                note.LastEditedBy.LastSeenUserName,
                note.CreatedAt,
                note.LastEditedAt
                ));
 }
Beispiel #5
0
        public async Task <IActionResult> AdminNote(AdminNote adminNote)
        {
            var aNotes = await _unitOfWork.AdminNotes.GetAllAsync();

            var aNote = aNotes.FirstOrDefault();

            if (aNote == null)
            {
                _unitOfWork.AdminNotes.Add(new AdminNote
                {
                    Note = adminNote.Note
                });
            }
            else
            {
                aNote.Note = adminNote.Note;
            }
            await _unitOfWork.SaveAsync();

            return(RedirectToAction(nameof(Index)));
        }