Click here to Skip to main content
15,886,720 members
Articles / Web Development / CSS

15 Steps to Develop a Product Management System in Only a Day

Rate me:
Please Sign up or sign in to vote.
4.83/5 (51 votes)
23 Mar 2010GPL34 min read 247.9K   4.8K   163  
The article introduces how to easily develop business solutions in RapidWebDev through developing a product management system with the special requirement step by step.
/****************************************************************************************************
	Copyright (C) 2010 RapidWebDev Organization (http://rapidwebdev.org)
	Author: Eunge, Legal Name: Jian Liu, Email: eunge.liu@RapidWebDev.org

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ****************************************************************************************************/

using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.IO;
using System.Linq;
using System.Text;
using System.Transactions;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Xml.Schema;
using RapidWebDev.Common;
using RapidWebDev.Common.Data;
using RapidWebDev.Common.Validation;
using RapidWebDev.Platform;
using RapidWebDev.Platform.Linq;
using RapidWebDev.UI;
using RapidWebDev.UI.Controls;
using RapidWebDev.UI.DynamicPages;
using NUnit.Framework;

namespace RapidWebDev.Tests.Platform
{
    [TestFixture]
    public class OrganizationApiTests
    {
        List<Guid> createdOrganizationIds = new List<Guid>();
        List<Guid> createdOrganizationTypeIds = new List<Guid>();

        [TearDown]
        public void TearDown()
        {
            using (MembershipDataContext ctx = DataContextFactory.Create<MembershipDataContext>())
            {
                var organizationsToDelete = ctx.Organizations.Where(org => createdOrganizationIds.ToArray().Contains(org.OrganizationId));
                var organizationTypesToDelete = ctx.OrganizationTypes.Where(orgType => createdOrganizationTypeIds.ToArray().Contains(orgType.OrganizationTypeId));

                ctx.Organizations.DeleteAllOnSubmit(organizationsToDelete);
                ctx.OrganizationTypes.DeleteAllOnSubmit(organizationTypesToDelete);
                ctx.SubmitChanges();
            }
        }

        [Test, Description("Basic organization type CRUD test.")]
        public void BasicOrganizationTypeTest()
        {
            IOrganizationApi organizationApi = SpringContext.Current.GetObject<IOrganizationApi>();

            OrganizationTypeObject department = new OrganizationTypeObject { Name = "department", Domain = "Department", Description = "department-desc" };
            organizationApi.Save(department);
            createdOrganizationTypeIds.Add(department.OrganizationTypeId);

            OrganizationTypeObject customer = new OrganizationTypeObject { Name = "customer", Domain = "Customer", Description = "customer-desc" };
            organizationApi.Save(customer);
            createdOrganizationTypeIds.Add(customer.OrganizationTypeId);

            department = organizationApi.GetOrganizationType(department.OrganizationTypeId);
            Assert.AreEqual("department", department.Name);
            Assert.AreEqual("department-desc", department.Description);

            customer = organizationApi.GetOrganizationType("customer");
            Assert.AreEqual("customer", customer.Name);
            Assert.AreEqual("customer-desc", customer.Description);

            var organizationTypes = organizationApi.FindOrganizationTypes().ToList();
            Assert.AreEqual(1, organizationTypes.Where(ct => ct.Name == "customer").Count());
            Assert.AreEqual(1, organizationTypes.Where(ct => ct.Name == "department").Count());

            department.Name = "departmentX";
            department.Description = "departmentX-desc";
            organizationApi.Save(department);

            department = organizationApi.GetOrganizationType(department.OrganizationTypeId);
            Assert.AreEqual("departmentX", department.Name);
            Assert.AreEqual("departmentX-desc", department.Description);

            Assert.IsNotNull(organizationApi.GetOrganizationType("customer"));

            organizationTypes = organizationApi.FindOrganizationTypes().ToList();
            Assert.AreEqual(1, organizationTypes.Where(ct => ct.Name == "customer").Count());
            Assert.AreEqual(1, organizationTypes.Where(ct => ct.Name == "departmentX").Count());

            customer.DeleteStatus = DeleteStatus.Deleted;
            organizationApi.Save(customer);

            organizationTypes = organizationApi.FindOrganizationTypes()
				.Where(orgType => orgType.DeleteStatus == DeleteStatus.NotDeleted).ToList();
            Assert.AreEqual(1, organizationTypes.Where(ct => ct.Name == "departmentX").Count());

            department = organizationApi.GetOrganizationType(department.OrganizationTypeId);
            Assert.AreEqual("departmentX", department.Name);
            Assert.AreEqual("departmentX-desc", department.Description);

            department.DeleteStatus = DeleteStatus.Deleted;
            organizationApi.Save(department);
        }

