Example #1
0
        public void AddNewMember()
        {
            MemberDE mod = new MemberDE();

            // Entity Fields
            mod.SiteCode = "QST";
            mod.EntityTypeCode = "MGR";
            mod.EntityName = "Kamran Ahmad";

            // Person Fields
            mod.MeritalStatusId = 3;
            mod.DOB = DateTime.Now;
            mod.Age = 45;
            mod.Picture = "abc.jpb";
            mod.Gender = "M";
            mod.Signature = "ImranKhan#123";
            mod.ThumbImpression = "ThumbImpressionPicPath";
            mod.NationalId = "34201-8888377-2";

            // Form Fields
            mod.FormNo = "FRM-001";
            mod.FormType = "GKT";
            mod.FatherOrHusbandName = "Jameel Ahmad";
            mod.MedicalProblemId = 10;
            mod.MemberStatusId = 10;
            mod.OccupationId = 10;
            mod.HouseStatus = "P";
            mod.ZakatAcceptable = true;
            mod.FamilySize = 10;
            mod.Salary = 3000;
            mod.Donations = 2000;
            mod.OtherIncome = 5000;
            mod.ShortFallInCash = 8000;
            mod.Remarks = "Test Remarks";
            mod.IsDeserving = true;
            mod.ReferredBy = 20;
            mod.DataCollectedBy = 10;
            mod.DataCollectedBySignatures = "Test Signs";
            mod.ApprovalByDataCollectedPerson = true;
            mod.AuthorizedBy = 9;
            mod.ApprovalByDataAuthorizedPerson = true;

            // Member Fields
            mod.RegDate = DateTime.Now;
            mod.RegNo = "REG-001";
            mod.DistributionPointId = 5;
            mod.FamilyPackageId = 4;

            IGroceryKit grocSvc = new GroceryKitService();
            decimal memberId = grocSvc.AddMember(mod);
            if (memberId > decimal.Zero)
            {
                Assert.AreNotEqual(memberId, decimal.Zero);
            }
        }
        public int AddMember(MemberDE mod)
        {
            int Id = 0;
            SqlConnection con = new SqlConnection(DBHelper.ConnectionString);
            StringBuilder sb = new StringBuilder();
            bool entityAddFlag = false;
            using (TransactionScope trans = new TransactionScope())
            {
                _bdmSvc = new BDMService();
                Person p = mod.ToPerson();
                Id = _bdmSvc.AddPerson(p);

                #region Commented Code

                //#region Add Entity

                //SqlCommand cmd = new SqlCommand();

                //#region CommandText & Params

                //sb.Append("INSERT INTO [dbo].[Entity]");
                //sb.Append("([SiteCode]");
                //sb.Append(",[EntityTypeCode]");

                ////sb.Append(",[ParentEntityID]");
                //sb.Append(",[EntityName]");
                //sb.Append(",[IsActive])");
                //sb.Append("VALUES");
                //sb.Append("(@SiteCode");
                //sb.Append(",@EntityTypeCode");
                ////sb.Append(",@ParentEntityID");
                //sb.Append(",@EntityName");
                //sb.Append(",@IsActive)");
                //sb.Append("Select @@IDENTITY");
                ////sb.Append("GO");

                //cmd.Parameters.AddWithValue("@SiteCode", mod.SiteCode);
                //cmd.Parameters.AddWithValue("@EntityTypeCode", mod.EntityTypeCode);
                ////cmd.Parameters.AddWithValue("@ParentEntityID", mod.Person.ParentEntityID);
                //cmd.Parameters.AddWithValue("@EntityName", mod.EntityName);
                //cmd.Parameters.AddWithValue("@IsActive", mod.IsActive);

                //#endregion

                //cmd.Connection = con;
                //cmd.CommandText = sb.ToString();
                //con.Open();

                //try
                //{
                //    decimal val = decimal.Zero;
                //    object retVal = cmd.ExecuteScalar();
                //    if (retVal != null)
                //    {
                //        val = (decimal)retVal;
                //        Id = Convert.ToInt32(val);
                //    }
                //}
                //catch (Exception ex)
                //{

                //}
                //#endregion

                //#region Add Person

                //cmd = new SqlCommand();

                //#region CommandText & Params

                //sb = new StringBuilder();

                //sb.Append("INSERT INTO [dbo].[Person]");
                //   sb.Append("([SiteCode]");
                //   sb.Append(",[EntityTypeCode]");
                //   sb.Append(",[PersonId]");
                //   sb.Append(",[ParentId]");
                //   sb.Append(",[ParentRelationId]");
                //   sb.Append(",[MeritalStatusId]");
                //   //sb.Append(",[Occupation]");
                //   sb.Append(",[DOB]");
                //   sb.Append(",[Age]");
                //   sb.Append(",[Picture]");
                //   sb.Append(",[Gender]");
                //   sb.Append(",[Signature]");
                //   sb.Append(",[ThumbImpression]");
                //   sb.Append(",[NationalId])");
                //sb.Append("VALUES");
                //    sb.Append("(@SiteCode");
                //    sb.Append(",@EntityTypeCode");
                //    sb.Append(",@PersonId");
                //    sb.Append(",@ParentId");
                //    sb.Append(",@ParentRelationId");
                //    sb.Append(",@MeritalStatusId");
                //    //sb.Append(",@Occupation");
                //    sb.Append(",@DOB");
                //    sb.Append(",@Age");
                //    sb.Append(",@Picture");
                //    sb.Append(",@Gender");
                //    sb.Append(",@Signature");
                //    sb.Append(",@ThumbImpression");
                //    sb.Append(",@NationalId)");
                //   //sb.Append("GO");

                //   cmd.Parameters.AddWithValue("@SiteCode", mod.SiteCode);
                //   cmd.Parameters.AddWithValue("@EntityTypeCode", mod.EntityTypeCode);
                //   cmd.Parameters.AddWithValue("@PersonId", Id);
                //   cmd.Parameters.AddWithValue("@ParentId", mod.ParentId);
                //   cmd.Parameters.AddWithValue("@ParentRelationId", mod.ParentRelationId);
                //   cmd.Parameters.AddWithValue("@MeritalStatusID", mod.MeritalStatuId);
                //   //cmd.Parameters.AddWithValue("@Occupation", mod.Occupation);
                //   cmd.Parameters.AddWithValue("@DOB", mod.DOB);
                //   cmd.Parameters.AddWithValue("@Age", mod.Age);
                //   cmd.Parameters.AddWithValue("@Picture", mod.Picture);
                //   cmd.Parameters.AddWithValue("@Gender", mod.Gender);
                //   cmd.Parameters.AddWithValue("@Signature", mod.Signature);
                //   cmd.Parameters.AddWithValue("@ThumbImpression", mod.ThumbImpression);
                //   cmd.Parameters.AddWithValue("@NationalId", mod.NationalId);

                //#endregion

                //cmd.CommandText = sb.ToString();
                //cmd.Connection = con;
                //try
                //{
                //    cmd.ExecuteNonQuery();
                //}
                //catch (Exception ex)
                //{

                //}
                //#endregion

                #endregion

                #region Add Form

                SqlCommand cmd = new SqlCommand();

                #region CommandText & Params

                sb = new StringBuilder();

                    sb.Append("INSERT INTO [dbo].[Form]");
                            sb.Append("([SiteCode]");
                            sb.Append(",[EntityTypeCode]");
                            sb.Append(",[FormId]");

                            sb.Append(",[FormNo]");
                           sb.Append(",[FormType]");
                           sb.Append(",[FatherOrHusbandName]");
                           sb.Append(",[MedicalProblemId]");
                           sb.Append(",[MemberStatusId]");
                           sb.Append(",[OccupationId]");
                           sb.Append(",[HouseStatus]");
                           sb.Append(",[ZakatAcceptable]");
                           sb.Append(",[FamilySize]");
                           sb.Append(",[Salary]");
                           sb.Append(",[Donations]");
                           sb.Append(",[OtherIncome]");
                           sb.Append(",[ShortfallInCash]");
                           sb.Append(",[Remarks]");
                           sb.Append(",[IsDeserving]");
                           sb.Append(",[ReferredBy]");
                           sb.Append(",[DataCollectedBy]");
                           sb.Append(",[DataCollectedBySign]");
                           sb.Append(",[ApprovalByDataCollectedPerson]");
                           sb.Append(",[AuthorizedBy]");
                           sb.Append(",[ApprovalByDataAuthorizedPerson])");
                    sb.Append("VALUES");
                            sb.Append("(@SiteCode");
                            sb.Append(",@EntityTypeCode");
                            sb.Append(",@FormId");

                            sb.Append(",@FormNo");
                           sb.Append(",@FormType");
                           sb.Append(",@FatherOrHusbandName");
                           sb.Append(",@MedicalProblemId");
                           sb.Append(",@MemberStatusId");
                           sb.Append(",@OccupationId");

                           sb.Append(",@HouseStatus");
                           sb.Append(",@ZakatAcceptable");
                           sb.Append(",@FamilySize");
                           sb.Append(",@Salary");
                           sb.Append(",@Donations");
                           sb.Append(",@OtherIncome");
                           sb.Append(",@ShortfallInCash");
                           sb.Append(",@Remarks");
                           sb.Append(",@IsDeserving");
                           sb.Append(",@ReferredBy");

                sb.Append(",@DataCollectedBy");
                           sb.Append(",@DataCollectedBySign");
                           sb.Append(",@ApprovalByDataCollectedPerson");
                           sb.Append(",@AuthorizedBy");
                           sb.Append(",@ApprovalByDataAuthorizedPerson)");

                           cmd.Parameters.AddWithValue("@SiteCode", mod.SiteCode);
                           cmd.Parameters.AddWithValue("@EntityTypeCode", mod.EntityTypeCode);
                           cmd.Parameters.AddWithValue("@FormId", Id);
                    cmd.Parameters.AddWithValue("@FormNo", mod.FormNo);
                    cmd.Parameters.AddWithValue("@FormType", mod.FormType);
                    cmd.Parameters.AddWithValue("@FatherOrHusbandName", mod.FatherOrHusbandName);
                    cmd.Parameters.AddWithValue("@MedicalProblemId", mod.MedicalProblemId);
                    cmd.Parameters.AddWithValue("@MemberStatusId", mod.MemberStatusId);
                    cmd.Parameters.AddWithValue("@OccupationId", mod.OccupationId);
                    cmd.Parameters.AddWithValue("@HouseStatus", mod.HouseStatus);
                    cmd.Parameters.AddWithValue("@ZakatAcceptable", mod.ZakatAcceptable);
                    cmd.Parameters.AddWithValue("@FamilySize", mod.FamilySize);
                    cmd.Parameters.AddWithValue("@Salary", mod.Salary);
                    cmd.Parameters.AddWithValue("@Donations", mod.Donations);
                    cmd.Parameters.AddWithValue("@OtherIncome", mod.OtherIncome);
                    cmd.Parameters.AddWithValue("@ShortfallInCash", mod.ShortFallInCash);
                    cmd.Parameters.AddWithValue("@Remarks", mod.Remarks);
                    cmd.Parameters.AddWithValue("@IsDeserving", mod.IsDeserving);

                    cmd.Parameters.AddWithValue("@ReferredBy", mod.ReferredBy);
                    cmd.Parameters.AddWithValue("@DataCollectedBy", mod.DataCollectedBy);
                    cmd.Parameters.AddWithValue("@DataCollectedBySign", mod.DataCollectedBySignatures);
                    cmd.Parameters.AddWithValue("@ApprovalByDataCollectedPerson", mod.ApprovalByDataCollectedPerson);
                    cmd.Parameters.AddWithValue("@AuthorizedBy", mod.AuthorizedBy);
                    cmd.Parameters.AddWithValue("@ApprovalByDataAuthorizedPerson", mod.ApprovalByDataAuthorizedPerson);

                #endregion

                cmd.CommandText = sb.ToString();
                cmd.Connection = con;
                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch (Exception Ex)
                {

                }
                #endregion

                #region Member

                cmd = new SqlCommand();
                sb = new StringBuilder();

                sb.Append("INSERT INTO [dbo].[Member]");
                       sb.Append("([SiteCode]");
                       sb.Append(",[EntityTypeCode]");
                       sb.Append(",[MemberId]");
                       sb.Append(",[RegDate]");
                       sb.Append(",[RegNo]");
                       sb.Append(",[DistributionPointId]");
                       sb.Append(",[FamilyPackageId]");
                       sb.Append(",[IsActive])");
                sb.Append("VALUES");
                       sb.Append("(@SiteCode");
                       sb.Append(",@EntityTypeCode");
                       sb.Append(",@MemberId");
                       sb.Append(",@RegDate");
                       sb.Append(",@RegNo");
                       sb.Append(",@DistributionPointId");
                       sb.Append(",@FamilyPackageId");
                       sb.Append(",@IsActive)");
                //sb.Append("GO");

                cmd.Parameters.AddWithValue("@SiteCode", mod.SiteCode);
                cmd.Parameters.AddWithValue("@EntityTypeCode", mod.EntityTypeCode);
                cmd.Parameters.AddWithValue("@MemberId", Id);
                cmd.Parameters.AddWithValue("@RegDate", mod.RegDate);
                cmd.Parameters.AddWithValue("@RegNo", mod.RegNo);
                cmd.Parameters.AddWithValue("@DistributionPointId", mod.DistributionPointId);
                cmd.Parameters.AddWithValue("@FamilyPackageId", mod.FamilyPackageId);
                cmd.Parameters.AddWithValue("@IsActive", mod.IsActive);

                #endregion

                cmd.CommandText = sb.ToString();
                cmd.Connection = con;
                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {

                }
                con.Close();
                trans.Complete();
            }

            return Id;
        }