Example #1
54
        public void generateReport(Client client)
        {
            string fileNameWithDate = "PlanOfCare(" + client.ClientID + client.FirstName + " " +
                client.LastName + ") " + DateTime.Now.Month + "." + DateTime.Now.Day +
                "." + DateTime.Now.Year + " " + DateTime.Now.Hour + "." + DateTime.Now.Minute +
                "." + DateTime.Now.Second;
            this.filePath = @"C:\MyClients\WordReports\" + fileNameWithDate + ".docx";
            string xmlStylePath = @"C:\MyClients\References\styles.xml";
            this.contentType = "application/msword";
            this.fileName = client.LastName + "_" + client.FirstName + "_PlanOfCare.docx";

            #region create document part
            // todo: make filename unique
            WordprocessingDocument document = WordprocessingDocument.Create(
                this.filePath,
                WordprocessingDocumentType.Document
            );

            // create "document" part
            MainDocumentPart mainDocumentPart = document.AddMainDocumentPart();
            mainDocumentPart.Document = new Document();
            // create body of the document
            Body documentBody = new Body();
            mainDocumentPart.Document.Append(documentBody);
            #endregion

            #region create style part
            // create "style" part
            StyleDefinitionsPart styleDefinitionsPart =
                mainDocumentPart.AddNewPart<StyleDefinitionsPart>();
            // open style xml

            // todo: reference this xml locally somehow
            FileStream stylesTemplate =
                new FileStream(xmlStylePath, FileMode.Open, FileAccess.Read);
            styleDefinitionsPart.FeedData(stylesTemplate);
            styleDefinitionsPart.Styles.Save();
            #endregion

            #region create title
            // create paragraph for title
            Paragraph titleParagraphe = new Paragraph();
            // create paragraph properties
            ParagraphProperties titleProperties = new ParagraphProperties();

            // todo: figure out more styles and how these styles work
            // make the paragraph a "title"
            titleProperties.ParagraphStyleId = new ParagraphStyleId { Val = "Title" };

            // apply the style properties to the paragraph
            titleParagraphe.Append(titleProperties);

            // create RUN, append TEXT to RUN, append RUN to PARAGRAPH
            Run titleRun = new Run();
            Text titleText = new Text("Plan of Care for " + client.FirstName + " " + client.LastName);
            titleRun.Append(titleText);
            titleParagraphe.Append(titleRun);

            // append PARAGRAPH to BODY
            documentBody.Append(titleParagraphe);
            #endregion

            #region create first heading (Client Details)
            // add client name
            Paragraph clientDetailsHeadingParagraph = new Paragraph();

            // create styling
            ParagraphProperties clientDetailsHeadingProperties = new ParagraphProperties();
            clientDetailsHeadingProperties.ParagraphStyleId = new ParagraphStyleId { Val = "Heading1" };
            clientDetailsHeadingParagraph.Append(clientDetailsHeadingProperties);

            // create run/text of client info
            Run clientDetailsHeadingRun = new Run();
            Text clientDetailsHeadingText = new Text("Contact Information");

            // append text to document
            clientDetailsHeadingRun.Append(clientDetailsHeadingText);
            clientDetailsHeadingParagraph.Append(clientDetailsHeadingRun);
            documentBody.Append(clientDetailsHeadingParagraph);
            #endregion

            // create details table
            Table addressTable = new Table();

            #region address label
            // create row/cell for address label
            TableRow addressLabelRow = new TableRow();
            TableCell addressLabelCell = new TableCell();
            Paragraph addressLabelPgh = new Paragraph();

            // create paragraph properties
            addressLabelPgh.Append(new ParagraphProperties
            {
                SpacingBetweenLines = new SpacingBetweenLines { After = "0" }
            });

            // create run properties
            RunProperties addressLabelRunProperties = new RunProperties();
            addressLabelRunProperties.Append(new Bold());
            // create label text to append to cell
            Run addressLabelRun = new Run();
            addressLabelRun.Append(addressLabelRunProperties);
            Text addressLabelText = new Text("Address: ");
            addressLabelRun.Append(addressLabelText);
            addressLabelPgh.Append(addressLabelRun);

            addressLabelCell.Append(addressLabelPgh);
            // add cell to row
            addressLabelRow.Append(addressLabelCell);
            #endregion

            #region address row 1
            // create row/cell for address label
            TableRow address1ValueRow = new TableRow();
            TableCell address1ValueCell = new TableCell();
            Paragraph address1ValuePgh = new Paragraph();

            // create paragraph properties
            address1ValuePgh.Append(new ParagraphProperties
            {
                SpacingBetweenLines = new SpacingBetweenLines { After = "0" }
            });

            // create label text to append to cell
            Run address1ValueRun = new Run();
            Text address1ValueText = new Text(client.Address.Address1 + " " + client.Address.Address2);
            address1ValueRun.Append(address1ValueText);
            address1ValuePgh.Append(address1ValueRun);
            address1ValueCell.Append(address1ValuePgh);
            // add cell to row
            address1ValueRow.Append(address1ValueCell);
            #endregion

            #region city row
            // create row/cell for address label
            TableRow cityValueRow = new TableRow();
            TableCell cityValueCell = new TableCell();
            Paragraph cityValuePgh = new Paragraph();

            // create paragraph properties
            cityValuePgh.Append(new ParagraphProperties
            {
                SpacingBetweenLines = new SpacingBetweenLines { After = "0" }
            });

            // create label text to append to cell
            Run cityValueRun = new Run();
            Text cityValueText = new Text(client.Address.City);
            cityValueRun.Append(cityValueText);
            cityValuePgh.Append(cityValueRun);
            cityValueCell.Append(cityValuePgh);
            // add cell to row
            cityValueRow.Append(cityValueCell);
            #endregion

            #region state row
            // create row/cell for address label
            TableRow stateValueRow = new TableRow();
            TableCell stateValueCell = new TableCell();
            Paragraph stateValuePgh = new Paragraph();

            // create paragraph properties
            stateValuePgh.Append(new ParagraphProperties
            {
                SpacingBetweenLines = new SpacingBetweenLines { After = "0" }
            });

            // create label text to append to cell
            Run stateValueRun = new Run();
            Text stateValueText = new Text(client.Address.State);
            stateValueRun.Append(stateValueText);
            stateValuePgh.Append(stateValueRun);
            stateValueCell.Append(stateValuePgh);
            // add cell to row
            stateValueRow.Append(stateValueCell);
            #endregion

            #region zip row
            // create row/cell for address label
            TableRow zipValueRow = new TableRow();
            TableCell zipValueCell = new TableCell();
            Paragraph zipValuePgh = new Paragraph();

            // create paragraph properties
            zipValuePgh.Append(new ParagraphProperties
            {
                SpacingBetweenLines = new SpacingBetweenLines { After = "0" }
            });

            // create label text to append to cell
            Run zipValueRun = new Run();
            Text zipValueText = new Text(client.Address.Zip);
            zipValueRun.Append(zipValueText);
            zipValuePgh.Append(zipValueRun);
            zipValueCell.Append(zipValuePgh);
            // add cell to row
            zipValueRow.Append(zipValueCell);
            #endregion

            #region write address table to doc
            addressTable.Append(
                addressLabelRow,
                address1ValueRow,
                cityValueRow,
                stateValueRow,
                zipValueRow
            );

            // append table to doc body
            documentBody.Append(addressTable);
            #endregion

            #region create second heading (Client Details)
            // add client name
            Paragraph spacerParagraph = new Paragraph();
            // create paragraph properties
            spacerParagraph.Append(new ParagraphProperties
            {
                SpacingBetweenLines = new SpacingBetweenLines { After = "0" }
            });

            Run spacerRun = new Run();

            // append text to document
            documentBody.Append(spacerParagraph);
            #endregion

            Table contactInfoTable = new Table();

            // create first row of details (2 properties)
            TableRow firstDetailRow = new TableRow();

            #region email label and value
            // email label in first row of details
            TableCell emailLabelCell = new TableCell();
            Paragraph emailLabelPgh = new Paragraph();

            // create paragraph properties
            emailLabelPgh.Append(new ParagraphProperties
            {
                SpacingBetweenLines = new SpacingBetweenLines { After = "0" }
            });

            // create email label run properties
            RunProperties emailLabelRunProperties = new RunProperties();
            emailLabelRunProperties.Append(new Bold());

            Run emailLabelRun = new Run();
            emailLabelRun.Append(emailLabelRunProperties);
            Text emailLabelText = new Text("Email:");
            emailLabelRun.Append(emailLabelText);
            emailLabelPgh.Append(emailLabelRun);
            emailLabelCell.Append(emailLabelPgh);

            // create cell for email value
            TableCell emailValueCell = new TableCell();
            Paragraph emailValuePgh = new Paragraph();

            // create paragraph properties
            emailValuePgh.Append(new ParagraphProperties
            {
                SpacingBetweenLines = new SpacingBetweenLines { After = "0" }
            });

            // create value run
            Run emailValueRun = new Run();
            Text emailValueText = new Text(client.Email);
            emailValueRun.Append(emailValueText);
            emailValuePgh.Append(emailValueRun);
            emailValueCell.Append(emailValuePgh);
            #endregion

            #region home phone label and value
            // email label in first row of details
            TableCell homePhoneLabelCell = new TableCell();
            Paragraph homePhoneLabelPgh = new Paragraph();

            // create paragraph properties
            homePhoneLabelPgh.Append(new ParagraphProperties
            {
                SpacingBetweenLines = new SpacingBetweenLines { After = "0" }
            });

            // create email label run properties
            RunProperties homePhoneLabelRunProperties = new RunProperties();
            homePhoneLabelRunProperties.Append(new Bold());

            Run homePhoneLabelRun = new Run();
            homePhoneLabelRun.Append(homePhoneLabelRunProperties);
            Text homePhoneLabelText = new Text("Home Phone: ");
            homePhoneLabelRun.Append(homePhoneLabelText);
            homePhoneLabelPgh.Append(homePhoneLabelRun);
            homePhoneLabelCell.Append(homePhoneLabelPgh);

            // create cell for email value
            TableCell homePhoneValueCell = new TableCell();
            Paragraph homePhoneValuePgh = new Paragraph();

            // create paragraph properties
            homePhoneValuePgh.Append(new ParagraphProperties
            {
                SpacingBetweenLines = new SpacingBetweenLines { After = "0" }
            });

            // create value run
            Run homePhoneValueRun = new Run();
            Text homePhoneValueText = new Text(client.HomePhoneNumber);
            homePhoneValueRun.Append(homePhoneValueText);
            homePhoneValuePgh.Append(homePhoneValueRun);
            homePhoneValueCell.Append(homePhoneValuePgh);

            // add cells to row
            firstDetailRow.Append(emailLabelCell, emailValueCell, homePhoneLabelCell, homePhoneValueCell);
            #endregion

            // create second row of details (2 properties)
            TableRow secondDetailRow = new TableRow();

            #region cellphone label and value
            // cellPhone label in first row of details
            TableCell cellPhoneLabelCell = new TableCell();
            Paragraph cellPhoneLabelPgh = new Paragraph();

            // create paragraph properties
            cellPhoneLabelPgh.Append(new ParagraphProperties
            {
                SpacingBetweenLines = new SpacingBetweenLines { After = "0" }
            });

            // create cellPhone label run properties
            RunProperties cellPhoneLabelRunProperties = new RunProperties();
            cellPhoneLabelRunProperties.Append(new Bold());

            Run cellPhoneLabelRun = new Run();
            cellPhoneLabelRun.Append(cellPhoneLabelRunProperties);
            Text cellPhoneLabelText = new Text("Cell Phone:");
            cellPhoneLabelRun.Append(cellPhoneLabelText);
            cellPhoneLabelPgh.Append(cellPhoneLabelRun);
            cellPhoneLabelCell.Append(cellPhoneLabelPgh);

            // create cell for cellPhone value
            TableCell cellPhoneValueCell = new TableCell();
            Paragraph cellPhoneValuePgh = new Paragraph();

            // create paragraph properties
            cellPhoneValuePgh.Append(new ParagraphProperties
            {
                SpacingBetweenLines = new SpacingBetweenLines { After = "0" }
            });

            // create value run
            Run cellPhoneValueRun = new Run();
            Text cellPhoneValueText = new Text(client.CellPhoneNumber);
            cellPhoneValueRun.Append(cellPhoneValueText);
            cellPhoneValuePgh.Append(cellPhoneValueRun);
            cellPhoneValueCell.Append(cellPhoneValuePgh);
            #endregion

            #region work phone label and value
            // email label in first row of details
            TableCell workPhoneLabelCell = new TableCell();
            Paragraph workPhoneLabelPgh = new Paragraph();

            // create paragraph properties
            workPhoneLabelPgh.Append(new ParagraphProperties
            {
                SpacingBetweenLines = new SpacingBetweenLines { After = "0" }
            });

            // create email label run properties
            RunProperties workPhoneLabelRunProperties = new RunProperties();
            workPhoneLabelRunProperties.Append(new Bold());

            Run workPhoneLabelRun = new Run();
            workPhoneLabelRun.Append(workPhoneLabelRunProperties);
            Text workPhoneLabelText = new Text("Work Phone: ");
            workPhoneLabelRun.Append(workPhoneLabelText);
            workPhoneLabelPgh.Append(workPhoneLabelRun);
            workPhoneLabelCell.Append(workPhoneLabelPgh);

            // create cell for email value
            TableCell workPhoneValueCell = new TableCell();
            Paragraph workPhoneValuePgh = new Paragraph();

            // create paragraph properties
            workPhoneValuePgh.Append(new ParagraphProperties
            {
                SpacingBetweenLines = new SpacingBetweenLines { After = "0" }
            });

            // create value run
            Run workPhoneValueRun = new Run();
            Text workPhoneValueText = new Text(client.WorkPhoneNumber);
            workPhoneValueRun.Append(workPhoneValueText);
            workPhoneValuePgh.Append(workPhoneValueRun);
            workPhoneValueCell.Append(workPhoneValuePgh);

            // add cells to row
            secondDetailRow.Append(cellPhoneLabelCell, cellPhoneValueCell, workPhoneLabelCell, workPhoneValueCell);
            #endregion

            #region write contact information table to doc
            contactInfoTable.Append(
                firstDetailRow,
                secondDetailRow);

            // append table to doc body
            documentBody.Append(contactInfoTable);
            #endregion

            #region create second heading (Demographics)
            // add client name
            Paragraph demographicsHeadingParagraph = new Paragraph();

            // create styling
            ParagraphProperties demographicsHeadingProperties = new ParagraphProperties();
            demographicsHeadingProperties.ParagraphStyleId = new ParagraphStyleId { Val = "Heading1" };
            demographicsHeadingParagraph.Append(demographicsHeadingProperties);

            // create run/text of client info
            Run demographicsHeadingRun = new Run();
            Text demographicsHeadingText = new Text("Demographics");

            // append text to document
            demographicsHeadingRun.Append(demographicsHeadingText);
            demographicsHeadingParagraph.Append(demographicsHeadingRun);
            documentBody.Append(demographicsHeadingParagraph);
            #endregion

            // create demographics table
            Table demographicsTable = new Table();

            // create first row of demographic info (2 properties)
            TableRow firstDemoRow = new TableRow();

            #region ss label and value
            // ss label in first row of details
            TableCell SsLabelCell = new TableCell();
            Paragraph SsLabelPgh = new Paragraph();

            // create paragraph properties
            SsLabelPgh.Append(new ParagraphProperties
            {
                SpacingBetweenLines = new SpacingBetweenLines { After = "0" }
            });

            // create Ss label run properties
            RunProperties SsLabelRunProperties = new RunProperties();
            SsLabelRunProperties.Append(new Bold());

            Run SsLabelRun = new Run();
            SsLabelRun.Append(SsLabelRunProperties);
            Text SsLabelText = new Text("Social Security Number:");
            SsLabelRun.Append(SsLabelText);
            SsLabelPgh.Append(SsLabelRun);
            SsLabelCell.Append(SsLabelPgh);

            // create cell for Ss value
            TableCell SsValueCell = new TableCell();
            Paragraph SsValuePgh = new Paragraph();

            // create paragraph properties
            SsValuePgh.Append(new ParagraphProperties
            {
                SpacingBetweenLines = new SpacingBetweenLines { After = "0" }
            });
            // create value run
            Run SsValueRun = new Run();
            Text SsValueText = new Text(client.SocialNum);
            SsValueRun.Append(SsValueText);
            SsValuePgh.Append(SsValueRun);
            SsValueCell.Append(SsValuePgh);
            #endregion

            #region date of birth label and value
            // email label in first row of details
            TableCell DobLabelCell = new TableCell();
            Paragraph DobLabelPgh = new Paragraph();

            // create paragraph properties
            DobLabelPgh.Append(new ParagraphProperties
            {
                SpacingBetweenLines = new SpacingBetweenLines { After = "0" }
            });

            // create email label run properties
            RunProperties DobLabelRunProperties = new RunProperties();
            DobLabelRunProperties.Append(new Bold());

            Run DobLabelRun = new Run();
            DobLabelRun.Append(DobLabelRunProperties);
            Text DobLabelText = new Text("Date of Birth: ");
            DobLabelRun.Append(DobLabelText);
            DobLabelPgh.Append(DobLabelRun);
            DobLabelCell.Append(DobLabelPgh);

            // create cell for email value
            TableCell DobValueCell = new TableCell();
            Paragraph DobValuePgh = new Paragraph();

            // create paragraph properties
            DobValuePgh.Append(new ParagraphProperties
            {
                SpacingBetweenLines = new SpacingBetweenLines { After = "0" }
            });

            // create value run
            Run DobValueRun = new Run();
            Text DobValueText = new Text();
            if (client.DateOfBirth != null)
                DobValueText.Text = Convert.ToString(client.DateOfBirth.Value.ToShortDateString());
            else
                DobValueText.Text = Convert.ToString(client.DateOfBirth);
            DobValueRun.Append(DobValueText);
            DobValuePgh.Append(DobValueRun);
            DobValueCell.Append(DobValuePgh);

            // add cells to row
            firstDemoRow.Append(SsLabelCell, SsValueCell, DobLabelCell, DobValueCell);
            #endregion

            // create second row of demographic info (2 properties)
            TableRow secondDemoRow = new TableRow();

            #region gender label and value
            // gender label in first row of details
            TableCell genderLabelCell = new TableCell();
            Paragraph genderLabelPgh = new Paragraph();

            // create paragraph properties
            genderLabelPgh.Append(new ParagraphProperties
            {
                SpacingBetweenLines = new SpacingBetweenLines { After = "0" }
            });

            // create gender label run properties
            RunProperties genderLabelRunProperties = new RunProperties();
            genderLabelRunProperties.Append(new Bold());

            Run genderLabelRun = new Run();
            genderLabelRun.Append(genderLabelRunProperties);
            Text genderLabelText = new Text("Gender:");
            genderLabelRun.Append(genderLabelText);
            genderLabelPgh.Append(genderLabelRun);
            genderLabelCell.Append(genderLabelPgh);

            // create cell for gender value
            TableCell genderValueCell = new TableCell();
            Paragraph genderValuePgh = new Paragraph();

            // create paragraph properties
            genderValuePgh.Append(new ParagraphProperties
            {
                SpacingBetweenLines = new SpacingBetweenLines { After = "0" }
            });

            // create value run
            Run genderValueRun = new Run();
            Text genderValueText = new Text(client.Gender.GenderName);
            genderValueRun.Append(genderValueText);
            genderValuePgh.Append(genderValueRun);
            genderValueCell.Append(genderValuePgh);
            #endregion

            #region age label and value
            // email label in first row of details
            TableCell ageLabelCell = new TableCell();
            Paragraph ageLabelPgh = new Paragraph();

            // create paragraph properties
            ageLabelPgh.Append(new ParagraphProperties
            {
                SpacingBetweenLines = new SpacingBetweenLines { After = "0" }
            });

            // create email label run properties
            RunProperties ageLabelRunProperties = new RunProperties();
            ageLabelRunProperties.Append(new Bold());

            Run ageLabelRun = new Run();
            ageLabelRun.Append(ageLabelRunProperties);
            Text ageLabelText = new Text("Age: ");
            ageLabelRun.Append(ageLabelText);
            ageLabelPgh.Append(ageLabelRun);
            ageLabelCell.Append(ageLabelPgh);

            // create cell for email value
            TableCell ageValueCell = new TableCell();
            Paragraph ageValuePgh = new Paragraph();

            // create paragraph properties
            ageValuePgh.Append(new ParagraphProperties
            {
                SpacingBetweenLines = new SpacingBetweenLines { After = "0" }
            });

            // create value run
            Run ageValueRun = new Run();
            Text ageValueText = new Text();
            int age = new Utility().getAge(client.DateOfBirth);
            if (age != 0)
                ageValueText.Text = Convert.ToString(age);
            else
                ageValueText.Text = null;
            ageValueRun.Append(ageValueText);
            ageValuePgh.Append(ageValueRun);
            ageValueCell.Append(ageValuePgh);

            // add cells to row
            secondDemoRow.Append(genderLabelCell, genderValueCell, ageLabelCell, ageValueCell);
            #endregion

            // create 3rd row of demographic info (1 property)
            TableRow thirdDemoRow = new TableRow();

            #region marital status label and value
            // email label in first row of details
            TableCell maritalStatusLabelCell = new TableCell();

            // create email label run properties
            RunProperties maritalStatusLabelRunProperties = new RunProperties();
            maritalStatusLabelRunProperties.Append(new Bold());

            Run maritalStatusLabelRun = new Run();
            maritalStatusLabelRun.Append(maritalStatusLabelRunProperties);
            Text maritalStatusLabelText = new Text("Marital Status:");
            maritalStatusLabelRun.Append(maritalStatusLabelText);
            maritalStatusLabelCell.Append(new Paragraph(maritalStatusLabelRun));

            // create cell for email value
            TableCell maritalStatusValueCell = new TableCell();
            // create value run
            Run maritalStatusValueRun = new Run();
            Text maritalStatusValueText = new Text(client.MaritalStatus.MaritalStatusName);
            maritalStatusValueRun.Append(maritalStatusValueText);
            maritalStatusValueCell.Append(new Paragraph(maritalStatusValueRun));

            // add cells to row
            thirdDemoRow.Append(maritalStatusLabelCell, maritalStatusValueCell);
            #endregion

            #region write demographics table to doc
            demographicsTable.Append(firstDemoRow, secondDemoRow, thirdDemoRow);

            // append table to doc body
            documentBody.Append(demographicsTable);
            #endregion

            #region insert background html

            // create temp html file to insert
            string fullHtml = "<html><body>" + client.Background + "</body></html>";

            StreamWriter sw = File.CreateText(@"C:\MyClients\References\tmp.html");
            sw.WriteLine(fullHtml);
            sw.Close();

            // create alt chunk that is inserted into document
            string altChunkId = "MyAltChunkId";
            AlternativeFormatImportPart chunk =
                mainDocumentPart.AddAlternativeFormatImportPart(
                AlternativeFormatImportPartType.Html,
                altChunkId);
            chunk.FeedData(File.Open(@"C:\MyClients\References\tmp.html", FileMode.Open));
            AltChunk altChunk = new AltChunk();
            altChunk.Id = altChunkId;
            mainDocumentPart.Document.Append(altChunk);

            #endregion

            // save doc and release
            document.MainDocumentPart.Document.Save();
            document.Dispose();
        }
        public void Client_Lists_Include_Correct_Page_Numbers()
        {
            // ARRANGE: if there are 5 clients in the repository...
            // create fake clients to insert to fake db
            Client[] clients = new Client[]
            {
                new Client { FirstName = "FName1" },
                new Client { FirstName = "FName2" },
                new Client { FirstName = "FName3" },
                new Client { FirstName = "FName4" },
                new Client { FirstName = "FName5" }
            };
            // mock db and have it return the fake records
            var mockRepository = new Mock<IClientRepository>();
            mockRepository.Setup(x => x.GetClientsForUser("BenR")).Returns(clients.AsQueryable());
            // make db return fake user
            mockRepository.Setup(x => x.GetUser("BenR")).Returns(new User { UserName = "******" });
            var controller = new ClientsController(mockRepository.Object, UnitTestHelpers.CreateMockLoggedInUser("BenR")) { PageSize = 3 };

            // ACT: ... and the user asks for the second page...
            var result = controller.List(2);

            // ASSERT: they see page links matching the following??
            var viewModel = (ClientsListViewModel)result.ViewData.Model;
            PagingInfo pagingInfo = viewModel.PagingInfo;
            pagingInfo.CurrentPage.ShouldEqual(2);
            pagingInfo.ItemsPerPage.ShouldEqual(3);
            pagingInfo.TotalItems.ShouldEqual(5);
            pagingInfo.TotalPages.ShouldEqual(2);
        }