        [Test, Description("Basic organization CRUD test.")]
        public void BasicOrganizationTest()
        {
            IOrganizationApi organizationApi = SpringContext.Current.GetObject<IOrganizationApi>();

            OrganizationTypeObject department = new OrganizationTypeObject { Name = "department", Domain = "Department", Description = "department-desc" };
            organizationApi.Save(department);
            createdOrganizationTypeIds.Add(department.OrganizationTypeId);

            OrganizationObject shOrganization = new OrganizationObject
            {
                OrganizationCode = "sh021",
                OrganizationName = "sh-department",
                OrganizationTypeId = department.OrganizationTypeId,
                Status = OrganizationStatus.Enabled,
                Description = "sh-desc"
            };

            organizationApi.Save(shOrganization);
            createdOrganizationIds.Add(shOrganization.OrganizationId);

            OrganizationObject cdOrganization = new OrganizationObject
            {
                OrganizationCode = "cd028",
                OrganizationName = "cd-department",
                OrganizationTypeId = department.OrganizationTypeId,
                Status = OrganizationStatus.Enabled,
                Description = "cd-desc"
            };

            organizationApi.Save(cdOrganization);
            createdOrganizationIds.Add(cdOrganization.OrganizationId);

            shOrganization = organizationApi.GetOrganization(shOrganization.OrganizationId);
            Assert.AreEqual("sh021", shOrganization.OrganizationCode);
            Assert.AreEqual("sh-department", shOrganization.OrganizationName);
            Assert.IsFalse(shOrganization.ParentOrganizationId.HasValue);
            Assert.AreEqual(OrganizationStatus.Enabled, shOrganization.Status);
            Assert.AreEqual("sh-desc", shOrganization.Description);

            cdOrganization = organizationApi.GetOrganization(cdOrganization.OrganizationId);
            Assert.IsNotNull(cdOrganization);

            shOrganization.OrganizationName = "021-depart";
            shOrganization.Description = "021-desc";
            organizationApi.Save(shOrganization);

            shOrganization = organizationApi.GetOrganization(shOrganization.OrganizationId);
            Assert.AreEqual("021-depart", shOrganization.OrganizationName);
            Assert.IsFalse(shOrganization.ParentOrganizationId.HasValue);
            Assert.AreEqual(OrganizationStatus.Enabled, shOrganization.Status);
            Assert.AreEqual("021-desc", shOrganization.Description);

            shOrganization = organizationApi.GetOrganizationByName("021-depart");
            Assert.AreEqual("021-depart", shOrganization.OrganizationName);

            shOrganization = organizationApi.GetOrganizationByCode("sh021");
            Assert.AreEqual("021-depart", shOrganization.OrganizationName);
        }

        [Test, Description("Save organization test.")]
        public void SaveOrganizationTest()
        {
            IOrganizationApi organizationApi = SpringContext.Current.GetObject<IOrganizationApi>();

            OrganizationTypeObject department = new OrganizationTypeObject { Name = "department", Domain = "Department", Description = "department-desc" };
            organizationApi.Save(department);
            createdOrganizationTypeIds.Add(department.OrganizationTypeId);

            OrganizationObject shanghai = new OrganizationObject
            {
                OrganizationCode = "sh",
                OrganizationName = "sh-department",
                OrganizationTypeId = department.OrganizationTypeId,
                Status = OrganizationStatus.Enabled,
                Description = "sh-desc"
            };

            organizationApi.Save(shanghai);
            createdOrganizationIds.Add(shanghai.OrganizationId);

            shanghai = organizationApi.GetOrganization(shanghai.OrganizationId);
            shanghai.OrganizationName = "shanghai organization";
            shanghai.Description = "shanghai organization description";
            organizationApi.Save(shanghai);

            shanghai = organizationApi.GetOrganization(shanghai.OrganizationId);
            Assert.AreEqual("shanghai organization", shanghai.OrganizationName);
            Assert.AreEqual("shanghai organization description", shanghai.Description);
        }

        [Test, Description("Setting wrong child organization status on creating test.")]
        [ExpectedException(typeof(ValidationException))]
        public void WrongChildOrganizationStatusOnCreatingTest()
        {
            IOrganizationApi organizationApi = SpringContext.Current.GetObject<IOrganizationApi>();
            OrganizationTypeObject department = new OrganizationTypeObject { Name = "department", Domain = "Department", Description = "department-desc" };
            organizationApi.Save(department);
            createdOrganizationTypeIds.Add(department.OrganizationTypeId);

            OrganizationObject shOrganization = new OrganizationObject
            {
                OrganizationCode = "sh",
                OrganizationName = "sh-department",
                OrganizationTypeId = department.OrganizationTypeId,
                Status = OrganizationStatus.Disabled,
                Description = "sh-desc"
            };

            organizationApi.Save(shOrganization);
            createdOrganizationIds.Add(shOrganization.OrganizationId);

            OrganizationObject cdOrganization = new OrganizationObject
            {
                OrganizationCode = "cd",
                OrganizationName = "cd-department",
                OrganizationTypeId = department.OrganizationTypeId,
                Status = OrganizationStatus.Enabled,
                ParentOrganizationId = shOrganization.OrganizationId,
                Description = "cd-desc"
            };

            organizationApi.Save(cdOrganization);
        }

