Example #1
0
        public void CanSaveOrUpdateValidTimeEntry()
        {
            // Establish Context
            TimeEntry validTimeEntry =
                TimeEntryInstanceFactory.CreateValidTransientTimeEntry();


            // Act
            ActionConfirmation confirmation =
                _timeEntryManagementService.SaveOrUpdate(validTimeEntry);

            // Assert
            confirmation.ShouldNotBeNull();
            confirmation.WasSuccessful.ShouldBeTrue();
            confirmation.Value.ShouldNotBeNull();
            confirmation.Value.ShouldEqual(validTimeEntry);
        }
        public ActionResult Create(TimeEntry timeEntry)
        {
            int userId = GetCurrentUser().Id;

            timeEntry.LastUpdateTimeStamp = DateTime.Now;
            timeEntry.LastUpdateUser      = userId;
            timeEntry.UserId = userId;
            timeEntry.Notes  = Server.HtmlEncode(timeEntry.Notes);

            var timeEntryDateString = string.Empty;

            if (timeEntry.WeekEndingDate.HasValue)
            {
                timeEntryDateString = timeEntry.WeekEndingDate.Value.ToString("MM-dd-yyyy");
            }

            if (ViewData.ModelState.IsValid)
            {
                ActionConfirmation saveOrUpdateConfirmation =
                    _timeEntryManagementService.SaveOrUpdate(timeEntry);

                if (saveOrUpdateConfirmation.WasSuccessful)
                {
                    TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] =
                        saveOrUpdateConfirmation.Message;
                    return(RedirectToAction("Index", new RouteValueDictionary(new { action = "Index", date = timeEntryDateString })));
                }
            }
            else
            {
                timeEntry = null;
            }

            TimeEntryFormViewModel viewModel =
                _timeEntryManagementService.CreateFormViewModelFor(timeEntry, _authenticationProvider.GetLoggedInUser());

            //return !string.IsNullOrEmpty(timeEntryDateString) ? RedirectToAction(action, new { date = timeEntryDateString }) : RedirectToAction(action);
            return(RedirectToAction("Index", new RouteValueDictionary(new { action = "Index", date = timeEntryDateString })));
        }