public ActionConfirmation Delete(int id)
        {
            SlideFolder slideFolderToDelete = slideFolderRepository.Get(id);

            if (slideFolderToDelete != null)
            {
                slideFolderRepository.Delete(slideFolderToDelete);

                try {
                    slideFolderRepository.DbContext.CommitChanges();

                    return(ActionConfirmation.CreateSuccessConfirmation(
                               "The slideFolder was successfully deleted."));
                }
                catch {
                    slideFolderRepository.DbContext.RollbackTransaction();

                    return(ActionConfirmation.CreateFailureConfirmation(
                               "A problem was encountered preventing the slideFolder from being deleted. " +
                               "Another item likely depends on this slideFolder."));
                }
            }
            else
            {
                return(ActionConfirmation.CreateFailureConfirmation(
                           "The slideFolder could not be found for deletion. It may already have been deleted."));
            }
        }
Exemple #2
0
        public ActionConfirmation Delete(int id)
        {
            Request requestToDelete = _requestRepository.Get(id);

            if (requestToDelete != null)
            {
                _requestEstimateManagementService.DeleteByRequest(id);
                _requestRepository.Delete(requestToDelete);

                try
                {
                    _requestRepository.DbContext.CommitChanges();

                    return(ActionConfirmation.CreateSuccessConfirmation(
                               "The request was successfully deleted."));
                }
                catch
                {
                    _requestRepository.DbContext.RollbackTransaction();

                    return(ActionConfirmation.CreateFailureConfirmation(
                               "A problem was encountered preventing the request from being deleted. " +
                               "Another item likely depends on this request."));
                }
            }
            else
            {
                return(ActionConfirmation.CreateFailureConfirmation(
                           "The request could not be found for deletion. It may already have been deleted."));
            }
        }
        public ActionConfirmation ValidateUser(UserDto userToValidate)
        {
            Person user;

            try
            {
                _securityProvider.Authenticate(userToValidate.UserName, userToValidate.Password);
                if (!_securityProvider.IsAuthenticated)
                {
                    return(ActionConfirmation.CreateFailureConfirmation("Invalid network user name or password"));
                }
                user = _personRepository.GetByUserName(userToValidate.UserName);
                if (user == null)
                {
                    return(ActionConfirmation.CreateFailureConfirmation("User not found"));
                }
                return(ActionConfirmation.CreateSuccessConfirmation(""));
            }
            catch (InvalidPasswordException)
            {
                return(ActionConfirmation.CreateFailureConfirmation("Invalid network user name or password"));
            }
            catch (NetworkUserNotFoundException)
            {
                return(ActionConfirmation.CreateFailureConfirmation("Invalid Network User Name or Password"));
            }
            catch (Exception ex)
            {
                throw new Exception("Encountered an error while attempting to validate username and password", ex);
            }
        }
Exemple #4
0
        public ActionConfirmation SaveOrUpdate(Request request)
        {
            if (request.IsValid())
            {
                ValidateRequest(request);
                if (request.IsRequestSignedOff == null)
                {
                    request.IsRequestSignedOff = false;
                }
                _requestRepository.SaveOrUpdate(request);
                if (!SaveEstimate(request))
                {
                    _requestRepository.DbContext.RollbackTransaction();
                    return(ActionConfirmation.CreateFailureConfirmation(
                               "The request could not be saved due to missing or invalid information."));
                }
                ActionConfirmation saveOrUpdateConfirmation = ActionConfirmation.CreateSuccessConfirmation(
                    "The request was successfully saved.");
                saveOrUpdateConfirmation.Value = request;

                return(saveOrUpdateConfirmation);
            }
            else
            {
                _requestRepository.DbContext.RollbackTransaction();

                return(ActionConfirmation.CreateFailureConfirmation(
                           "The request could not be saved due to missing or invalid information."));
            }
        }
