public WorkDescription InsertWorkDescription(WorkDescription objWorkDescription)
        {
            using (IDbConnection connection = OpenConnection(dataConnection))
            {
                //var result = new WorkDescription();
                IDbTransaction trn = connection.BeginTransaction();
                string         sql = @"insert  into WorkDescription(WorkDescriptionRefNo,VehicleModelId,FreezerUnitId,BoxId,
                               WorkDescr,WorkDescrShortName,isNewInstallation,isRepair,isSubAssembly,isProjectBased,CreatedBy,CreatedDate,OrganizationId) 
                               Values (@WorkDescriptionRefNo,@VehicleModelId,@FreezerUnitId,@BoxId,@WorkDescr,@WorkDescrShortName,@isNewInstallation,
                               @isRepair,@isSubAssembly,0,@CreatedBy,@CreatedDate,@OrganizationId);
                               SELECT CAST(SCOPE_IDENTITY() as int)";

                try
                {
                    int internalid = DatabaseCommonRepository.GetInternalIDFromDatabase(connection, trn, typeof(WorkDescription).Name, "0", 1);
                    objWorkDescription.WorkDescriptionRefNo = "WD/" + internalid;
                    var id = connection.Query <int>(sql, objWorkDescription, trn).Single();

                    var worksitemrepo = new WorkVsItemRepository();
                    foreach (var item in objWorkDescription.WorkVsItems)
                    {
                        if (item.ItemId == 0 || item.Quantity == 0)
                        {
                            continue;
                        }
                        item.WorkDescriptionId = id;
                        item.CreatedBy         = objWorkDescription.CreatedBy;
                        item.CreatedDate       = objWorkDescription.CreatedDate;
                        worksitemrepo.InsertWorkVsItem(item, connection, trn);
                    }


                    var workstaskepo = new WorkVsTaskRepository();
                    foreach (var item in objWorkDescription.WorkVsTasks)
                    {
                        if (item.JobCardTaskMasterId == 0)
                        {
                            continue;
                        }
                        item.WorkDescriptionId = id;
                        item.CreatedBy         = objWorkDescription.CreatedBy;
                        item.CreatedDate       = objWorkDescription.CreatedDate;
                        workstaskepo.InsertWorkVsTask(item, connection, trn);
                    }

                    objWorkDescription.WorkDescriptionId = id;
                    InsertLoginHistory(dataConnection, objWorkDescription.CreatedBy, "Create", "Work Description", id.ToString(), "0");
                    trn.Commit();
                }
                catch (Exception ex)
                {
                    trn.Rollback();
                    objWorkDescription.WorkDescriptionId    = 0;
                    objWorkDescription.WorkDescriptionRefNo = null;
                }
                return(objWorkDescription);
            }
        }
        public WorkDescription GetWorkDescription(int WorkDescriptionId)
        {
            using (IDbConnection connection = OpenConnection(dataConnection))
            {
                string sql = @"select * from WorkDescription
                        where WorkDescriptionId=@WorkDescriptionId";

                var objWorkDescription = connection.Query <WorkDescription>(sql, new
                {
                    WorkDescriptionId = WorkDescriptionId
                }).First <WorkDescription>();
                var worksitemrepo = new WorkVsItemRepository();
                var workstaskrepo = new WorkVsTaskRepository();
                objWorkDescription.WorkVsItems = worksitemrepo.GetWorkDescriptionWorkVsItems(WorkDescriptionId);
                objWorkDescription.WorkVsTasks = workstaskrepo.GetWorkDescriptionWorkVsTasks(WorkDescriptionId);
                return(objWorkDescription);
            }
        }