Example #3
0
        public void Can_View_A_Single_Page_Of_Clients()
        {
            // ARRANGE: if user is logged in and there are 5 clients in the repository...
            // create fake clients to insert to fake db
            Client[] clients = new Client[]
            {
                new Client { FirstName = "FName1" },
                new Client { FirstName = "FName2" },
                new Client { FirstName = "FName3" },
                new Client { FirstName = "FName4" },
                new Client { FirstName = "FName5" }
            };

            // mock db and have it return the fake records
            var repository = new Mock<IClientRepository>();
            repository.Setup(x => x.GetClientsForUser("TeamFortress2User")).Returns(clients.AsQueryable());
            // make db return fake user
            repository.Setup(x => x.GetUser("TeamFortress2User")).Returns(new User { UserName = "******" });

            // create controller
            var controller = new ClientsController(repository.Object, UnitTestHelpers.CreateMockLoggedInUser("TeamFortress2User"));
            controller.PageSize = 3;

            // ACT: and the user asks for the second page...
            var result = controller.List(2);

            // ASSERT: ...the user sees the last two clients
            var viewModel = (ClientsListViewModel)result.ViewData.Model;
            var displayedClients = viewModel.Clients;
            displayedClients.Count.ShouldEqual(2);
            displayedClients[0].FirstName.ShouldEqual("FName4");
            displayedClients[1].FirstName.ShouldEqual("FName5");
        }