Exemple #5
0
        public ActionConfirmation UpdateWith(Request requestFromForm, int idOfRequestToUpdate)
        {
            Request requestToUpdate =
                _requestRepository.Get(idOfRequestToUpdate);

            ValidateRequest(requestFromForm);

            TransferFormValuesTo(requestToUpdate, requestFromForm);

            if (requestToUpdate.IsValid())
            {
                if (!SaveEstimate(requestToUpdate))
                {
                    _requestRepository.DbContext.RollbackTransaction();
                    return(ActionConfirmation.CreateFailureConfirmation(
                               "The request could not be saved due to missing or invalid information."));
                }
                ActionConfirmation updateConfirmation = ActionConfirmation.CreateSuccessConfirmation(
                    "The request was successfully updated.");
                updateConfirmation.Value = requestToUpdate;

                return(updateConfirmation);
            }
            else
            {
                _requestRepository.DbContext.RollbackTransaction();


                return(ActionConfirmation.CreateFailureConfirmation(
                           "The request could not be saved due to missing or invalid information."));
            }
        }
Exemple #6
0
        public ActionConfirmation UpdateWith(Template templateFromForm, int idOfTemplateToUpdate, string fileName, byte[] fileByteArray)
        {
            Template templateToUpdate =
                templateRepository.Get(idOfTemplateToUpdate);

            TransferFormValuesTo(templateToUpdate, templateFromForm);

            if (fileByteArray != null)
            {
                SaveFile(templateToUpdate, fileName, fileByteArray);
            }

            if (templateToUpdate.IsValid())
            {
                ActionConfirmation updateConfirmation = ActionConfirmation.CreateSuccessConfirmation(
                    "The template was successfully updated.");
                updateConfirmation.Value = templateToUpdate;

                return(updateConfirmation);
            }
            else
            {
                templateRepository.DbContext.RollbackTransaction();

                return(ActionConfirmation.CreateFailureConfirmation(
                           "The template could not be saved due to missing or invalid information."));
            }
        }
Exemple #7
0
        public ActionConfirmation UpdateWith(Host hostFromForm, int idOfHostToUpdate)
        {
            Host hostToUpdate =
                _hostRepository.Get(idOfHostToUpdate);

            ValidateHost(hostFromForm);

            TransferFormValuesTo(hostToUpdate, hostFromForm);

            if (hostToUpdate.IsValid())
            {
                ActionConfirmation updateConfirmation = ActionConfirmation.CreateSuccessConfirmation(
                    "The host was successfully updated.");
                updateConfirmation.Value = hostToUpdate;

                return(updateConfirmation);
            }
            else
            {
                _hostRepository.DbContext.RollbackTransaction();

                return(ActionConfirmation.CreateFailureConfirmation(
                           "The host could not be saved due to missing or invalid information."));
            }
        }
        public virtual ActionConfirmation <T> Delete(int id)
        {
            T toDelete = _entityRepository.Get(id);

            if (toDelete != null)
            {
                try {
                    _entityRepository.Delete(toDelete);
                    return(ActionConfirmation <T> .CreateSuccessConfirmation(
                               "The " + GetFriendlyNameOfType() + " was successfully deleted.", toDelete));
                }
                // A foreign key constraint violation will thrown an exception.  As inadvisable as it use
                // to use exceptions as a means of business logic, this is certainly the easiest way to to do it.
                catch {
                    // Since we're swallowing the exception, we want to make sure the transaction gets rolled back
                    _entityRepository.DbContext.RollbackTransaction();

                    return(ActionConfirmation <T> .CreateFailureConfirmation(
                               "The " + GetFriendlyNameOfType() + " could not be deleted; another item depends on it.", toDelete));
                }
            }

            return(ActionConfirmation <T> .CreateFailureConfirmation(
                       "The " + GetFriendlyNameOfType() + " could not be found for deletion. It may already have been deleted.", default(T)));
        }