        [Test, Description("Organization status update test.")]
        public void UpdateOrganizationStatusTest()
        {
            IOrganizationApi organizationApi = SpringContext.Current.GetObject<IOrganizationApi>();

            OrganizationTypeObject department = new OrganizationTypeObject { Name = "department", Domain = "Department", Description = "department-desc" };
            organizationApi.Save(department);
            createdOrganizationTypeIds.Add(department.OrganizationTypeId);

            OrganizationObject shOrganization = new OrganizationObject
            {
                OrganizationCode = "sh",
                OrganizationName = "sh-department",
                OrganizationTypeId = department.OrganizationTypeId,
                Status = OrganizationStatus.Enabled,
                Description = "sh-desc"
            };

            organizationApi.Save(shOrganization);
            createdOrganizationIds.Add(shOrganization.OrganizationId);

            OrganizationObject cdOrganization = new OrganizationObject
            {
                OrganizationCode = "cd",
                OrganizationName = "cd-department",
                OrganizationTypeId = department.OrganizationTypeId,
                Status = OrganizationStatus.Enabled,
                ParentOrganizationId = shOrganization.OrganizationId,
                Description = "cd-desc"
            };

            organizationApi.Save(cdOrganization);
            createdOrganizationIds.Add(cdOrganization.OrganizationId);

            // update parent's status from Enabled to Disabled will affect its children
            shOrganization.Status = OrganizationStatus.Disabled;
            organizationApi.Save(shOrganization);
            shOrganization = organizationApi.GetOrganization(shOrganization.OrganizationId);
            cdOrganization = organizationApi.GetOrganization(cdOrganization.OrganizationId);
            Assert.AreEqual(OrganizationStatus.Disabled, shOrganization.Status);
            Assert.AreEqual(OrganizationStatus.Disabled, cdOrganization.Status);

            // update parent's status from Disabled to Enabled won't affect its children
            shOrganization.Status = OrganizationStatus.Enabled;
            organizationApi.Save(shOrganization);
            shOrganization = organizationApi.GetOrganization(shOrganization.OrganizationId);
            cdOrganization = organizationApi.GetOrganization(cdOrganization.OrganizationId);
            Assert.AreEqual(OrganizationStatus.Enabled, shOrganization.Status);
            Assert.AreEqual(OrganizationStatus.Disabled, cdOrganization.Status);

            cdOrganization.Status = OrganizationStatus.Enabled;
            organizationApi.Save(cdOrganization);

            // update child's status from Enabled to Disabled won't affect its parent
            cdOrganization.Status = OrganizationStatus.Disabled;
            organizationApi.Save(cdOrganization);
            shOrganization = organizationApi.GetOrganization(shOrganization.OrganizationId);
            cdOrganization = organizationApi.GetOrganization(cdOrganization.OrganizationId);
            Assert.AreEqual(OrganizationStatus.Enabled, shOrganization.Status);
            Assert.AreEqual(OrganizationStatus.Disabled, cdOrganization.Status);
        }

        [Test, Description("Add multiple organizations first, then validate the query against them.")]
        public void FindOrganizationTest()
        {
            IOrganizationApi organizationApi = SpringContext.Current.GetObject<IOrganizationApi>();

            OrganizationTypeObject department = new OrganizationTypeObject { Name = "department", Domain = "Department", Description = "department-desc" };
            organizationApi.Save(department);
            createdOrganizationTypeIds.Add(department.OrganizationTypeId);

            OrganizationObject shanghai = new OrganizationObject
            {
                OrganizationCode = "sh",
                OrganizationName = "shanghai department",
                OrganizationTypeId = department.OrganizationTypeId,
                Status = OrganizationStatus.Enabled,
                Description = "shanghai desc"
            };

            organizationApi.Save(shanghai);
            createdOrganizationIds.Add(shanghai.OrganizationId);

            OrganizationObject chengdu = new OrganizationObject
            {
                OrganizationCode = "cd",
                OrganizationName = "chengdu department",
                OrganizationTypeId = department.OrganizationTypeId,
                Status = OrganizationStatus.Enabled,
                Description = "chengdu desc"
            };

            organizationApi.Save(chengdu);
            createdOrganizationIds.Add(chengdu.OrganizationId);

            int recordCount;
            LinqPredicate linqPredicate = new LinqPredicate("OrganizationName.EndsWith(@0) And Status=@1", "department", OrganizationStatus.Enabled);
            IEnumerable<OrganizationObject> organizations = organizationApi.FindOrganizations(linqPredicate, null, 0, 10, out recordCount);
            Assert.AreEqual(2, recordCount);
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
President TCWH
China China
I've worked as a software architect and developer based on Microsoft .NET framework and web technology since 2002, having rich experience on SaaS, multiple-tier web system and website development. I've devoted into open source project development since 2003, and have created 3 main projects including DataQuicker (ORM), ExcelQuicker (Excel Report Generator), and RapidWebDev (Enterprise-level CMS)

I worked in BenQ (8 mo), Bleum (4 mo), Newegg (1 mo), Microsoft (3 yr) and Autodesk (5 yr) before 2012. Now I own a startup company in Shanghai China to deliver the exceptional results to global internet users by leveraging the power of Internet and the local excellence.

Comments and Discussions