Example #4
0
		private void detach_Clients(Client entity)
		{
			this.SendPropertyChanging();
			entity.MaritalStatus = null;
		}
Example #5
0
 partial void DeleteClient(Client instance);
Example #6
0
 partial void UpdateClient(Client instance);
Example #7
0
 partial void InsertClient(Client instance);
Example #8
0
		private void detach_Clients(Client entity)
		{
			this.SendPropertyChanging();
			entity.Gender = null;
		}
Example #9
0
		private void attach_Clients(Client entity)
		{
			this.SendPropertyChanging();
			entity.Gender = this;
		}
Example #10
0
		private void detach_Clients(Client entity)
		{
			this.SendPropertyChanging();
			entity.LivingWill = null;
		}
Example #11
0
		private void attach_Clients(Client entity)
		{
			this.SendPropertyChanging();
			entity.LivingWill = this;
		}
Example #12
0
		private void detach_Clients(Client entity)
		{
			this.SendPropertyChanging();
			entity.FuneralHome = null;
		}
Example #13
0
		private void attach_Clients(Client entity)
		{
			this.SendPropertyChanging();
			entity.Cemetery = this;
		}
Example #14
0
		private void detach_Clients(Client entity)
		{
			this.SendPropertyChanging();
			entity.LivingEnvironmentType = null;
		}
        public void SaveClient(Client client)
        {
            // if its a new client, insert it
            if (client.ClientID == 0)
            {
                client.FuneralHomeId = 1;
                client.CemeteryId = 1;
                _db.Clients.InsertOnSubmit(client);
            }
            else if (_db.Clients.GetOriginalEntityState(client) == null)
            {
                // we are updating an existing client, but it's not attached
                // to the data context, so attach it and detect changes

                // todo: address logic should go in SaveAddress() function
                _db.Addresses.Attach(client.Address);
                _db.Clients.Attach(client);
                _db.Clients.Context.Refresh(RefreshMode.KeepCurrentValues, client);
                _db.Addresses.Context.Refresh(RefreshMode.KeepCurrentValues, client.Address);
            }

            _db.SubmitChanges();
        }
 public void DeleteClient(Client client)
 {
     _db.Addresses.DeleteOnSubmit(client.Address);
     _db.KeyContacts.DeleteAllOnSubmit(client.KeyContacts);
     if (client.FuneralHomeId != 1)
         _db.FuneralHomes.DeleteOnSubmit(client.FuneralHome);
     if (client.CemeteryId != 1)
         _db.Cemeteries.DeleteOnSubmit(client.Cemetery);
     _db.Clients.DeleteOnSubmit(client);
     _db.Clients.Context.SubmitChanges();
 }