Exemple #9
0
        public void CanSaveOrUpdateValidRequest()
        {
            // Establish Context
            Request validRequest =
                RequestInstanceFactory.CreateValidTransientRequest();

            WrmsSystem systemToExpect = WrmsSystemInstanceFactory.CreateValidTransientWrmsSystem();

            _wrmsSystemManagementService.Expect(r => r.Get(13))
            .Return(systemToExpect);

            _requestEstimateManagementService.Expect(
                r =>
                r.SaveOrUpdate(new RequestEstimate
            {
                RequestId = validRequest.Id, EstimatedHours = validRequest.EstimatedHours
            })).Return(
                ActionConfirmation.CreateSuccessConfirmation(""));

            // Act
            ActionConfirmation confirmation =
                _requestManagementService.SaveOrUpdate(validRequest);

            // Assert
            confirmation.ShouldNotBeNull();
            confirmation.WasSuccessful.ShouldBeTrue();
            confirmation.Value.ShouldNotBeNull();
            confirmation.Value.ShouldEqual(validRequest);
        }
        public ActionConfirmation <SupportTicket> Open(SupportTicketFormDto supportTicketFormDto)
        {
            if (supportTicketFormDto == null)
            {
                throw new ArgumentNullException("supportTicketFormDto is null");
            }
            if (!DataAnnotationsValidator.TryValidate(supportTicketFormDto))
            {
                throw new InvalidOperationException("supportTicketFormDto is in an invalid state");
            }

            var supportTicketToSave = supportTicketFormDto.Id > 0
                ? _supportTicketRepository.Get(supportTicketFormDto.Id)
                : CreateNewSupportTicket(supportTicketFormDto);

            TransferFormValuesTo(supportTicketToSave, supportTicketFormDto);

            var customerConfirmationMessage = HandleNewCustomer(supportTicketFormDto.NewCustomer, supportTicketToSave);
            var issueConfirmationMessage    = HandleNewIssueType(supportTicketFormDto.NewIssueType, supportTicketToSave);

            _supportTicketRepository.SaveOrUpdate(supportTicketToSave);

            return(ActionConfirmation <SupportTicket>
                   .CreateSuccessConfirmation("Support ticket #" + supportTicketToSave.Id + " has been opened." +
                                              customerConfirmationMessage + issueConfirmationMessage, supportTicketToSave));
        }
        public ActionConfirmation Run(int id)
        {
            var rssFeed = rSSFeedRepository.Get(id);

            Run(rssFeed);
            return(ActionConfirmation.CreateSuccessConfirmation("Success"));
        }
        public ActionConfirmation Delete(int id)
        {
            TimeEntry timeEntryToDelete = _timeEntryRepository.Get(id);

            if (timeEntryToDelete != null)
            {
                _timeEntryRepository.Delete(timeEntryToDelete);

                try
                {
                    _timeEntryRepository.DbContext.CommitChanges();

                    return(ActionConfirmation.CreateSuccessConfirmation(
                               "The Time Entry was successfully deleted."));
                }
                catch
                {
                    _timeEntryRepository.DbContext.RollbackTransaction();

                    return(ActionConfirmation.CreateFailureConfirmation(
                               "A problem was encountered preventing the Time Entry from being deleted. " +
                               "Another item likely depends on this Time Entry."));
                }
            }
            else
            {
                return(ActionConfirmation.CreateFailureConfirmation(
                           "The Time Entry could not be found for deletion. It may already have been deleted."));
            }
        }
Exemple #13
0
        public ActionConfirmation Create(Template template, string fileName, byte[] fileByteArray)
        {
            Template newTemplate = new Template(".swf");

            SaveFile(newTemplate, fileName, fileByteArray);
            newTemplate.MetaData        = template.MetaData;
            newTemplate.Publisher       = template.Publisher;
            newTemplate.DisplayDuration = template.DisplayDuration;
            templateRepository.SaveOrUpdate(newTemplate);
            return(ActionConfirmation.CreateSuccessConfirmation("The template was successfully uploaded"));
        }
        public void CanDeleteTimeEntry()
        {
            // Establish Context
            _timeEntryManagementService.Expect(r => r.Delete(1))
            .Return(ActionConfirmation.CreateSuccessConfirmation("deleted"));

            // Act
            RedirectToRouteResult redirectResult =
                _timeEntriesController.Delete(1)
                .AssertActionRedirect().ToAction("Index");

            // Assert
            _timeEntriesController.TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()].ToString()
            .ShouldEqual("deleted");
        }
        public ActionConfirmation Refresh()
        {
            try
            {
                //NHibernateSession.GetDefaultSessionFactory().OpenSession();
                var rssFeeds = rSSFeedRepository.GetAll();
                foreach (var rssFeed in rssFeeds)
                {
                    rSSFeedRepository.DbContext.BeginTransaction();
                    Run(rssFeed);
                    rSSFeedRepository.DbContext.CommitChanges();
                    rSSFeedRepository.DbContext.CommitTransaction();
                }

                NHibernateSession.Current.Clear();

                List <string> filesToDelete = new List <string>();
                var           slideFolders  = slideFolderRepository.GetSlideFoldersWithTooManySlides();
                slideFolderRepository.DbContext.BeginTransaction();

                foreach (var slideFolder in slideFolders)
                {
                    int numberOfSlideToRemove = slideFolder.SlideCount - slideFolder.MaxSlideCount;
                    for (int x = 0; x < numberOfSlideToRemove; x++)
                    {
                        var slide = slideFolder.Slides[0];
                        filesToDelete.Add(slide.FileFullPathName);
                        slideFolder.Slides.RemoveAt(0);
                        slideRepository.Delete(slide);
                    }
                }
                slideFolderRepository.DbContext.CommitChanges();
                rSSFeedRepository.DbContext.CommitTransaction();

                foreach (var filePath in filesToDelete)
                {
                    if (File.Exists(filePath))
                    {
                        File.Delete(filePath);
                    }
                }
            }
            catch (Exception ex)
            {
                return(ActionConfirmation.CreateFailureConfirmation(ex.ToString()));
            }
            return(ActionConfirmation.CreateSuccessConfirmation("Success"));
        }
Exemple #16
0
        public void CanUpdateValidChannelFromForm()
        {
            // Establish Context
            Channel channelFromForm = new Channel();

            channelManagementService.Expect(r => r.UpdateWith(channelFromForm, 0))
            .Return(ActionConfirmation.CreateSuccessConfirmation("updated"));

            // Act
            RedirectToRouteResult redirectResult =
                channelsController.Edit(channelFromForm)
                .AssertActionRedirect().ToAction("Index");

            // Assert
            channelsController.TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()].ToString()
            .ShouldEqual("updated");
        }
        public void CanUpdateValidTemplateFromForm()
        {
            // Establish Context
            Template templateFromForm = new Template();

            templateManagementService.Expect(r => r.UpdateWith(templateFromForm, 0, null, null))
            .Return(ActionConfirmation.CreateSuccessConfirmation("updated"));

            // Act
            RedirectToRouteResult redirectResult =
                templatesController.Edit(templateFromForm, null)
                .AssertActionRedirect().ToAction("Index");

            // Assert
            templatesController.TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()].ToString()
            .ShouldEqual("updated");
        }
        public void CanCreateValidAssetContentFromForm()
        {
            // Establish Context
            AssetContent assetContentFromForm = new AssetContent();

            assetContentManagementService.Expect(r => r.SaveOrUpdate(assetContentFromForm))
            .Return(ActionConfirmation.CreateSuccessConfirmation("saved"));

            // Act
            RedirectToRouteResult redirectResult =
                assetContentsController.Create(assetContentFromForm)
                .AssertActionRedirect().ToAction("Index");

            // Assert
            assetContentsController.TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()].ToString()
            .ShouldEqual("saved");
        }
        public ActionConfirmation DeleteByRequest(int requestId)
        {
            _requestEstimateRepository.DeleteByRequest(requestId);
            try
            {
                _requestEstimateRepository.DbContext.CommitChanges();

                return(ActionConfirmation.CreateSuccessConfirmation(
                           "The requestEstimates were successfully deleted."));
            }
            catch
            {
                _requestEstimateRepository.DbContext.RollbackTransaction();

                return(ActionConfirmation.CreateFailureConfirmation(
                           "A problem was encountered preventing the requestEstimates from being deleted. " +
                           "Another item likely depends on this Request Estimate."));
            }
        }
        public ActionConfirmation SaveOrUpdate(TimeEntry timeEntry)
        {
            if (timeEntry.IsValid())
            {
                _timeEntryRepository.SaveOrUpdate(timeEntry);

                ActionConfirmation saveOrUpdateConfirmation = ActionConfirmation.CreateSuccessConfirmation("");
                saveOrUpdateConfirmation.Value = timeEntry;

                return(saveOrUpdateConfirmation);
            }
            else
            {
                _timeEntryRepository.DbContext.RollbackTransaction();

                return(ActionConfirmation.CreateFailureConfirmation(
                           "The Time Entry could not be saved due to missing or invalid information."));
            }
        }
        public ActionConfirmation SaveOrUpdate(AssetContent assetContent)
        {
            if (assetContent.IsValid())
            {
                assetContentRepository.SaveOrUpdate(assetContent);

                ActionConfirmation saveOrUpdateConfirmation = ActionConfirmation.CreateSuccessConfirmation(
                    "The assetContent was successfully saved.");
                saveOrUpdateConfirmation.Value = assetContent;

                return(saveOrUpdateConfirmation);
            }
            else
            {
                assetContentRepository.DbContext.RollbackTransaction();

                return(ActionConfirmation.CreateFailureConfirmation(
                           "The assetContent could not be saved due to missing or invalid information."));
            }
        }
        public void CanUpdateValidTimeEntryFromForm()
        {
            // Establish Context
            var timeEntryFromForm = new TimeEntry();

            _timeEntryManagementService.Expect(r => r.UpdateWith(timeEntryFromForm, 0))
            .Return(ActionConfirmation.CreateSuccessConfirmation("updated"));
            _authenticationProvider.Expect(x => x.GetLoggedInUser()).Return("testuser");
            _personManagementService.Expect(x => x.GetByUserName(Arg <string> .Is.Anything)).Return(
                PersonInstanceFactory.CreateValidTransientPerson());

            // Act
            RedirectToRouteResult redirectResult =
                _timeEntriesController.Edit(timeEntryFromForm)
                .AssertActionRedirect().ToAction("Index");

            // Assert
            _timeEntriesController.TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()].ToString()
            .ShouldEqual("updated");
        }
Exemple #23
0
        public ActionConfirmation SaveOrUpdate(Slide slide)
        {
            if (slide.IsValid())
            {
                slideRepository.SaveOrUpdate(slide);

                ActionConfirmation saveOrUpdateConfirmation = ActionConfirmation.CreateSuccessConfirmation(
                    "The slide was successfully saved.");
                saveOrUpdateConfirmation.Value = slide;

                return(saveOrUpdateConfirmation);
            }
            else
            {
                slideRepository.DbContext.RollbackTransaction();

                return(ActionConfirmation.CreateFailureConfirmation(
                           "The slide could not be saved due to missing or invalid information."));
            }
        }
Exemple #24
0
        public ActionConfirmation SaveOrUpdate(RequestStatus requestStatus)
        {
            if (requestStatus.IsValid())
            {
                _requestStatusRepository.SaveOrUpdate(requestStatus);

                ActionConfirmation saveOrUpdateConfirmation = ActionConfirmation.CreateSuccessConfirmation(
                    "The requestStatus was successfully saved.");
                saveOrUpdateConfirmation.Value = requestStatus;

                return(saveOrUpdateConfirmation);
            }
            else
            {
                _requestStatusRepository.DbContext.RollbackTransaction();

                return(ActionConfirmation.CreateFailureConfirmation(
                           "The requestStatus could not be saved due to missing or invalid information."));
            }
        }
Exemple #25
0
        public ActionConfirmation SaveOrUpdate(SupportTeam supportTeam)
        {
            if (supportTeam.IsValid())
            {
                _supportTeamRepository.SaveOrUpdate(supportTeam);

                ActionConfirmation saveOrUpdateConfirmation = ActionConfirmation.CreateSuccessConfirmation(
                    "The support team was successfully saved.");
                saveOrUpdateConfirmation.Value = supportTeam;

                return(saveOrUpdateConfirmation);
            }
            else
            {
                _supportTeamRepository.DbContext.RollbackTransaction();

                return(ActionConfirmation.CreateFailureConfirmation(
                           "The support team could not be saved due to missing or invalid information."));
            }
        }
Exemple #26
0
        public ActionConfirmation SaveOrUpdate(Channel channel)
        {
            if (channel.IsValid())
            {
                channelRepository.SaveOrUpdate(channel);

                ActionConfirmation saveOrUpdateConfirmation = ActionConfirmation.CreateSuccessConfirmation(
                    "The channel was successfully saved.");
                saveOrUpdateConfirmation.Value = channel;

                return(saveOrUpdateConfirmation);
            }
            else
            {
                channelRepository.DbContext.RollbackTransaction();

                return(ActionConfirmation.CreateFailureConfirmation(
                           "The channel could not be saved due to missing or invalid information."));
            }
        }
        public ActionConfirmation SaveOrUpdate(RSSFeed rSSFeed)
        {
            if (rSSFeed.IsValid())
            {
                rSSFeedRepository.SaveOrUpdate(rSSFeed);

                ActionConfirmation saveOrUpdateConfirmation = ActionConfirmation.CreateSuccessConfirmation(
                    "The rSSFeed was successfully saved.");
                saveOrUpdateConfirmation.Value = rSSFeed;

                return(saveOrUpdateConfirmation);
            }
            else
            {
                rSSFeedRepository.DbContext.RollbackTransaction();

                return(ActionConfirmation.CreateFailureConfirmation(
                           "The rSSFeed could not be saved due to missing or invalid information."));
            }
        }
Exemple #28
0
        public ActionConfirmation SaveOrUpdate(Publisher publisher)
        {
            if (publisher.IsValid())
            {
                publisherRepository.SaveOrUpdate(publisher);

                ActionConfirmation saveOrUpdateConfirmation = ActionConfirmation.CreateSuccessConfirmation(
                    "The publisher was successfully saved.");
                saveOrUpdateConfirmation.Value = publisher;

                return(saveOrUpdateConfirmation);
            }
            else
            {
                publisherRepository.DbContext.RollbackTransaction();

                return(ActionConfirmation.CreateFailureConfirmation(
                           "The publisher could not be saved due to missing or invalid information."));
            }
        }
Exemple #29
0
        public ActionConfirmation SaveOrUpdate(Application application)
        {
            if (application.IsValid())
            {
                application.SetHostsFromHostId(application.HostIds);
                _applicationRepository.SaveOrUpdate(application);

                ActionConfirmation saveOrUpdateConfirmation = ActionConfirmation.CreateSuccessConfirmation(
                    "The application was successfully saved.");
                saveOrUpdateConfirmation.Value = application;

                return(saveOrUpdateConfirmation);
            }
            else
            {
                _applicationRepository.DbContext.RollbackTransaction();

                return(ActionConfirmation.CreateFailureConfirmation(
                           "The application could not be saved due to missing or invalid information."));
            }
        }
Exemple #30
0
        public void CanCreateValidAgencyFromForm()
        {
            // Establish Context
            var agencyFromForm = new Agency();
            var testUser       = new Person();

            testUser.SetAssignedIdTo(1);
            _agencyManagementService.Expect(r => r.SaveOrUpdate(agencyFromForm))
            .Return(ActionConfirmation.CreateSuccessConfirmation("saved"));

            _authenticationProvider.Expect(r => r.GetLoggedInUser()).Return("user1");
            _personManagementService.Expect(r => r.GetByUserName("user1")).Return(testUser);
            // Act
            RedirectToRouteResult redirectResult =
                _agenciesController.Create(agencyFromForm)
                .AssertActionRedirect().ToAction("Search");

            // Assert
            _agenciesController.TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()].ToString()
            .ShouldEqual("saved");
        }